Skip to content

Commit 0e3ee6e

Browse files
committed
Just: reorganize code and revamp formatting
1 parent 365b2eb commit 0e3ee6e

File tree

11 files changed

+100
-65
lines changed

11 files changed

+100
-65
lines changed

java/ql/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "../../lib.just"
22

33
[no-cd]
4-
format *ARGS=".": (_ql_format ARGS)
4+
format *ARGS=".": (_format_ql ARGS)
55

66
consistency_queries := source_dir() / "consistency-queries"

misc/codegen/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import "../just/lib.just"
22

33
test *ARGS="": (_bazel "test" "@codeql//misc/codegen/...")
44

5-
format *ARGS=".": (_black ARGS)
5+
format *ARGS=".": (_format_py ARGS)

misc/just/build.just

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "defs.just"
2+
3+
_build_dist LANGUAGE: _require_semmle_code (_maybe_build_dist LANGUAGE)
4+
5+
[no-exit-message]
6+
_maybe_build_dist LANGUAGE: (_if_in_semmle_code ('cd "$SEMMLE_CODE"; tools/bazel run //language-packs:intree-' + LANGUAGE) '# using codeql from PATH, if any')
7+
8+
[no-cd, no-exit-message]
9+
_bazel COMMAND *ARGS: (_if_in_semmle_code 'cd "$SEMMLE_CODE"; tools/bazel' 'bazel' COMMAND ARGS)
10+
11+
[no-cd, no-exit-message]
12+
_sembuild *ARGS: (_run_in_semmle_code "./build" ARGS)

misc/just/defs.just

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import? '../../../semmle-code.just' # internal repo just file, if present
2+
import 'semmle-code-stub.just'
3+
4+
set fallback
5+
set allow-duplicate-recipes
6+
set allow-duplicate-variables
7+
set unstable
8+
9+
export PATH_SEP := if os() == "windows" { ";" } else { ":" }
10+
export JUST_EXECUTABLE := just_executable()
11+
12+
error := style("error") + "error" + NORMAL + ": "
13+
cmd_sep := "\n#--------------------------------------------------------\n"
14+
export CMD_BEGIN := style("command") + cmd_sep
15+
export CMD_END := cmd_sep + NORMAL
16+
export JUST_ERROR := error
17+
18+
tsx := "npx tsx@4.19.0"
19+
20+
default_db_checks := """\
21+
--check-databases \
22+
--check-diff-informed \
23+
--fail-on-trap-errors \
24+
"""
25+
26+
[no-exit-message]
27+
@_require_semmle_code:
28+
{{ if SEMMLE_CODE == "" { '''
29+
echo "''' + error + ''' running this recipe requires doing so from an internal repository checkout" >&2
30+
exit 1
31+
''' } else { "" } }}
32+
33+
[no-cd]
34+
_run +ARGS:
35+
{{ cmd_sep }}{{ ARGS }}{{ cmd_sep }}
36+
37+
[no-cd]
38+
_run_in DIR +ARGS:
39+
{{ cmd_sep }}cd "{{ DIR }}"; {{ ARGS }}{{ cmd_sep }}
40+
41+
[no-cd]
42+
_run_in_semmle_code +ARGS: _require_semmle_code (_run_in "$SEMMLE_CODE" ARGS)
43+
44+
[no-cd, positional-arguments, no-exit-message]
45+
@_just +ARGS:
46+
echo "-> just $@"
47+
"{{ JUST_EXECUTABLE }}" "$@"
48+
49+
[no-cd, positional-arguments]
50+
@_if_not_on_ci_just +ARGS:
51+
if [ "${GITHUB_ACTIONS:-}" != "true" ]; then \
52+
echo "-> just $@"; \
53+
"$JUST_EXECUTABLE" "$@"; \
54+
fi
55+
56+
[no-cd, no-exit-message]
57+
_if_in_semmle_code THEN ELSE *ARGS:
58+
{{ cmd_sep }}{{ if SEMMLE_CODE != "" { THEN } else { ELSE } }} {{ ARGS }}{{ cmd_sep }}

misc/just/format.just

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import "build.just"
2+
3+
[no-cd, no-exit-message]
4+
_format_ql +ARGS: (_maybe_build_dist "nolang") (
5+
_if_in_semmle_code
6+
'"$SEMMLE_CODE/target/intree/codeql-nolang/codeql"'
7+
'codeql'
8+
("query format --in-place -v $(find " + ARGS + " -type f -name '*.ql' -or -name '*.qll')")
9+
)
10+
11+
[no-cd, no-exit-message]
12+
_format_py *ARGS=".": (_if_in_semmle_code "uv run black" "black" ARGS)
13+
14+
[no-cd, no-exit-message]
15+
_format_cpp *ARGS=".": (
16+
_if_in_semmle_code
17+
"uv run clang-format"
18+
"clang-format"
19+
"-i --verbose $(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')"
20+
)

