Skip to content

Commit d7d7cf9

Browse files
committed
Just: format ts files
1 parent a4acf08 commit d7d7cf9

File tree

2 files changed

+109
-85
lines changed

2 files changed

+109
-85
lines changed

misc/just/codeql-test-run.ts

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ import * as child_process from "child_process";
22
import * as path from "path";
33
import * as os from "os";
44

5-
6-
7-
function invoke(invocation: string[], options: {cwd?: string, log_prefix?: string} = {}) : number {
8-
const log_prefix = options.log_prefix && options.log_prefix !== "" ? `${options.log_prefix} ` : "";
9-
console.log(`${process.env["CMD_BEGIN"] || ""}${log_prefix}${invocation.join(" ")}${process.env["CMD_END"] || ""}`);
5+
function invoke(
6+
invocation: string[],
7+
options: { cwd?: string; log_prefix?: string } = {},
8+
): number {
9+
const log_prefix =
10+
options.log_prefix && options.log_prefix !== ""
11+
? `${options.log_prefix} `
12+
: "";
13+
console.log(
14+
`${process.env["CMD_BEGIN"] || ""}${log_prefix}${invocation.join(" ")}${process.env["CMD_END"] || ""}`,
15+
);
1016
try {
11-
child_process.execFileSync(invocation[0], invocation.slice(1), { stdio: "inherit", cwd: options.cwd });
17+
child_process.execFileSync(invocation[0], invocation.slice(1), {
18+
stdio: "inherit",
19+
cwd: options.cwd,
20+
});
1221
} catch (error) {
1322
return 1;
1423
}
@@ -24,43 +33,40 @@ type Args = {
2433
};
2534

2635
function parseArgs(args: Args, argv: string) {
27-
argv
28-
.split(/(?<!\\) /)
29-
.forEach((arg) => {
30-
if (arg === "--no-build") {
31-
args.build = false;
32-
} else if (arg.startsWith("-")) {
33-
args.flags.push(arg);
34-
} else if (/^[A-Z_][A-Z_0-9]*=.*$/.test(arg)) {
35-
args.env.push(arg);
36-
} else if (/^\++$/.test(arg)) {
37-
args.testing_level = Math.max(args.testing_level, arg.length);
38-
} else if (arg !== "") {
39-
args.tests.push(arg);
40-
}
41-
});
36+
argv.split(/(?<!\\) /).forEach((arg) => {
37+
if (arg === "--no-build") {
38+
args.build = false;
39+
} else if (arg.startsWith("-")) {
40+
args.flags.push(arg);
41+
} else if (/^[A-Z_][A-Z_0-9]*=.*$/.test(arg)) {
42+
args.env.push(arg);
43+
} else if (/^\++$/.test(arg)) {
44+
args.testing_level = Math.max(args.testing_level, arg.length);
45+
} else if (arg !== "") {
46+
args.tests.push(arg);
47+
}
48+
});
4249
}
4350

44-
4551
function codeqlTestRun(argv: string[]): number {
4652
const [language, extra_args, ...plus] = argv;
47-
let codeql =
48-
process.env["SEMMLE_CODE"] ?
49-
path.join(process.env["SEMMLE_CODE"], "target", "intree", `codeql-${language}`, "codeql")
50-
:
51-
"codeql"
52-
;
53+
let codeql = process.env["SEMMLE_CODE"]
54+
? path.join(
55+
process.env["SEMMLE_CODE"],
56+
"target",
57+
"intree",
58+
`codeql-${language}`,
59+
"codeql",
60+
)
61+
: "codeql";
5362
const ram_per_thread = process.platform === "linux" ? 3000 : 2048;
5463
const cpus = os.cpus().length;
5564
let args: Args = {
5665
tests: [],
57-
flags: [
58-
`--ram=${ram_per_thread * cpus}`,
59-
`-j${cpus}`,
60-
],
66+
flags: [`--ram=${ram_per_thread * cpus}`, `-j${cpus}`],
6167
env: [],
6268
build: true,
63-
testing_level: 0
69+
testing_level: 0,
6470
};
6571
parseArgs(args, extra_args);
6672
for (let i = 0; i < Math.min(plus.length, args.testing_level); i++) {
@@ -72,11 +78,15 @@ function codeqlTestRun(argv: string[]): number {
7278
if (args.build && process.env["SEMMLE_CODE"]) {
7379
// If SEMMLE_CODE is set, we are in the semmle-code repo, so we build the codeql binary.
7480
// Otherwise, we use codeql from PATH.
75-
if (invoke(["python3", "build", `target/intree/codeql-${language}`], {cwd: process.env["SEMMLE_CODE"]}) !== 0) {
81+
if (
82+
invoke(["python3", "build", `target/intree/codeql-${language}`], {
83+
cwd: process.env["SEMMLE_CODE"],
84+
}) !== 0
85+
) {
7686
return 1;
7787
}
7888
}
79-
process.env["CODEQL_CONFIG_FILE"] ||= "." // disable the default implicit config file, but keep an explicit one
89+
process.env["CODEQL_CONFIG_FILE"] ||= "."; // disable the default implicit config file, but keep an explicit one
8090
// Set and unset environment variables
8191
args.env.forEach((envVar) => {
8292
const [key, value] = envVar.split("=", 2);
@@ -91,7 +101,9 @@ function codeqlTestRun(argv: string[]): number {
91101
process.exit(1);
92102
}
93103
});
94-
return invoke([codeql, "test", "run", ...args.flags, "--", ...args.tests], {log_prefix: args.env.join(" ")});
104+
return invoke([codeql, "test", "run", ...args.flags, "--", ...args.tests], {
105+
log_prefix: args.env.join(" "),
106+
});
95107
}
96108

97109
process.exit(codeqlTestRun(process.argv.slice(2)));

misc/just/forward-command.ts

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,75 @@ import * as path from "path";
33
import * as fs from "fs";
44

55
function commonDir(paths: string[]): string {
6-
if (paths.length === 0) return "";
7-
const splitPaths = paths.map(p => p.split(path.sep));
8-
let i;
9-
for (i = 0; i < splitPaths[0].length; i++) {
10-
if (!splitPaths.every(parts => parts[i] === splitPaths[0][i])) {
11-
break;
12-
}
6+
if (paths.length === 0) return "";
7+
const splitPaths = paths.map((p) => p.split(path.sep));
8+
let i;
9+
for (i = 0; i < splitPaths[0].length; i++) {
10+
if (!splitPaths.every((parts) => parts[i] === splitPaths[0][i])) {
11+
break;
12+
}
1313
}
1414
const commonParts = splitPaths[0].slice(0, i);
15-
let ret = commonParts.join(path.sep);
16-
if (!fs.existsSync(ret)) {
17-
throw new Error(`Common directory does not exist: ${ret}`);
18-
}
19-
if (!fs.lstatSync(ret).isDirectory()) {
20-
ret = path.dirname(ret);
21-
}
22-
return ret;
15+
let ret = commonParts.join(path.sep);
16+
if (!fs.existsSync(ret)) {
17+
throw new Error(`Common directory does not exist: ${ret}`);
18+
}
19+
if (!fs.lstatSync(ret).isDirectory()) {
20+
ret = path.dirname(ret);
21+
}
22+
return ret;
2323
}
2424

2525
function forwardCommand(args: string[]): number {
26-
// Avoid infinite recursion
27-
if (args.length == 0) {
28-
console.error("No command provided");
29-
return 1;
30-
}
31-
const cmd = args[0];
32-
const envVariable = `__JUST_FORWARD_${cmd}`;
33-
if (process.env[envVariable]) {
34-
console.error(`No common ${cmd} handler found`);
35-
return 1;
36-
}
37-
process.env[envVariable] = "true";
38-
const cmdArgs = args.slice(1);
39-
// non-positional arguments are flags, repeated + (used by language tests) or environment variable settings
40-
const is_non_positional = /^(-.*|\++|[A-Z_][A-Z_0-9]*=.*)$/;
41-
const flags = cmdArgs.filter(arg => is_non_positional.test(arg));
42-
const positionalArgs = cmdArgs.filter(arg => !is_non_positional.test(arg));
26+
// Avoid infinite recursion
27+
if (args.length == 0) {
28+
console.error("No command provided");
29+
return 1;
30+
}
31+
const cmd = args[0];
32+
const envVariable = `__JUST_FORWARD_${cmd}`;
33+
if (process.env[envVariable]) {
34+
console.error(`No common ${cmd} handler found`);
35+
return 1;
36+
}
37+
process.env[envVariable] = "true";
38+
const cmdArgs = args.slice(1);
39+
// non-positional arguments are flags, repeated + (used by language tests) or environment variable settings
40+
const is_non_positional = /^(-.*|\++|[A-Z_][A-Z_0-9]*=.*)$/;
41+
const flags = cmdArgs.filter((arg) => is_non_positional.test(arg));
42+
const positionalArgs = cmdArgs.filter(
43+
(arg) => !is_non_positional.test(arg),
44+
);
4345

44-
if (positionalArgs.length === 0) {
45-
console.error("No positional arguments provided");
46-
return 1;
47-
}
46+
if (positionalArgs.length === 0) {
47+
console.error("No positional arguments provided");
48+
return 1;
49+
}
4850

49-
const commonPath = commonDir(positionalArgs);
50-
let relativeArgs = positionalArgs.map(arg => path.relative(commonPath, arg) || ".");
51-
if (relativeArgs.length === 1 && relativeArgs[0] === ".") {
52-
relativeArgs = [];
53-
}
51+
const commonPath = commonDir(positionalArgs);
52+
let relativeArgs = positionalArgs.map(
53+
(arg) => path.relative(commonPath, arg) || ".",
54+
);
55+
if (relativeArgs.length === 1 && relativeArgs[0] === ".") {
56+
relativeArgs = [];
57+
}
5458

55-
const invocation = [process.env["JUST_EXECUTABLE"] || "just", cmd, ...flags, ...relativeArgs];
56-
console.log(`-> ${commonPath}: just ${invocation.slice(1).join(" ")}`);
57-
try {
58-
child_process.execFileSync(invocation[0], invocation.slice(1), { stdio: "inherit", cwd: commonPath });
59-
} catch (error) {
60-
return 1;
61-
}
62-
return 0;
59+
const invocation = [
60+
process.env["JUST_EXECUTABLE"] || "just",
61+
cmd,
62+
...flags,
63+
...relativeArgs,
64+
];
65+
console.log(`-> ${commonPath}: just ${invocation.slice(1).join(" ")}`);
66+
try {
67+
child_process.execFileSync(invocation[0], invocation.slice(1), {
68+
stdio: "inherit",
69+
cwd: commonPath,
70+
});
71+
} catch (error) {
72+
return 1;
73+
}
74+
return 0;
6375
}
6476

6577
process.exit(forwardCommand(process.argv.slice(2)));

0 commit comments

Comments
 (0)