-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a rough PoC showcasing [just](https://github.com/casey/just) as a builder/test runner. After installing `just` you can (in this PoC <language> can only be `rust`): * `just install <language>` to install a language pack in-tree `<language>` can be omitted if running from inside its directory. * `just build <language>` will build `target/intree/codeql-<language>` from the internal repository, if available, otherwise it will fall back to `install`. * `just test TESTS... FLAGS...` will run the provided tests, if they are of the same kind (integration or QL tests), passing FLAGS to the runner. For QL tests the appropriate `build <language>` is run. Notably, for QL tests this command works also if using `codeql` standalone from the internal repository (using `install` and `codeql` from `PATH`). If running from within a test directory, `TESTS` can be omitted and defaults to all tests in the current directory.
- Loading branch information
Paolo Tranquilli
committed
Dec 12, 2024
1 parent
066db76
commit 3d93b38
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env just --justfile | ||
|
||
set allow-duplicate-recipes | ||
set allow-duplicate-variables | ||
set unstable | ||
set quiet | ||
|
||
_install LANGUAGE: | ||
bazel run //{{ trim_end_match(LANGUAGE, '/') }}:install | ||
|
||
_build LANGUAGE: | ||
if [ -n ${SEMMLE_CODE:-} ]; then \ | ||
cd $SEMMLE_CODE; ./build target/intree/codeql-{{ LANGUAGE }}; \ | ||
else \ | ||
just install {{ LANGUAGE }}; \ | ||
fi | ||
|
||
build LANGUAGE: (_build LANGUAGE) | ||
install LANGUAGE: (_install LANGUAGE) | ||
|
||
[no-cd, script:'python3', positional-arguments, no-exit-message] | ||
test +ARGS: # TODO: fuzzy test chooser when no arguments are provided! | ||
import pathlib | ||
import subprocess | ||
import os | ||
import sys | ||
# avoid infinite recursion: this happens when arguments have kinds of tests | ||
if os.environ.get("CODEQL_JUSTFILE_TEST"): | ||
print("No common test handler found", file=sys.stderr) | ||
sys.exit(1) | ||
os.environ["CODEQL_JUSTFILE_TEST"] = "true" | ||
|
||
flags = [arg for arg in sys.argv[1:] if arg.startswith('-')] | ||
args = [arg for arg in sys.argv[1:] if not arg.startswith('-')] | ||
common_path = pathlib.Path(os.path.commonpath(args)).resolve() | ||
if not common_path.is_dir(): | ||
common_path = common_path.parent | ||
ret = subprocess.run( | ||
['{{ just_executable() }}', 'test'] + flags + [pathlib.Path(a).resolve().relative_to(common_path) for a in args], | ||
cwd=common_path).returncode | ||
sys.exit(ret) | ||
|
||
[no-cd] | ||
_run_language_tests LANGUAGE *ARGS: (_build LANGUAGE) | ||
if [ -n ${SEMMLE_CODE:-} ]; then \ | ||
$SEMMLE_CODE/target/intree/codeql-{{ LANGUAGE }}/codeql test run $ARGS; \ | ||
else \ | ||
codeql --search-path={{ source_dir() }} test run $ARGS; \ | ||
fi | ||
|
||
[no-cd] | ||
_run_integration_tests *ARGS: | ||
if [ -n ${SEMMLE_CODE:-} ]; then \ | ||
$SEMMLE_CODE/tools/pytest $ARGS; \ | ||
else \ | ||
echo "integration tests require running from an internal repository working copy" >&2; \ | ||
exit 1; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'impl.just' | ||
import? '../justfile' # internal repo just file, if present | ||
|
||
@_default: | ||
{{ just_executable() }} --list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import '../justfile' | ||
|
||
install LANGUAGE='rust': (_install LANGUAGE) | ||
build LANGUAGE='rust': (_build LANGUAGE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '../../justfile' | ||
|
||
test *ARGS=".": (_run_integration_tests ARGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env just --justfile | ||
|
||
import '../../justfile' | ||
|
||
test *ARGS=".": (_run_language_tests "rust" ARGS) |