diff --git a/java/ql/justfile b/java/ql/justfile index 7a46396fb85..ff0e4c1090f 100644 --- a/java/ql/justfile +++ b/java/ql/justfile @@ -1,6 +1,6 @@ import "../../lib.just" [no-cd] -format *ARGS=".": (_ql_format ARGS) +format *ARGS=".": (_format_ql ARGS) consistency_queries := source_dir() / "consistency-queries" diff --git a/misc/codegen/justfile b/misc/codegen/justfile index 9dd2019b5fa..8c1e8cdbab4 100644 --- a/misc/codegen/justfile +++ b/misc/codegen/justfile @@ -2,4 +2,4 @@ import "../just/lib.just" test *ARGS="": (_bazel "test" "@codeql//misc/codegen/...") -format *ARGS=".": (_black ARGS) \ No newline at end of file +format *ARGS=".": (_format_py ARGS) diff --git a/misc/just/build.just b/misc/just/build.just new file mode 100644 index 00000000000..226b52a76d3 --- /dev/null +++ b/misc/just/build.just @@ -0,0 +1,12 @@ +import "defs.just" + +_build_dist LANGUAGE: _require_semmle_code (_maybe_build_dist LANGUAGE) + +[no-exit-message] +_maybe_build_dist LANGUAGE: (_if_in_semmle_code ('cd "$SEMMLE_CODE"; tools/bazel run //language-packs:intree-' + LANGUAGE) '# using codeql from PATH, if any') + +[no-cd, no-exit-message] +_bazel COMMAND *ARGS: (_if_in_semmle_code 'cd "$SEMMLE_CODE"; tools/bazel' 'bazel' COMMAND ARGS) + +[no-cd, no-exit-message] +_sembuild *ARGS: (_run_in_semmle_code "./build" ARGS) diff --git a/misc/just/defs.just b/misc/just/defs.just new file mode 100644 index 00000000000..6f46b84597a --- /dev/null +++ b/misc/just/defs.just @@ -0,0 +1,58 @@ +import? '../../../semmle-code.just' # internal repo just file, if present +import 'semmle-code-stub.just' + +set fallback +set allow-duplicate-recipes +set allow-duplicate-variables +set unstable + +export PATH_SEP := if os() == "windows" { ";" } else { ":" } +export JUST_EXECUTABLE := just_executable() + +error := style("error") + "error" + NORMAL + ": " +cmd_sep := "\n#--------------------------------------------------------\n" +export CMD_BEGIN := style("command") + cmd_sep +export CMD_END := cmd_sep + NORMAL +export JUST_ERROR := error + +tsx := "npx tsx@4.19.0" + +default_db_checks := """\ + --check-databases \ + --check-diff-informed \ + --fail-on-trap-errors \ +""" + +[no-exit-message] +@_require_semmle_code: + {{ if SEMMLE_CODE == "" { ''' + echo "''' + error + ''' running this recipe requires doing so from an internal repository checkout" >&2 + exit 1 + ''' } else { "" } }} + +[no-cd] +_run +ARGS: + {{ cmd_sep }}{{ ARGS }}{{ cmd_sep }} + +[no-cd] +_run_in DIR +ARGS: + {{ cmd_sep }}cd "{{ DIR }}"; {{ ARGS }}{{ cmd_sep }} + +[no-cd] +_run_in_semmle_code +ARGS: _require_semmle_code (_run_in "$SEMMLE_CODE" ARGS) + +[no-cd, positional-arguments, no-exit-message] +@_just +ARGS: + echo "-> just $@" + "{{ JUST_EXECUTABLE }}" "$@" + +[no-cd, positional-arguments] +@_if_not_on_ci_just +ARGS: + if [ "${GITHUB_ACTIONS:-}" != "true" ]; then \ + echo "-> just $@"; \ + "$JUST_EXECUTABLE" "$@"; \ + fi + +[no-cd, no-exit-message] +_if_in_semmle_code THEN ELSE *ARGS: + {{ cmd_sep }}{{ if SEMMLE_CODE != "" { THEN } else { ELSE } }} {{ ARGS }}{{ cmd_sep }} diff --git a/misc/just/format.just b/misc/just/format.just new file mode 100644 index 00000000000..9430cb4c0a9 --- /dev/null +++ b/misc/just/format.just @@ -0,0 +1,20 @@ +import "build.just" + +[no-cd, no-exit-message] +_format_ql +ARGS: (_maybe_build_dist "nolang") ( + _if_in_semmle_code + '"$SEMMLE_CODE/target/intree/codeql-nolang/codeql"' + 'codeql' + ("query format --in-place -v $(find " + ARGS + " -type f -name '*.ql' -or -name '*.qll')") +) + +[no-cd, no-exit-message] +_format_py *ARGS=".": (_if_in_semmle_code "uv run black" "black" ARGS) + +[no-cd, no-exit-message] +_format_cpp *ARGS=".": ( + _if_in_semmle_code + "uv run clang-format" + "clang-format" + "-i --verbose $(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')" +) diff --git a/misc/just/lib.just b/misc/just/lib.just index 3379ab8ed37..7fd3156ba46 100644 --- a/misc/just/lib.just +++ b/misc/just/lib.just @@ -1,42 +1,5 @@ -set fallback -set allow-duplicate-recipes -set allow-duplicate-variables -set unstable - -export PATH_SEP := if os() == "windows" { ";" } else { ":" } -export JUST_EXECUTABLE := just_executable() - -error := style("error") + "error" + NORMAL + ": " -cmd_sep := "\n#--------------------------------------------------------\n" -export CMD_BEGIN := style("command") + cmd_sep -export CMD_END := cmd_sep + NORMAL -export JUST_ERROR := error - -tsx := "npx tsx@4.19.0" - -import? '../../../semmle-code.just' # internal repo just file, if present -import 'semmle-code-stub.just' - - -[no-exit-message] -@_require_semmle_code: - {{ if SEMMLE_CODE == "" { ''' - echo "''' + error + ''' running this recipe requires doing so from an internal repository checkout" >&2 - exit 1 - ''' } else { "" } }} - -_build_dist LANGUAGE: _require_semmle_code (_maybe_build_dist LANGUAGE) - -[no-exit-message] -_maybe_build_dist LANGUAGE: - {{ cmd_sep }}{{ if SEMMLE_CODE == "" { '# using codeql from PATH, if any' } else { 'cd "$SEMMLE_CODE"; tools/bazel run //language-packs:intree-' + LANGUAGE } }}{{ cmd_sep }} - - -default_db_checks := """\ - --check-databases \ - --check-diff-informed \ - --fail-on-trap-errors \ -""" +import "build.just" +import "format.just" [no-cd, positional-arguments, no-exit-message] @_codeql_test LANGUAGE BASE_FLAGS ALL_CHECKS_FLAGS EXTRA_ARGS: @@ -46,18 +9,8 @@ default_db_checks := """\ @_language_tests EXTRA_ARGS SOURCE_DIR +ROOTS: _require_semmle_code {{ tsx }} "{{ source_dir() }}/language-tests.ts" "$@" -[no-cd, no-exit-message] -_ql_format +ARGS: (_maybe_build_dist "nolang") - {{ cmd_sep }}{{ if SEMMLE_CODE != "" { '"$SEMMLE_CODE/target/intree/codeql-nolang/codeql"' } else { 'codeql' } }} query format --in-place $(find {{ ARGS }} -type f -name '*.ql' -or -name '*.qll'){{ cmd_sep }} -[no-cd, no-exit-message] -_bazel COMMAND *ARGS: - {{ cmd_sep }}{{ if SEMMLE_CODE != "" { 'cd "$SEMMLE_CODE"; tools/bazel' } else { 'bazel' } }} {{ COMMAND }} {{ ARGS }}{{ cmd_sep }} - -[no-cd, no-exit-message] -_sembuild *ARGS: (_run_in_semmle_code "./build" ARGS) - [no-cd, no-exit-message] _integration_test *ARGS: _require_semmle_code (_run "$SEMMLE_CODE/tools/pytest" ARGS) @@ -83,6 +36,3 @@ _run_in_semmle_code +ARGS: _require_semmle_code (_run_in "$SEMMLE_CODE" ARGS) echo "-> just $@"; \ "$JUST_EXECUTABLE" "$@"; \ fi - -[no-cd] -_black *ARGS=".": (_run "uv" "run" "black" ARGS) diff --git a/rust/ql/integration-tests/justfile b/rust/ql/integration-tests/justfile index 7f5aab6c508..ee967d781e6 100644 --- a/rust/ql/integration-tests/justfile +++ b/rust/ql/integration-tests/justfile @@ -7,4 +7,4 @@ test *ARGS=".": (_if_not_on_ci_just "generate" source_dir()) (_integration_test # TODO in separate PR # [no-cd] -# format *ARGS=".": (_ql_format ARGS) (_black ARGS) +# format *ARGS=".": (_format_ql ARGS) (_format_py ARGS) diff --git a/rust/ql/justfile b/rust/ql/justfile index 7a46396fb85..ff0e4c1090f 100644 --- a/rust/ql/justfile +++ b/rust/ql/justfile @@ -1,6 +1,6 @@ import "../../lib.just" [no-cd] -format *ARGS=".": (_ql_format ARGS) +format *ARGS=".": (_format_ql ARGS) consistency_queries := source_dir() / "consistency-queries" diff --git a/swift/justfile b/swift/justfile index f09fea32e52..72fa15c8156 100644 --- a/swift/justfile +++ b/swift/justfile @@ -1,4 +1,5 @@ import '../lib.just' +import "../../ql/swift/ql/justfile" install: (_bazel "run" "@codeql//swift:install") @@ -7,13 +8,7 @@ build: (_build_dist "swift") generate: (_bazel "run" "@codeql//swift/codegen") -@_check_clang_format: - if ! which clang-format > /dev/null; then \ - "{{ JUST_EXECUTABLE }}" _run_in_semmle_code "tools/bazel" "run" "//c/clang-format:install"; \ - fi - -format ARGS=".": _check_clang_format (_run "clang-format" "-i" ("$(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')")) -import "../../ql/swift/ql/justfile" +format ARGS=".": (_format_cpp ARGS) [group('test')] language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test') diff --git a/swift/ql/integration-tests/justfile b/swift/ql/integration-tests/justfile index 370f7ef8779..dabd36eebd1 100644 --- a/swift/ql/integration-tests/justfile +++ b/swift/ql/integration-tests/justfile @@ -6,4 +6,4 @@ test *ARGS=".": (_just "generate") (_integration_test ARGS) # TODO in separate PR # [no-cd] -# format *ARGS=".": (_ql_format ARGS) (_black ARGS) +# format *ARGS=".": (_format_ql ARGS) (_format_py ARGS) diff --git a/swift/ql/justfile b/swift/ql/justfile index 7a46396fb85..ff0e4c1090f 100644 --- a/swift/ql/justfile +++ b/swift/ql/justfile @@ -1,6 +1,6 @@ import "../../lib.just" [no-cd] -format *ARGS=".": (_ql_format ARGS) +format *ARGS=".": (_format_ql ARGS) consistency_queries := source_dir() / "consistency-queries"