Content-Length: 601296 | pFad | http://github.com/github/codeql/pull/19978/commits/6e14111337ca02bdc6a65e228ddd6aa4f912f4e9

0D Just: introduce common "verbs" by redsun82 · Pull Request #19978 · github/codeql · GitHub
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 1 commit
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
Prev Previous commit
Next Next commit
Just: use --all-checks and --codeql special flags, and relativize…
… flags in forwarder
  • Loading branch information
redsun82 committed Jul 7, 2025
commit 6e14111337ca02bdc6a65e228ddd6aa4f912f4e9
3 changes: 3 additions & 0 deletions java/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../misc/just/lib.just'

build: (_build "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 "../../misc/just/lib.just"

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

consistency_queries := source_dir() / "consistency-queries"
15 changes: 15 additions & 0 deletions java/ql/test/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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)
97 changes: 63 additions & 34 deletions misc/just/codeql-test-run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as child_process from "child_process";
import * as path from "path";
import * as os from "os";
import * as fs from "fs";

function invoke(
invocation: string[],
Expand Down Expand Up @@ -28,65 +29,68 @@ type Args = {
tests: string[];
flags: string[];
env: string[];
build: boolean;
testing_level: number;
codeql: string;
all: boolean;
};

function parseArgs(args: Args, argv: string) {
argv.split(/(?<!\\) /).forEach((arg) => {
if (arg === "--no-build") {
args.build = false;
} else if (arg.startsWith("-")) {
args.flags.push(arg);
} else if (/^[A-Z_][A-Z_0-9]*=.*$/.test(arg)) {
args.env.push(arg);
} else if (/^\++$/.test(arg)) {
args.testing_level = Math.max(args.testing_level, arg.length);
} else if (arg !== "") {
args.tests.push(arg);
}
});
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, extra_args, ...plus] = argv;
let codeql = process.env["SEMMLE_CODE"]
? path.join(
process.env["SEMMLE_CODE"],
"target",
"intree",
`codeql-${language}`,
"codeql",
)
: "codeql";
const semmle_code = process.env["SEMMLE_CODE"];
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: [],
build: true,
testing_level: 0,
codeql: semmle_code ? "build" : "host",
all: false,
};
parseArgs(args, base_args);
parseArgs(args, extra_args);
for (let i = 0; i < Math.min(plus.length, args.testing_level); i++) {
parseArgs(args, plus[i]);
if (args.all) {
parseArgs(args, all_args);
}
if (!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.build && process.env["SEMMLE_CODE"]) {
// If SEMMLE_CODE is set, we are in the semmle-code repo, so we build the codeql binary.
// Otherwise, we use codeql from PATH.
if (args.codeql === "build") {
if (
invoke(["python3", "build", `target/intree/codeql-${language}`], {
cwd: process.env["SEMMLE_CODE"],
cwd: semmle_code,
}) !== 0
) {
return 1;
}
}
process.env["CODEQL_CONFIG_FILE"] ||= "."; // disable the default implicit config file, but keep an explicit one
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);
Expand All @@ -101,6 +105,31 @@ function codeqlTestRun(argv: string[]): number {
process.exit(1);
}
});
let codeql;
if (args.codeql === "built" || args.codeql === "build") {
codeql = path.join(
semmle_code!,
"target",
"intree",
`codeql-${language}`,
"codeql",
);
} else if (args.codeql === "host") {
codeql = "codeql";
} else {
codeql = args.codeql;
if (fs.lstatSync(codeql).isDirectory()) {
codeql = path.join(codeql, "codeql");
if (process.platform === "win32") {
codeql += ".exe";
}
}
if (!fs.existsSync(codeql)) {
console.error(`CodeQL executable not found: ${codeql}`);
return 1;
}
}

return invoke([codeql, "test", "run", ...args.flags, "--", ...args.tests], {
log_prefix: args.env.join(" "),
});
Expand Down
21 changes: 18 additions & 3 deletions misc/just/forward-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function forwardCommand(args: string[]): number {
}
process.env[envVariable] = "true";
const cmdArgs = args.slice(1);
// non-positional arguments are flags, repeated + (used by language tests) or environment variable settings
const is_non_positional = /^(-.*|\++|[A-Z_][A-Z_0-9]*=.*)$/;
// non-positional arguments are flags, + (used by language tests) or environment variable settings
const is_non_positional = /^(-.*|\+|[A-Z_][A-Z_0-9]*=.*)$/;
const flags = cmdArgs.filter((arg) => is_non_positional.test(arg));
const positionalArgs = cmdArgs.filter(
(arg) => !is_non_positional.test(arg),
Expand All @@ -55,11 +55,26 @@ function forwardCommand(args: string[]): number {
if (relativeArgs.length === 1 && relativeArgs[0] === ".") {
relativeArgs = [];
}
let relativeFlags = flags.map((arg) => {
// this might break in specific corner cases, but is good enough for most uses
// workaround if this doesn't work is to not use the forwarder (call just directly in the relevant directory)
if (arg.includes("=") && arg.includes(path.sep)) {
let [flags, flag_arg] = arg.split("=", 2);
flag_arg = flag_arg
.split(path.delimiter)
.map((p) =>
path.isAbsolute(p) ? p : path.relative(commonPath, p),
)
.join(path.delimiter);
return `${flags}=${flag_arg}`;
}
return arg;
});

const invocation = [
process.env["JUST_EXECUTABLE"] || "just",
cmd,
...flags,
...relativeFlags,
...relativeArgs,
];
console.log(`-> ${commonPath}: just ${invocation.slice(1).join(" ")}`);
Expand Down
2 changes: 1 addition & 1 deletion misc/just/lib.just
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ default_db_checks := """\
"""

[no-cd, positional-arguments, no-exit-message]
@_codeql_test LANGUAGE +ARGS:
@_codeql_test LANGUAGE BASE_FLAGS ALL_CHECKS_FLAGS EXTRA_ARGS:
{{ tsx }} "{{ source_dir() }}/codeql-test-run.ts" "$@"


Expand Down
7 changes: 3 additions & 4 deletions rust/ql/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import "../../misc/just/lib.just"
[no-cd]
format *ARGS=".": (_ql_format ARGS)

db_checks := default_db_checks

consistency := "--consistency-queries=" + source_dir() / "consistency-queries"
all_checks := default_db_checks + """\
--consistency-queries=""" + source_dir() / "consistency-queries"

[no-cd]
test *ARGS=".": (_codeql_test "rust" ARGS db_checks consistency)
test *ARGS=".": (_codeql_test "rust" "" all_checks ARGS)
7 changes: 3 additions & 4 deletions swift/ql/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import "../../misc/just/lib.just"
[no-cd]
format *ARGS=".": (_ql_format ARGS)

db_checks := default_db_checks + """\
all_checks := default_db_checks + """\
--check-repeated-labels \
--check-redefined-labels \
--check-use-before-definition \
"""
--consistency-queries=""" + source_dir() / "consistency-queries"

consistency := "--consistency-queries=" + source_dir() / "consistency-queries"

[no-cd]
test *ARGS=".": (_codeql_test "swift" ARGS db_checks consistency)
test *ARGS=".": (_codeql_test "swift" "" all_checks ARGS)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql/pull/19978/commits/6e14111337ca02bdc6a65e228ddd6aa4f912f4e9

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy