summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Vetrov <vvvvvv@google.com>2024-03-19 18:41:55 +0000
committerAleksei Vetrov <vvvvvv@google.com>2024-03-21 19:05:32 +0000
commita12fb1571bbf7b563d1e3aa056b09be859e42039 (patch)
tree479d40cba54de15fd791ca19b0e8caf0195b1a11
parent115b5f28138ef723ec1abed6a0e81a455b07315d (diff)
downloadbuild-a12fb1571bbf7b563d1e3aa056b09be859e42039.tar.gz
kleaf: deduplicate gcov mappings
When Kleaf creates mappings for mixed build, it updates mappings from base build. But these mappings may already contain the same folders like OUT_DIR. This change uses dict to update existing mappings instead of adding duplicate mapping. Tested: bazel run --gcov //common-modules/virtual-device:virtual_device_x86_64_dist Bug: 330338115 Change-Id: I68ff5ff25dd9233d1330ff896edab5036c91cd6d
-rw-r--r--kleaf/impl/print_gcno_mapping.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/kleaf/impl/print_gcno_mapping.py b/kleaf/impl/print_gcno_mapping.py
index 824ef1e..4368eda 100644
--- a/kleaf/impl/print_gcno_mapping.py
+++ b/kleaf/impl/print_gcno_mapping.py
@@ -20,17 +20,19 @@ from typing import TextIO, Optional
def main(base: Optional[TextIO], mappings: list[str]):
- result = []
+ mappings_dict = {}
if base:
- result = json.load(base)
+ for mapping in json.load(base):
+ mappings_dict[mapping["from"]] = mapping["to"]
for mapping in mappings:
from_val, to_val = mapping.split(":")
+ mappings_dict[from_val] = to_val
- result.append({
- "from": from_val,
- "to": to_val,
- })
+ result = [
+ {"from": from_val, "to": to_val}
+ for from_val, to_val in sorted(mappings_dict.items())
+ ]
print(json.dumps(result, sort_keys=True, indent=2))