From ac77208d577785ffcbdb456a0527d5aaa0970f8e Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 24 Jun 2026 15:13:19 -0400 Subject: [PATCH] Add feature to respect threads option on pack create step --- codeql_bundle/cli.py | 9 +++++++++ codeql_bundle/helpers/bundle.py | 7 +++++++ codeql_bundle/helpers/codeql.py | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/codeql_bundle/cli.py b/codeql_bundle/cli.py index b1f254c..db6372d 100644 --- a/codeql_bundle/cli.py +++ b/codeql_bundle/cli.py @@ -72,6 +72,13 @@ type=click.Path(exists=True, path_type=Path), help="Path to a JSON file specifying additional data to install into the bundle", ) +@click.option( + "-j", + "--threads", + type=click.INT, + help="Use this many threads to compile queries.", +) + @click.argument("packs", nargs=-1, required=True) def main( bundle_path: Path, @@ -82,6 +89,7 @@ def main( platform: List[str], code_scanning_config: Optional[Path], additional_data_config: Optional[Path], + threads: Optional[int], packs: List[str], ) -> None: @@ -109,6 +117,7 @@ def main( bundle = CustomBundle(bundle_path, workspace) # options for custom bundle bundle.disable_precompilation = no_precompile + bundle.threads = threads unsupported_platforms = list( filter( diff --git a/codeql_bundle/helpers/bundle.py b/codeql_bundle/helpers/bundle.py index 9278586..2a7d205 100644 --- a/codeql_bundle/helpers/bundle.py +++ b/codeql_bundle/helpers/bundle.py @@ -278,6 +278,13 @@ def disable_precompilation(self): def disable_precompilation(self, value: bool): self._disable_precompilation = value + @property + def threads(self): + return self.codeql.threads + + @threads.setter + def threads(self, value: int): + self.codeql.threads= value class CustomBundle(Bundle): def __init__(self, bundle_path: Path, workspace_path: Path = Path.cwd()) -> None: diff --git a/codeql_bundle/helpers/codeql.py b/codeql_bundle/helpers/codeql.py index f5a9462..c65849e 100644 --- a/codeql_bundle/helpers/codeql.py +++ b/codeql_bundle/helpers/codeql.py @@ -64,6 +64,7 @@ class CodeQL: def __init__(self, codeql_path: Path): self.codeql_path = codeql_path self._version = None + self._threads = None @property def disable_precompilation(self): @@ -72,6 +73,14 @@ def disable_precompilation(self): @disable_precompilation.setter def disable_precompilation(self, value: bool): self._disable_precompilation = value + + @property + def threads(self): + return self._threads + + @threads.setter + def threads(self, value: int): + self._threads = value def _exec(self, command: str, *args: str) -> subprocess.CompletedProcess[str]: logger.debug( @@ -166,7 +175,14 @@ def pack_create( if pack.config.library: raise CodeQLException(f"Cannot bundle non-query pack {pack.config.name}!") - args = ["create", "--format=json", f"--output={output_path}", "--threads=0", "--no-default-compilation-cache"] + args = ["create", "--format=json", f"--output={output_path}", "--no-default-compilation-cache"] + + if self.threads is not None: + logging.info(f"Using {self.threads} threads for bundling {pack.config.name}.") + args.append(f"--threads={self.threads}") + else: + args.append(f"--threads=0") + if disable_precompilation: args.append("--no-precompile") logging.warn(