Skip to content

Just: introduce common "verbs" #19978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c284b1
Just: introduce scaffolding for common verbs, and apply to rust
redsun82 Jul 4, 2025
1202af1
Just: fix for windows
redsun82 Jul 4, 2025
2dea9da
Just: add `codegen`
redsun82 Jul 4, 2025
9e31fb5
Just: fix and add windows
redsun82 Jul 4, 2025
4768eba
Merge branch 'main' into redsun82/just2
redsun82 Jul 4, 2025
5b9436a
Just: fix swift tests
redsun82 Jul 4, 2025
812fc23
Merge branch 'main' into redsun82/just2
redsun82 Jul 7, 2025
a4acf08
Just: fix ram option for `codeql test run`
redsun82 Jul 7, 2025
d7d7cf9
Just: format `ts` files
redsun82 Jul 7, 2025
6e14111
Just: use `--all-checks` and `--codeql` special flags, and relativize…
redsun82 Jul 7, 2025
cb652f3
Just: add `format` to just directory
redsun82 Jul 7, 2025
fba96c4
Just: add root `lib.just`
redsun82 Jul 7, 2025
c430515
Just: simplify forwarder using `--justfile`
redsun82 Jul 8, 2025
acc7e3f
Just: add `generate` prerequisite to rust ql tests
redsun82 Jul 8, 2025
e8bcbbd
Just: add `language-tests.ts` helper
redsun82 Jul 8, 2025
d987aa6
Merge branch 'main' into redsun82/just2
redsun82 Jul 8, 2025
bb467d4
Just: fix CI build for rust
redsun82 Jul 8, 2025
8ba7efd
Just: fix mono-argument case for argumentless recipes
redsun82 Jul 8, 2025
aa09288
Just: introduce aliases
redsun82 Jul 8, 2025
7f72f87
Just: fix `just rust format` and similar
redsun82 Jul 8, 2025
b8b01ce
Just: rename `_build` to `_build_dist`
redsun82 Jul 8, 2025
0809715
Merge branch 'main' into redsun82/just2
redsun82 Jul 8, 2025
bd003c5
Just: add `_if_not_on_ci_just` helper, and add generation prerequisites
redsun82 Jul 8, 2025
c9cda74
Just: allow mixing different verb implementations
redsun82 Jul 9, 2025
c51f2f8
Merge branch 'main' into redsun82/just2
redsun82 Jul 9, 2025
9267283
Merge branch 'main' into redsun82/just2
redsun82 Jul 10, 2025
103745b
Just: group just invocations in forwarder and improve logging
redsun82 Jul 10, 2025
7e7afba
Merge branch 'main' into redsun82/just2
redsun82 Jul 17, 2025
f2a6503
Just: use bazel directly for dist building
redsun82 Jul 18, 2025
365b2eb
Merge branch 'main' into redsun82/just2
redsun82 Jul 18, 2025
0e3ee6e
Just: reorganize code and revamp formatting
redsun82 Jul 18, 2025
4284d66
Merge branch 'main' into redsun82/just2
redsun82 Jul 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions java/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../lib.just'

build: (_build_dist "java")
6 changes: 6 additions & 0 deletions java/ql/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "../../lib.just"

[no-cd]
format *ARGS=".": (_format_ql ARGS)

consistency_queries := source_dir() / "consistency-queries"
16 changes: 16 additions & 0 deletions java/ql/test/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "../justfile"

base_flags := """\
CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT="\\ " \
"""

all_checks := default_db_checks + """\
--check-undefined-labels \
--check-repeated-labels \
--check-redefined-labels \
--check-use-before-definition \
--consistency-queries=""" + consistency_queries

[no-cd]
test *ARGS=".": (_codeql_test "java" base_flags all_checks ARGS)

2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'misc/just/lib.just'
import 'misc/just/forward.just'
1 change: 1 addition & 0 deletions lib.just
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "misc/just/lib.just"
5 changes: 5 additions & 0 deletions misc/bazel/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../just/lib.just'

[no-cd, positional-arguments, no-exit-message]
hello +ARGS:
@echo "hello from bzl" "$@"
5 changes: 5 additions & 0 deletions misc/codegen/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "../just/lib.just"

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

format *ARGS=".": (_format_py ARGS)
12 changes: 12 additions & 0 deletions misc/just/build.just
Original file line number Diff line number Diff line change
@@ -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)
156 changes: 156 additions & 0 deletions misc/just/codeql-test-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import * as child_process from "child_process";
import * as path from "path";
import * as os from "os";
import * as fs from "fs";

