diff --git a/impl.just b/impl.just new file mode 100755 index 0000000000000..5284bbafea065 --- /dev/null +++ b/impl.just @@ -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 diff --git a/justfile b/justfile new file mode 100755 index 0000000000000..e2c44720524d3 --- /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 0000000000000..1bbf38aef00f2 --- /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 0000000000000..3e4a93107a2e5 --- /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 0000000000000..fa355af10764f --- /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)