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 @@ -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,
Expand All @@ -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:

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