Skip to content

Commit

Permalink
Just: improve structure, add language-tests + integration-tests recip…
Browse files Browse the repository at this point in the history
…es for rust
  • Loading branch information
Paolo Tranquilli committed Dec 12, 2024
1 parent ee753c6 commit 066c6c3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 42 deletions.
13 changes: 13 additions & 0 deletions build.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'lib.just'

@_build LANGUAGE:
if [ -n "${SEMMLE_CODE:-}" ]; then \
cd $SEMMLE_CODE; ./build target/intree/codeql-{{ LANGUAGE }}; \
else \
just install {{ LANGUAGE }}; \
fi

[group('build')]
build LANGUAGE: (_build LANGUAGE)

alias b := build
9 changes: 9 additions & 0 deletions install.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'lib.just'

@_install LANGUAGE:
cd {{ source_dir() }}; bazel run //{{ trim_end_match(LANGUAGE, '/') }}:install

[group('build')]
install LANGUAGE: (_install LANGUAGE)

alias i := install
10 changes: 7 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'impl.just'
import? '../justfile' # internal repo just file, if present
import 'build.just'
import 'test.just'
import 'install.just'
import? 'local.just'

mod rust

@_default:
{{ just_executable() }} --list
{{ just_executable() }} --list --list-submodules
5 changes: 5 additions & 0 deletions lib.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import? '../semmle-code.just' # internal repo just file, if present

set fallback
set allow-duplicate-recipes
set unstable
22 changes: 21 additions & 1 deletion rust/justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import '../justfile'
import '../build.just'
import '../install.just'
import '../test.just'

@_default: generate (build "rust")

[group('build')]
install LANGUAGE='rust': (_install LANGUAGE)

[group('build')]
build LANGUAGE='rust': (_build LANGUAGE)

[group('generate')]
generate:
bazel run @codeql//rust/codegen

alias gen := generate
alias g := generate

[group('test')]
integration-tests: (_integration_tests (source_dir() / 'ql/integration-tests'))

[group('test')]
language-tests: (_language_tests 'rust' (source_dir() / 'ql/test'))
5 changes: 3 additions & 2 deletions rust/ql/integration-tests/justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../justfile'
import '../../../test.just'

test *ARGS=".": (_run_integration_tests ARGS)
[group('test')]
test *ARGS=".": (_integration_tests ARGS)
7 changes: 3 additions & 4 deletions rust/ql/test/justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env just --justfile
import '../../../test.just'

import '../../justfile'

test *ARGS=".": (_run_language_tests "rust" ARGS)
[group('test')]
test *ARGS=".": (_language_tests "rust" ARGS)
48 changes: 16 additions & 32 deletions impl.just → test.just
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env just --justfile
import 'build.just'

set allow-duplicate-recipes
set allow-duplicate-variables
set unstable
set quiet

_install LANGUAGE:
cd {{ source_dir() }}; bazel run //{{ trim_end_match(LANGUAGE, '/') }}:install

_build LANGUAGE:
[no-cd, positional-arguments, no-exit-message]
@_language_tests LANGUAGE *ARGS: (_build LANGUAGE)
shift; \
if [ -n "${SEMMLE_CODE:-}" ]; then \
cd $SEMMLE_CODE; ./build target/intree/codeql-{{ LANGUAGE }}; \
CODEQL_CONFIG_FILE= $SEMMLE_CODE/target/intree/codeql-{{ LANGUAGE }}/codeql test run -j0 "$@"; \
else \
just install {{ LANGUAGE }}; \
codeql test run --search-path={{ source_dir() }} -j0 "$@"; \
fi

build LANGUAGE: (_build LANGUAGE)
install LANGUAGE: (_install LANGUAGE)
[no-cd, positional-arguments, no-exit-message]
@_integration_tests *ARGS:
if [ -n "${SEMMLE_CODE:-}" ]; then \
$SEMMLE_CODE/tools/pytest "$@"; \
else \
echo "integration tests require running from an internal repository working copy" >&2; \
exit 1; \
fi

[no-cd, script:'python3', positional-arguments, no-exit-message]
[group('test'), no-cd, script:'python3', positional-arguments, no-exit-message]
test +ARGS: # TODO: fuzzy test chooser when no arguments are provided!
import pathlib
import subprocess
Expand All @@ -43,20 +43,4 @@ test +ARGS: # TODO: fuzzy test chooser when no arguments are provided!
cwd=common_path).returncode
sys.exit(ret)

[no-cd, positional-arguments]
_run_language_tests LANGUAGE *ARGS: (_build LANGUAGE)
shift; \
if [ -n "${SEMMLE_CODE:-}" ]; then \
$SEMMLE_CODE/target/intree/codeql-{{ LANGUAGE }}/codeql test run "$@"; \
else \
codeql test run --search-path={{ source_dir() }} "$@"; \
fi

[no-cd, positional-arguments]
_run_integration_tests *ARGS:
if [ -n "${SEMMLE_CODE:-}" ]; then \
$SEMMLE_CODE/tools/pytest "$@"; \
else \
echo "integration tests require running from an internal repository working copy" >&2; \
exit 1; \
fi
alias t := test

0 comments on commit 066c6c3

Please sign in to comment.