Skip to content

Commit ec63408

Browse files
committed
Fix incorrect handling of transitive workspace dependencies
1 parent 06266ad commit ec63408

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

codeql_bundle/helpers/bundle.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,14 @@ def add_packs(self, *packs: ResolvedCodeQLPack):
188188
# Keep a map of standard library packs to their customization packs so we know which need to be modified.
189189
std_lib_deps : dict[ResolvedCodeQLPack, List[ResolvedCodeQLPack]] = defaultdict(list)
190190
pack_sorter : TopologicalSorter[ResolvedCodeQLPack] = TopologicalSorter()
191-
for pack in packs:
191+
192+
def add_to_graph(pack: ResolvedCodeQLPack, processed_packs: set[ResolvedCodeQLPack], std_lib_deps: dict[ResolvedCodeQLPack, List[ResolvedCodeQLPack]]):
193+
# Only process workspace packs in this function
194+
if not pack in self.workspace_packs:
195+
logger.debug(f"Skipping adding pack {pack.config.name}@{str(pack.config.version)} to dependency graph")
196+
return
192197
if pack.kind == CodeQLPackKind.CUSTOMIZATION_PACK:
198+
logger.debug(f"Adding customization pack {pack.config.name}@{str(pack.config.version)} to dependency graph")
193199
pack_sorter.add(pack)
194200
std_lib_deps[pack.dependencies[0]].append(pack)
195201
else:
@@ -202,18 +208,27 @@ def add_packs(self, *packs: ResolvedCodeQLPack):
202208
if not std_lib_dep in pack.dependencies:
203209
logger.debug(f"Adding stdlib dependency {std_lib_dep.config.name}@{str(std_lib_dep.config.version)} to {pack.config.name}@{str(pack.config.version)}")
204210
pack.dependencies.append(std_lib_dep)
211+
logger.debug(f"Adding pack {pack.config.name}@{str(pack.config.version)} to dependency graph")
205212
pack_sorter.add(pack, *pack.dependencies)
213+
for dep in pack.dependencies:
214+
if dep not in processed_packs:
215+
add_to_graph(dep, processed_packs, std_lib_deps)
216+
processed_packs.add(pack)
206217

207-
for pack in [p for p in self.workspace_packs if p.kind == CodeQLPackKind.CUSTOMIZATION_PACK]:
208-
del pack.dependencies[0]
218+
processed_packs : set[ResolvedCodeQLPack] = set()
219+
for pack in packs:
220+
if not pack in processed_packs:
221+
add_to_graph(pack, processed_packs, std_lib_deps)
209222

210223
def is_dependent_on(pack: ResolvedCodeQLPack, other: ResolvedCodeQLPack) -> bool:
211224
return other in pack.dependencies or any(map(lambda p: is_dependent_on(p, other), pack.dependencies))
212225
# Add the stdlib and its dependencies to properly sort the customization packs before the other packs.
213226
for pack, deps in std_lib_deps.items():
227+
logger.debug(f"Adding standard library pack {pack.config.name}@{str(pack.config.version)} to dependency graph")
214228
pack_sorter.add(pack, *deps)
215229
# Add the standard query packs that rely transitively on the stdlib.
216230
for query_pack in [p for p in self.bundle_packs if p.kind == CodeQLPackKind.QUERY_PACK and is_dependent_on(p, pack)]:
231+
logger.debug(f"Adding standard query pack {query_pack.config.name}@{str(query_pack.config.version)} to dependency graph")
217232
pack_sorter.add(query_pack, pack)
218233

219234
def bundle_customization_pack(customization_pack: ResolvedCodeQLPack):

0 commit comments

Comments
 (0)