Skip to content

Commit b27bcd8

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 52be212 commit b27bcd8

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

scanpipe/pipes/d2d.py

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,14 +1870,41 @@ def map_elfs(project, logger=None):
18701870
None
18711871
18721872
"""
1873-
map_paths(
1874-
project=project,
1875-
file_type="elfs",
1876-
collect_paths_func=get_elf_file_dwarf_paths,
1877-
map_types=["dwarf_compiled_paths", "dwarf_included_paths"],
1878-
logger=logger,
1873+
from_resources = project.codebaseresources.files().from_codebase()
1874+
to_resources = (
1875+
project.codebaseresources.files().to_codebase().has_no_relation().elfs()
1876+
)
1877+
for resource in to_resources:
1878+
try:
1879+
paths = get_elf_file_dwarf_paths(resource.location_path)
1880+
resource.update_extra_data(paths)
1881+
except Exception as e:
1882+
logger(f"Can not parse {resource.location_path!r} {e!r}")
1883+
1884+
if logger:
1885+
logger(
1886+
f"Mapping {to_resources.count():,d} to/ resources using paths "
1887+
f"with {from_resources.count():,d} from/ resources."
1888+
)
1889+
1890+
from_resources_index = pathmap.build_index(
1891+
from_resources.values_list("id", "path"), with_subpaths=True
18791892
)
18801893

1894+
if logger:
1895+
logger("Done building from/ resources index.")
1896+
1897+
resource_iterator = to_resources.iterator(chunk_size=2000)
1898+
progress = LoopProgress(to_resources.count(), logger)
1899+
for to_resource in progress.iter(resource_iterator):
1900+
map_paths_resource(
1901+
to_resource,
1902+
from_resources,
1903+
from_resources_index,
1904+
map_types=["dwarf_compiled_paths", "dwarf_included_paths"],
1905+
logger=logger,
1906+
)
1907+
18811908

18821909
def get_elf_file_dwarf_paths(location):
18831910
"""
@@ -1929,10 +1956,40 @@ def map_go_paths(project, logger=None):
19291956
None
19301957
19311958
"""
1932-
map_paths(
1933-
project=project,
1934-
file_type="executable_binaries",
1935-
collect_paths_func=get_go_file_paths,
1936-
map_types=["go_file_paths"],
1937-
logger=logger,
1959+
from_resources = project.codebaseresources.files().from_codebase()
1960+
to_resources = (
1961+
project.codebaseresources.files()
1962+
.to_codebase()
1963+
.has_no_relation()
1964+
.executable_binaries()
19381965
)
1966+
for resource in to_resources:
1967+
try:
1968+
paths = get_go_file_paths(resource.location_path)
1969+
resource.update_extra_data(paths)
1970+
except Exception as e:
1971+
logger(f"Can not parse {resource.location_path!r} {e!r}")
1972+
1973+
if logger:
1974+
logger(
1975+
f"Mapping {to_resources.count():,d} to/ resources using paths "
1976+
f"with {from_resources.count():,d} from/ resources."
1977+
)
1978+
1979+
from_resources_index = pathmap.build_index(
1980+
from_resources.values_list("id", "path"), with_subpaths=True
1981+
)
1982+
1983+
if logger:
1984+
logger("Done building from/ resources index.")
1985+
1986+
resource_iterator = to_resources.iterator(chunk_size=2000)
1987+
progress = LoopProgress(to_resources.count(), logger)
1988+
for to_resource in progress.iter(resource_iterator):
1989+
map_paths_resource(
1990+
to_resource,
1991+
from_resources,
1992+
from_resources_index,
1993+
map_types=["go_file_paths"],
1994+
logger=logger,
1995+
)
-578 KB
Binary file not shown.

scanpipe/tests/pipes/test_d2d.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,6 @@ def test_scanpipe_pipes_d2d_map_elfs(self):
14841484
recurse=True,
14851485
)
14861486
pipes.collect_and_create_codebase_resources(self.project1)
1487-
print(self.project1.codebaseresources.files().from_codebase())
14881487
buffer = io.StringIO()
14891488
d2d.map_elfs(project=self.project1, logger=buffer.write)
14901489
self.assertEqual(

0 commit comments

Comments
 (0)