misc/just/lib.just

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,5 @@
1-
set fallback
2-
set allow-duplicate-recipes
3-
set allow-duplicate-variables
4-
set unstable
5-
6-
export PATH_SEP := if os() == "windows" { ";" } else { ":" }
7-
export JUST_EXECUTABLE := just_executable()
8-
9-
error := style("error") + "error" + NORMAL + ": "
10-
cmd_sep := "\n#--------------------------------------------------------\n"
11-
export CMD_BEGIN := style("command") + cmd_sep
12-
export CMD_END := cmd_sep + NORMAL
13-
export JUST_ERROR := error
14-
15-
tsx := "npx tsx@4.19.0"
16-
17-
import? '../../../semmle-code.just' # internal repo just file, if present
18-
import 'semmle-code-stub.just'
19-
20-
21-
[no-exit-message]
22-
@_require_semmle_code:
23-
{{ if SEMMLE_CODE == "" { '''
24-
echo "''' + error + ''' running this recipe requires doing so from an internal repository checkout" >&2
25-
exit 1
26-
''' } else { "" } }}
27-
28-
_build_dist LANGUAGE: _require_semmle_code (_maybe_build_dist LANGUAGE)
29-
30-
[no-exit-message]
31-
_maybe_build_dist LANGUAGE:
32-
{{ cmd_sep }}{{ if SEMMLE_CODE == "" { '# using codeql from PATH, if any' } else { 'cd "$SEMMLE_CODE"; tools/bazel run //language-packs:intree-' + LANGUAGE } }}{{ cmd_sep }}
33-
34-
35-
default_db_checks := """\
36-
--check-databases \
37-
--check-diff-informed \
38-
--fail-on-trap-errors \
39-
"""
1+
import "build.just"
2+
import "format.just"
403

414
[no-cd, positional-arguments, no-exit-message]
425
@_codeql_test LANGUAGE BASE_FLAGS ALL_CHECKS_FLAGS EXTRA_ARGS:
@@ -46,17 +9,7 @@ default_db_checks := """\
469
@_language_tests EXTRA_ARGS SOURCE_DIR +ROOTS: _require_semmle_code
4710
{{ tsx }} "{{ source_dir() }}/language-tests.ts" "$@"
4811

49-
[no-cd, no-exit-message]
50-
_ql_format +ARGS: (_maybe_build_dist "nolang")
51-
{{ 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 }}
52-
53-
54-
[no-cd, no-exit-message]
55-
_bazel COMMAND *ARGS:
56-
{{ cmd_sep }}{{ if SEMMLE_CODE != "" { 'cd "$SEMMLE_CODE"; tools/bazel' } else { 'bazel' } }} {{ COMMAND }} {{ ARGS }}{{ cmd_sep }}
5712

58-
[no-cd, no-exit-message]
59-
_sembuild *ARGS: (_run_in_semmle_code "./build" ARGS)
6013

6114
[no-cd, no-exit-message]
6215
_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)
8336
echo "-> just $@"; \
8437
"$JUST_EXECUTABLE" "$@"; \
8538
fi
86-
87-
[no-cd]
88-
_black *ARGS=".": (_run "uv" "run" "black" ARGS)

rust/ql/integration-tests/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ test *ARGS=".": (_if_not_on_ci_just "generate" source_dir()) (_integration_test
77

88
# TODO in separate PR
99
# [no-cd]
10-
# format *ARGS=".": (_ql_format ARGS) (_black ARGS)
10+
# format *ARGS=".": (_format_ql ARGS) (_format_py ARGS)

rust/ql/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "../../lib.just"
22

33
[no-cd]
4-
format *ARGS=".": (_ql_format ARGS)
4+
format *ARGS=".": (_format_ql ARGS)
55

66
consistency_queries := source_dir() / "consistency-queries"

swift/justfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import '../lib.just'
2+
import "../../ql/swift/ql/justfile"
23

34
install: (_bazel "run" "@codeql//swift:install")
45

@@ -7,13 +8,7 @@ build: (_build_dist "swift")
78

89
generate: (_bazel "run" "@codeql//swift/codegen")
910

10-
@_check_clang_format:
11-
if ! which clang-format > /dev/null; then \
12-
"{{ JUST_EXECUTABLE }}" _run_in_semmle_code "tools/bazel" "run" "//c/clang-format:install"; \
13-
fi
14-
15-
format ARGS=".": _check_clang_format (_run "clang-format" "-i" ("$(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')"))
16-
import "../../ql/swift/ql/justfile"
11+
format ARGS=".": (_format_cpp ARGS)
1712

1813
[group('test')]
1914
language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test')

swift/ql/integration-tests/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ test *ARGS=".": (_just "generate") (_integration_test ARGS)
66

77
# TODO in separate PR
88
# [no-cd]
9-
# format *ARGS=".": (_ql_format ARGS) (_black ARGS)
9+
# format *ARGS=".": (_format_ql ARGS) (_format_py ARGS)

0 commit comments

Comments
 (0)