diff --git a/codeql_bundle/cli.py b/codeql_bundle/cli.py index d8d8c1b..932db96 100644 --- a/codeql_bundle/cli.py +++ b/codeql_bundle/cli.py @@ -104,6 +104,12 @@ help="Do not resolve, download, or use published compilation caches.", ) +@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: str, @@ -118,6 +124,7 @@ def main( cache_dir: Path, cache_manifest: Optional[str], no_compilation_cache: bool, + ram: Optional[int], packs: List[str], ) -> None: @@ -169,6 +176,7 @@ def main( # options for custom bundle bundle.disable_precompilation = no_precompile bundle.threads = threads + bundle.ram = ram unsupported_platforms = list( filter( diff --git a/codeql_bundle/helpers/bundle.py b/codeql_bundle/helpers/bundle.py index 24f2975..d323165 100644 --- a/codeql_bundle/helpers/bundle.py +++ b/codeql_bundle/helpers/bundle.py @@ -337,6 +337,16 @@ def threads(self): def threads(self, value: int): self.codeql.threads= 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, diff --git a/codeql_bundle/helpers/codeql.py b/codeql_bundle/helpers/codeql.py index 3f052af..b4d53d0 100644 --- a/codeql_bundle/helpers/codeql.py +++ b/codeql_bundle/helpers/codeql.py @@ -66,6 +66,7 @@ def __init__(self, codeql_path: Path): self.codeql_path = codeql_path self._version = None self._threads = None + self._ram = None @property def disable_precompilation(self): @@ -74,7 +75,7 @@ def disable_precompilation(self): @disable_precompilation.setter def disable_precompilation(self, value: bool): self._disable_precompilation = value - + @property def threads(self): return self._threads @@ -83,6 +84,14 @@ def threads(self): def threads(self, value: int): self._threads = 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)}" @@ -125,7 +134,7 @@ def _exec_streaming( ) def version(self) -> Version: - if self._version != None: + if self._version is not None: return self._version else: cp = self._exec("version", "--format=json") @@ -178,7 +187,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( @@ -189,6 +198,11 @@ def pack_bundle( args.append( f"--additional-packs={os.pathsep.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, @@ -217,7 +231,7 @@ def pack_create( args.append(f"--threads={self.threads}") else: args.append(f"--threads=0") - + if disable_precompilation: args.append("--no-precompile") logging.warn( @@ -232,6 +246,10 @@ def pack_create( args.append( f"--additional-packs={os.pathsep.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, @@ -271,7 +289,7 @@ def query_compile( if cp.returncode != 0: raise CodeQLException(f"Failed to run {cp.args} command! {cp.stderr}") return cp - + def resolve_languages(self) -> set[str]: cp = self._exec("resolve", "languages", "--format=json") if cp.returncode == 0: