Skip to content

Commit 0f4067b

Browse files
authored
Merge pull request #1 from jsinglet/jsinglet/no-precompile-flag
fix windows compatability; add flag for skipping compliation.
2 parents 299904d + 6294646 commit 0f4067b

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

codeql_bundle/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
type=click.Path(exists=True, path_type=Path),
4141
default=Path.cwd(),
4242
)
43+
@click.option('--no-precompile', '-nc', is_flag=True, help="Do not pre-compile the bundle.")
4344
@click.option(
4445
"-l",
4546
"--log",
@@ -56,6 +57,7 @@ def main(
5657
bundle_path: Path,
5758
output: Path,
5859
workspace: Path,
60+
no_precompile: bool,
5961
loglevel: str,
6062
platform: List[str],
6163
code_scanning_config: Optional[Path],
@@ -82,6 +84,8 @@ def main(
8284

8385
try:
8486
bundle = CustomBundle(bundle_path, workspace)
87+
# options for custom bundle
88+
bundle.disable_precompilation = no_precompile
8589

8690
unsupported_platforms = list(filter(lambda p: not bundle.supports_platform(BundlePlatform.from_string(p)), platform))
8791
if len(unsupported_platforms) > 0:

codeql_bundle/helpers/bundle.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def __str__(self):
144144
class Bundle:
145145
def __init__(self, bundle_path: Path) -> None:
146146
self.tmp_dir = TemporaryDirectory()
147+
self.disable_precompilation = False
148+
147149
if bundle_path.is_dir():
148150
self.bundle_path = Path(self.tmp_dir.name) / bundle_path.name
149151
shutil.copytree(
@@ -190,7 +192,8 @@ def supports_windows() -> set[BundlePlatform]:
190192
elif current_system == "Windows" and BundlePlatform.WINDOWS not in self.platforms:
191193
raise BundleException("Bundle doesn't support Windows!")
192194

193-
self.codeql = CodeQL(self.bundle_path / "codeql")
195+
self.codeql = CodeQL(self.bundle_codeql_exe)
196+
194197
try:
195198
logging.info(f"Validating the CodeQL CLI version part of the bundle.")
196199
unpacked_location = self.codeql.unpacked_location()
@@ -215,12 +218,28 @@ def __del__(self) -> None:
215218
f"Removing temporary directory {self.tmp_dir.name} used to build custom bundle."
216219
)
217220
self.tmp_dir.cleanup()
218-
221+
219222
def get_bundle_packs(self) -> List[ResolvedCodeQLPack]:
220223
return self.bundle_packs
221224

222225
def supports_platform(self, platform: BundlePlatform) -> bool:
223226
return platform in self.platforms
227+
228+
@property
229+
def bundle_codeql_exe(self):
230+
if platform.system() == "Windows":
231+
return self.bundle_path / "codeql.exe"
232+
233+
return self.bundle_path / "codeql"
234+
235+
@property
236+
def disable_precompilation(self):
237+
return self._disable_precompilation
238+
239+
@disable_precompilation.setter
240+
def disable_precompilation(self, value: bool):
241+
self._disable_precompilation = value
242+
224243

225244
class CustomBundle(Bundle):
226245
def __init__(self, bundle_path: Path, workspace_path: Path = Path.cwd()) -> None:
@@ -341,7 +360,7 @@ def bundle_customization_pack(customization_pack: ResolvedCodeQLPack):
341360
f"Bundling the customization pack {customization_pack_copy.config.name} at {customization_pack_copy.path}"
342361
)
343362
self.codeql.pack_bundle(
344-
customization_pack_copy, self.bundle_path / "qlpacks"
363+
customization_pack_copy, self.bundle_path / "qlpacks", disable_precompilation=self.disable_precompilation
345364
)
346365

347366
def copy_pack(pack: ResolvedCodeQLPack) -> ResolvedCodeQLPack:
@@ -470,13 +489,14 @@ def bundle_stdlib_pack(pack: ResolvedCodeQLPack):
470489
logging.debug(
471490
f"Bundling the standard library pack {pack_copy.config.name} at {pack_copy.path}"
472491
)
473-
self.codeql.pack_bundle(pack_copy, self.bundle_path / "qlpacks")
492+
self.codeql.pack_bundle(pack_copy, self.bundle_path / "qlpacks", disable_precompilation=self.disable_precompilation)
474493

475494
def bundle_library_pack(library_pack: ResolvedCodeQLPack):
476495
logging.info(f"Bundling the library pack {library_pack.config.name}.")
477496
self.codeql.pack_bundle(
478497
library_pack,
479498
self.bundle_path / "qlpacks",
499+
disable_precompilation=self.disable_precompilation
480500
)
481501

482502
def bundle_query_pack(pack: ResolvedCodeQLPack):
@@ -520,8 +540,7 @@ def bundle_query_pack(pack: ResolvedCodeQLPack):
520540
self.codeql.pack_create(
521541
pack_copy,
522542
self.bundle_path / "qlpacks",
523-
self.bundle_path,
524-
)
543+
self.bundle_path)
525544
else:
526545
logging.info(f"Bundling the query pack {pack.config.name}.")
527546
pack_copy = copy_pack(pack)
@@ -537,8 +556,7 @@ def bundle_query_pack(pack: ResolvedCodeQLPack):
537556

538557
self.codeql.pack_create(
539558
pack_copy,
540-
self.bundle_path / "qlpacks",
541-
)
559+
self.bundle_path / "qlpacks")
542560

543561
sorted_packs = list(pack_sorter.static_order())
544562
logger.debug(f"Sorted packs: {' -> '.join(map(lambda p: p.config.name, sorted_packs))}")

codeql_bundle/helpers/codeql.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def __init__(self, codeql_path: Path):
6565
self.codeql_path = codeql_path
6666
self._version = None
6767

68+
@property
69+
def disable_precompilation(self):
70+
return self._disable_precompilation
71+
72+
@disable_precompilation.setter
73+
def disable_precompilation(self, value: bool):
74+
self._disable_precompilation = value
75+
6876
def _exec(self, command: str, *args: str) -> subprocess.CompletedProcess[str]:
6977
logger.debug(
7078
f"Running CodeQL command: {command} with arguments: {' '.join(args)}"
@@ -124,11 +132,18 @@ def pack_bundle(
124132
pack: CodeQLPack,
125133
output_path: Path,
126134
*additional_packs: Path,
135+
disable_precompilation = False
127136
):
128137
if not pack.config.library:
129138
raise CodeQLException(f"Cannot bundle non-library pack {pack.config.name}!")
130139

131140
args = ["bundle", "--format=json", f"--pack-path={output_path}"]
141+
if disable_precompilation:
142+
args.append("--no-precompile")
143+
logging.warn(
144+
f"NOTE: Precompilation is disabled for {pack.config.name}! This may result in slower query execution."
145+
)
146+
132147
if len(additional_packs) > 0:
133148
args.append(f"--additional-packs={':'.join(map(str,additional_packs))}")
134149
cp = self._exec(
@@ -146,11 +161,18 @@ def pack_create(
146161
pack: CodeQLPack,
147162
output_path: Path,
148163
*additional_packs: Path,
164+
disable_precompilation = False
149165
):
150166
if pack.config.library:
151167
raise CodeQLException(f"Cannot bundle non-query pack {pack.config.name}!")
152168

153169
args = ["create", "--format=json", f"--output={output_path}", "--threads=0", "--no-default-compilation-cache"]
170+
if disable_precompilation:
171+
args.append("--no-precompile")
172+
logging.warn(
173+
f"NOTE: Precompilation is disabled for {pack.config.name}! This may result in slower query execution."
174+
)
175+
154176
if self.supports_qlx():
155177
args.append("--qlx")
156178
if len(additional_packs) > 0:

0 commit comments

Comments
 (0)