Skip to content

Commit 49ec798

Browse files
authored
Add support for default code scanning config
2 parents 853aad4 + 739d20e commit 49ec798

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

codeql_bundle/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pathlib import Path
1212
from codeql_bundle.helpers.codeql import CodeQLException
1313
from codeql_bundle.helpers.bundle import CustomBundle, BundleException, BundlePlatform
14-
from typing import List
14+
from typing import List, Optional
1515
import sys
1616
import logging
1717

@@ -50,13 +50,15 @@
5050
default="WARNING",
5151
)
5252
@click.option("-p", "--platform", multiple=True, type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False), help="Target platform for the bundle")
53+
@click.option("-c", "--code-scanning-config", type=click.Path(exists=True, path_type=Path), help="Path to a Code Scanning configuration file that will be the default for the bundle")
5354
@click.argument("packs", nargs=-1, required=True)
5455
def main(
5556
bundle_path: Path,
5657
output: Path,
5758
workspace: Path,
5859
loglevel: str,
5960
platform: List[str],
61+
code_scanning_config: Optional[Path],
6062
packs: List[str],
6163
) -> None:
6264

@@ -119,6 +121,9 @@ def main(
119121
f"Adding the pack(s) {','.join(map(lambda p: p.config.name, selected_packs))} and its workspace dependencies to the custom bundle."
120122
)
121123
bundle.add_packs(*selected_packs)
124+
if code_scanning_config:
125+
logger.info(f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle.")
126+
bundle.add_code_scanning_config(code_scanning_config)
122127
logger.info(f"Bundling custom bundle(s) at {output}")
123128
platforms = set(map(BundlePlatform.from_string, platform))
124129
bundle.bundle(output, platforms)

codeql_bundle/helpers/bundle.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def add_to_graph(pack: ResolvedCodeQLPack, processed_packs: set[ResolvedCodeQLPa
296296
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)}")
297297
pack.dependencies.append(std_lib_dep)
298298
logger.debug(f"Adding pack {pack.config.name}@{str(pack.config.version)} to dependency graph")
299-
pack_sorter.add(pack)
299+
pack_sorter.add(pack, *pack.dependencies)
300300
for dep in pack.dependencies:
301301
if dep not in processed_packs:
302302
add_to_graph(dep, processed_packs, std_lib_deps)
@@ -537,7 +537,9 @@ def bundle_query_pack(pack: ResolvedCodeQLPack):
537537
self.bundle_path / "qlpacks",
538538
)
539539

540-
for pack in pack_sorter.static_order():
540+
sorted_packs = list(pack_sorter.static_order())
541+
logger.debug(f"Sorted packs: {' -> '.join(map(lambda p: p.config.name, sorted_packs))}")
542+
for pack in sorted_packs:
541543
if pack.kind == CodeQLPackKind.CUSTOMIZATION_PACK:
542544
bundle_customization_pack(pack)
543545
elif pack.kind == CodeQLPackKind.LIBRARY_PACK:
@@ -548,7 +550,14 @@ def bundle_query_pack(pack: ResolvedCodeQLPack):
548550
elif pack.kind == CodeQLPackKind.QUERY_PACK:
549551
bundle_query_pack(pack)
550552

551-
def bundle(self, output_path: Path, platforms: set[BundlePlatform] = set()):
553+
def add_code_scanning_config(self, default_config: Path):
554+
if not default_config.exists():
555+
raise BundleException(f"Default config {default_config} does not exist.")
556+
if not default_config.is_file():
557+
raise BundleException(f"Default config {default_config} is not a file.")
558+
shutil.copy(default_config, self.bundle_path / "default-codeql-config.yml")
559+
560+
def bundle(self, output_path: Path, platforms: set[BundlePlatform] = set(), default_config : Optional[Path] = None):
552561
if len(platforms) == 0:
553562
if output_path.is_dir():
554563
output_path = output_path / "codeql-bundle.tar.gz"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "codeql-bundle"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "Tool to create custom CodeQL bundles"
55
authors = ["Remco Vermeulen <[email protected]>"]
66
readme = "README.md"

tests/workspace/cpp/aa/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ warnOnImplicitThis: false
44
name: test/aa
55
version: 0.0.1
66
dependencies:
7-
"codeql/cpp-all": "0.7.4"
7+
"codeql/cpp-all": "^0.8.0"

tests/workspace/cpp/foo-customizations/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ library: True
22
name: foo/cpp-customizations
33
version: 0.0.1
44
dependencies:
5-
"codeql/cpp-all": "0.7.4"
5+
"codeql/cpp-all": "^0.8.0"

0 commit comments

Comments
 (0)