diff --git a/codeql_bundle/cli.py b/codeql_bundle/cli.py index b1f254c..28b0405 100644 --- a/codeql_bundle/cli.py +++ b/codeql_bundle/cli.py @@ -72,6 +72,12 @@ type=click.Path(exists=True, path_type=Path), help="Path to a JSON file specifying additional data to install into the bundle", ) +@click.option( + "-M", + "--ram", + type=click.INT, + help="Set total amount of RAM that the compiler should be allowed to use.", +) @click.argument("packs", nargs=-1, required=True) def main( bundle_path: Path, @@ -82,6 +88,7 @@ def main( platform: List[str], code_scanning_config: Optional[Path], additional_data_config: Optional[Path], + ram: Optional[int], packs: List[str], ) -> None: @@ -109,6 +116,7 @@ def main( bundle = CustomBundle(bundle_path, workspace) # options for custom bundle bundle.disable_precompilation = no_precompile + bundle.ram = ram unsupported_platforms = list( filter( diff --git a/codeql_bundle/helpers/bundle.py b/codeql_bundle/helpers/bundle.py index 9278586..6d29dc3 100644 --- a/codeql_bundle/helpers/bundle.py +++ b/codeql_bundle/helpers/bundle.py @@ -278,6 +278,15 @@ def disable_precompilation(self): def disable_precompilation(self, value: bool): self._disable_precompilation = value + @property + def ram(self): + return self.codeql.ram + + @ram.setter + def ram(self, value: int): + self.codeql.ram = 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..608f175 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._ram = None @property def disable_precompilation(self): @@ -73,6 +74,14 @@ def disable_precompilation(self): def disable_precompilation(self, value: bool): self._disable_precompilation = value + @property + def ram(self): + return self._ram + + @ram.setter + def ram(self, value: int): + self._ram = value + def _exec(self, command: str, *args: str) -> subprocess.CompletedProcess[str]: logger.debug( f"Running CodeQL command: {command} with arguments: {' '.join(args)}" @@ -84,7 +93,7 @@ def _exec(self, command: str, *args: str) -> subprocess.CompletedProcess[str]: ) def version(self) -> Version: - if self._version != None: + if self._version is not None: return self._version else: cp = self._exec("version", "--format=json") @@ -137,7 +146,7 @@ def pack_bundle( if not pack.config.library: raise CodeQLException(f"Cannot bundle non-library pack {pack.config.name}!") - args = ["bundle", "--format=json", f"--pack-path={output_path}"] + args = ["bundle", "--format=json", f"--pack-path={output_path}", "--threads=0"] if disable_precompilation: args.append("--no-precompile") logging.warn( @@ -146,6 +155,11 @@ def pack_bundle( if len(additional_packs) > 0: args.append(f"--additional-packs={':'.join(map(str,additional_packs))}") + + if self.ram is not None: + logging.info(f"Using {self.ram} MB of RAM for bundling {pack.config.name}.") + args.append(f"--ram={self.ram}") + cp = self._exec( "pack", *args, @@ -177,6 +191,9 @@ def pack_create( args.append("--qlx") if len(additional_packs) > 0: args.append(f"--additional-packs={':'.join(map(str,additional_packs))}") + if self.ram is not None: + logging.info(f"Using {self.ram} MB of RAM for packing {pack.config.name}.") + args.append(f"--ram={self.ram}") cp = self._exec( "pack", *args,