diff --git a/impl.just b/impl.just new file mode 100755 index 000000000000..4e4901e315c3 --- /dev/null +++ b/impl.just @@ -0,0 +1,61 @@ +#!/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 test args are of different kinds + # or for different languages, or also if they are across the external/internal + # repository boundary + # TODO: allow some degree of mixing maybe? + 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 diff --git a/justfile b/justfile new file mode 100755 index 000000000000..e2c44720524d --- /dev/null +++ b/justfile @@ -0,0 +1,5 @@ +import 'impl.just' +import? '../justfile' # internal repo just file, if present + +@_default: + {{ just_executable() }} --list diff --git a/rust/justfile b/rust/justfile new file mode 100644 index 000000000000..1bbf38aef00f --- /dev/null +++ b/rust/justfile @@ -0,0 +1,4 @@ +import '../justfile' + +install LANGUAGE='rust': (_install LANGUAGE) +build LANGUAGE='rust': (_build LANGUAGE) diff --git a/rust/ql/integration-tests/justfile b/rust/ql/integration-tests/justfile new file mode 100644 index 000000000000..3e4a93107a2e --- /dev/null +++ b/rust/ql/integration-tests/justfile @@ -0,0 +1,3 @@ +import '../../justfile' + +test *ARGS=".": (_run_integration_tests ARGS) diff --git a/rust/ql/test/justfile b/rust/ql/test/justfile new file mode 100755 index 000000000000..fa355af10764 --- /dev/null +++ b/rust/ql/test/justfile @@ -0,0 +1,5 @@ +#!/usr/bin/env just --justfile + +import '../../justfile' + +test *ARGS=".": (_run_language_tests "rust" ARGS)