Skip to content

Commit

Permalink
Include filenames in exported coverage files
Browse files Browse the repository at this point in the history
The previous coverage schema required the exporter logic to replace all
filenames with file hashes unconditionally.

The new exporter logic is able to retain filenames, which can be used to
compute file hashes when required.

Signed-off-by: John Pennycook <john.pennycook@intel.com>
  • Loading branch information
Pennycook committed Feb 5, 2024
1 parent 360d840 commit c53a2cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions bin/cbicov
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ if __name__ == "__main__":

state = finder.find(source_dir, codebase, configuration)

exporter = Exporter(codebase)
exporter = Exporter(codebase, hash_filenames=False)
exports = exporter.walk(state)
for p in codebase["platforms"]:
covarray = []
for filename in exports[p]:
covobject = {"file": filename, "regions": []}
covobject = {
"file": util.compute_file_hash(filename),
"path": filename,
"regions": [],
}
for region in exports[p][filename]:
covobject["regions"].append(list(region))
covarray.append(covobject)
Expand Down
10 changes: 6 additions & 4 deletions codebasin/walkers/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ class Exporter(TreeWalker):
Build a per-platform list of mappings.
"""

def __init__(self, codebase):
def __init__(self, codebase, *, hash_filenames=True):
super().__init__(None, None)
self.codebase = codebase
self.exports = None
self.hash_filenames = hash_filenames

def walk(self, state):
self.exports = collections.defaultdict(
lambda: collections.defaultdict(list),
)
for fn in state.get_filenames():
hashed_fn = util.compute_file_hash(fn)
if self.hash_filenames:
fn = util.compute_file_hash(fn)
self._export_node(
hashed_fn,
fn,
state.get_tree(fn).root,
state.get_map(fn),
)
Expand All @@ -56,6 +58,6 @@ def _export_node(self, _filename, _node, _map):

next_filename = _filename
if isinstance(_node, FileNode):
next_filename = util.compute_file_hash(_node.filename)
next_filename = _node.filename
for child in _node.children:
self._export_node(next_filename, child, _map)

0 comments on commit c53a2cb

Please sign in to comment.