const vars = {
just: process.env["JUST_EXECUTABLE"] || "just",
error: process.env["JUST_ERROR"] || "error",
cmd_begin: process.env["CMD_BEGIN"] || "",
cmd_end: process.env["CMD_END"] || "",
semmle_code: process.env["SEMMLE_CODE"],
}

function invoke(
invocation: string[],
options: { cwd?: string; log_prefix?: string } = {},
): number {
const log_prefix =
options.log_prefix && options.log_prefix !== ""
? `${options.log_prefix} `
: "";
console.log(
`${vars.cmd_begin}${log_prefix}${invocation.join(" ")}${vars.cmd_end}`,
);
try {
child_process.execFileSync(invocation[0], invocation.slice(1), {
stdio: "inherit",
cwd: options.cwd,
});
} catch (error) {
return 1;
}
return 0;
}

type Args = {
tests: string[];
flags: string[];
env: string[];
codeql: string;
all: boolean;
};

const old_console_error = console.error;

console.error = (message: string) => {
old_console_error(vars.error + message);
};

function parseArgs(args: Args, argv: string) {
argv.split(/(?<!\\) /)
.map((arg) => arg.replace("\\ ", " "))
.forEach((arg) => {
if (arg.startsWith("--codeql=")) {
args.codeql = arg.split("=")[1];
} else if (arg === "+" || arg === "--all-checks") {
args.all = true;
} else if (arg.startsWith("-")) {
args.flags.push(arg);
} else if (/^[A-Z_][A-Z_0-9]*=.*$/.test(arg)) {
args.env.push(arg);
} else if (arg !== "") {
args.tests.push(arg);
}
});
}

function codeqlTestRun(argv: string[]): number {
const [language, base_args, all_args, extra_args] = argv;
const ram_per_thread = process.platform === "linux" ? 3000 : 2048;
const cpus = os.cpus().length;
let args: Args = {
tests: [],
flags: [`--ram=${ram_per_thread * cpus}`, `-j${cpus}`],
env: [],
codeql: vars.semmle_code ? "build" : "host",
all: false,
};
parseArgs(args, base_args);
parseArgs(args, extra_args);
if (args.all) {
parseArgs(args, all_args);
}
if (!vars.semmle_code && (args.codeql === "build" || args.codeql === "built")) {
console.error(
"Using `--codeql=build` or `--codeql=built` requires working with the internal repository",
);
return 1;
}
if (args.tests.length === 0) {
args.tests.push(".");
}
if (args.codeql === "build") {
if (
invoke([vars.just, language, "build"], {
cwd: vars.semmle_code,
}) !== 0
) {
return 1;
}
}
if (args.codeql !== "host") {
// disable the default implicit config file, but keep an explicit one
// this is the same behavior wrt to `--codeql` as the integration test runner
process.env["CODEQL_CONFIG_FILE"] ||= ".";
}
// Set and unset environment variables
args.env.forEach((envVar) => {
const [key, value] = envVar.split("=", 2);
if (key) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
} else {
console.error(`Invalid environment variable assignment: ${envVar}`);
process.exit(1);
}
});
let codeql;
function check_codeql() {
if (!fs.existsSync(codeql)) {
console.error(`CodeQL executable not found: ${codeql}`);
process.exit(1);
}
}
if (args.codeql === "built" || args.codeql === "build") {
codeql = path.join(
vars.semmle_code!,
"target",
"intree",
`codeql-${language}`,
"codeql",
);
check_codeql();
} else if (args.codeql === "host") {
codeql = "codeql";
} else {
codeql = args.codeql;
check_codeql();
}
if (fs.lstatSync(codeql).isDirectory()) {
codeql = path.join(codeql, "codeql");
if (process.platform === "win32") {
codeql += ".exe";
}
check_codeql();
}

return invoke([codeql, "test", "run", ...args.flags, "--", ...args.tests], {
log_prefix: args.env.join(" "),
});
}

process.exit(codeqlTestRun(process.argv.slice(2)));
58 changes: 58 additions & 0 deletions misc/just/defs.just
Original file line number Diff line number Diff line change
@@ -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 }}
20 changes: 20 additions & 0 deletions misc/just/format.just
Original file line number Diff line number Diff line change
@@ -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')"
)
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy