Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions codeql_bundle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -118,6 +124,7 @@ def main(
cache_dir: Path,
cache_manifest: Optional[str],
no_compilation_cache: bool,
ram: Optional[int],
packs: List[str],
) -> None:

Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions codeql_bundle/helpers/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 23 additions & 5 deletions codeql_bundle/helpers/codeql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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)}"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down