summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/bench/mod.js2
-rw-r--r--tools/bench/rebench.js2
-rw-r--r--tools/bench/rebootstrap.js2
-rw-r--r--tools/copyright_checker.js18
-rwxr-xr-xtools/flamebench.js142
-rwxr-xr-xtools/format.js54
-rwxr-xr-xtools/lint.js50
-rw-r--r--tools/upload_wptfyi.js2
8 files changed, 120 insertions, 152 deletions
diff --git a/tools/bench/mod.js b/tools/bench/mod.js
index 685834281..9d90818a5 100644
--- a/tools/bench/mod.js
+++ b/tools/bench/mod.js
@@ -1,2 +1,4 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
export * from "./rebench.js";
export * from "./rebootstrap.js";
diff --git a/tools/bench/rebench.js b/tools/bench/rebench.js
index bbc5a3c2f..7d77a79cd 100644
--- a/tools/bench/rebench.js
+++ b/tools/bench/rebench.js
@@ -1,3 +1,5 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
export function benchSync(name, n, innerLoop) {
const t1 = Date.now();
for (let i = 0; i < n; i++) {
diff --git a/tools/bench/rebootstrap.js b/tools/bench/rebootstrap.js
index 6090843d8..0e94285d5 100644
--- a/tools/bench/rebootstrap.js
+++ b/tools/bench/rebootstrap.js
@@ -1,3 +1,5 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
import { dirname, fromFileUrl, join } from "../../test_util/std/path/mod.ts";
import { expandGlobSync } from "../../test_util/std/fs/mod.ts";
diff --git a/tools/copyright_checker.js b/tools/copyright_checker.js
index 706f59dbd..c8ddcdc91 100644
--- a/tools/copyright_checker.js
+++ b/tools/copyright_checker.js
@@ -1,4 +1,4 @@
-#!/usr/bin/env -S deno run --unstable --allow-read --allow-run
+#!/usr/bin/env -S deno run --unstable --allow-read=. --allow-run=git
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { getSources, ROOT_PATH } from "./util.js";
@@ -16,7 +16,7 @@ async function readFirstPartOfFile(filePath) {
}
}
-async function checkCopyright() {
+export async function checkCopyright() {
const sourceFiles = await getSources(ROOT_PATH, [
// js and ts
"*.js",
@@ -28,7 +28,6 @@ async function checkCopyright() {
":!:cli/tsc/*typescript.js",
":!:cli/tsc/compiler.d.ts",
":!:test_util/wpt/**",
- ":!:tools/**", // these files are starts with `#!/usr/bin/env`
":!:cli/tools/init/templates/**",
// rust
@@ -58,8 +57,9 @@ async function checkCopyright() {
continue;
}
+ // use .includes(...) because the first line might be a shebang
if (
- !fileText.startsWith(
+ !fileText.includes(
"// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.",
)
) {
@@ -68,17 +68,11 @@ async function checkCopyright() {
}
}
- console.log("\nTotal errors: " + totalCount);
-
if (totalCount > 0) {
- Deno.exit(1);
+ throw new Error(`Copyright checker had ${totalCount} errors.`);
}
}
-async function main() {
- await Deno.chdir(ROOT_PATH);
-
+if (import.meta.main) {
await checkCopyright();
}
-
-await main();
diff --git a/tools/flamebench.js b/tools/flamebench.js
index e471d2891..5d1fc161d 100755
--- a/tools/flamebench.js
+++ b/tools/flamebench.js
@@ -2,35 +2,49 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { join, ROOT_PATH as ROOT } from "./util.js";
-async function bashOut(subcmd) {
- const { success, stdout } = await new Deno.Command("bash", {
- args: ["-c", subcmd],
- stdout: "piped",
- stderr: "null",
- }).output();
+const { 0: benchName, 1: benchFilter } = Deno.args;
+// Print usage if no bench specified
+if (!benchName) {
+ console.log("flamebench.js <bench_name> [bench_filter]");
+ // Also show available benches
+ console.log("\nAvailable benches:");
+ const benches = await availableBenches();
+ console.log(benches.join("\n"));
+ return Deno.exit(1);
+}
- // Check for failure
- if (!success) {
- throw new Error("subcmd failed");
- }
- // Gather output
- const output = new TextDecoder().decode(stdout);
+// List available benches, hoping we don't have any benches called "ls" :D
+if (benchName === "ls") {
+ const benches = await availableBenches();
+ console.log(benches.join("\n"));
+ return;
+}
- return output.trim();
+// Ensure flamegraph is installed
+if (!await binExists("flamegraph")) {
+ console.log(
+ "flamegraph (https://github.com/flamegraph-rs/flamegraph) not found, please run:",
+ );
+ console.log();
+ console.log("cargo install flamegraph");
+ return Deno.exit(1);
}
-async function bashThrough(subcmd, opts = {}) {
- const { success, code } = await new Deno.Command("bash", {
- ...opts,
- args: ["-c", subcmd],
- stdout: "inherit",
- stderr: "inherit",
- }).output();
+// Build bench with frame pointers
+await bashThrough(
+ `RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
+);
- // Exit process on failure
- if (!success) {
- Deno.exit(code);
- }
+// Get the freshly built bench binary
+const benchBin = await latestBenchBin(benchName);
+
+// Run flamegraph
+const outputFile = join(ROOT, "flamebench.svg");
+await runFlamegraph(benchBin, benchFilter, outputFile);
+
+// Open flamegraph (in your browser / SVG viewer)
+if (await binExists("open")) {
+ await bashThrough(`open ${outputFile}`);
}
async function availableBenches() {
@@ -59,60 +73,42 @@ function runFlamegraph(benchBin, benchFilter, outputFile) {
);
}
-async function binExists(bin) {
- try {
- await bashOut(`which ${bin}`);
- return true;
- } catch (_) {
- return false;
- }
-}
-
-async function main() {
- const { 0: benchName, 1: benchFilter } = Deno.args;
- // Print usage if no bench specified
- if (!benchName) {
- console.log("flamebench.js <bench_name> [bench_filter]");
- // Also show available benches
- console.log("\nAvailable benches:");
- const benches = await availableBenches();
- console.log(benches.join("\n"));
- return Deno.exit(1);
- }
-
- // List available benches, hoping we don't have any benches called "ls" :D
- if (benchName === "ls") {
- const benches = await availableBenches();
- console.log(benches.join("\n"));
- return;
- }
+async function bashOut(subcmd) {
+ const { success, stdout } = await new Deno.Command("bash", {
+ args: ["-c", subcmd],
+ stdout: "piped",
+ stderr: "null",
+ }).output();
- // Ensure flamegraph is installed
- if (!await binExists("flamegraph")) {
- console.log(
- "flamegraph (https://github.com/flamegraph-rs/flamegraph) not found, please run:",
- );
- console.log();
- console.log("cargo install flamegraph");
- return Deno.exit(1);
+ // Check for failure
+ if (!success) {
+ throw new Error("subcmd failed");
}
+ // Gather output
+ const output = new TextDecoder().decode(stdout);
- // Build bench with frame pointers
- await bashThrough(
- `RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
- );
+ return output.trim();
+}
- // Get the freshly built bench binary
- const benchBin = await latestBenchBin(benchName);
+async function bashThrough(subcmd, opts = {}) {
+ const { success, code } = await new Deno.Command("bash", {
+ ...opts,
+ args: ["-c", subcmd],
+ stdout: "inherit",
+ stderr: "inherit",
+ }).output();
- // Run flamegraph
- const outputFile = join(ROOT, "flamebench.svg");
- await runFlamegraph(benchBin, benchFilter, outputFile);
+ // Exit process on failure
+ if (!success) {
+ Deno.exit(code);
+ }
+}
- // Open flamegraph (in your browser / SVG viewer)
- if (await binExists("open")) {
- await bashThrough(`open ${outputFile}`);
+async function binExists(bin) {
+ try {
+ await bashOut(`which ${bin}`);
+ return true;
+ } catch (_) {
+ return false;
}
}
-// Run
-await main();
diff --git a/tools/format.js b/tools/format.js
index 223eb1b0d..bd34b1cfd 100755
--- a/tools/format.js
+++ b/tools/format.js
@@ -2,45 +2,15 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js";
-async function dprint() {
- const configFile = join(ROOT_PATH, ".dprint.json");
- const execPath = getPrebuiltToolPath("dprint");
- const cmd = new Deno.Command(execPath, {
- args: ["fmt", "--config=" + configFile],
- stdout: "inherit",
- stderr: "inherit",
- });
-
- const { code } = await cmd.output();
-
- if (code > 0) {
- throw new Error("dprint failed");
- }
-}
-
-async function main() {
- await Deno.chdir(ROOT_PATH);
- await dprint();
-
- if (Deno.args.includes("--check")) {
- const cmd = new Deno.Command("git", {
- args: ["status", "-uno", "--porcelain", "--ignore-submodules"],
- stderr: "inherit",
- });
-
- const { code, stdout } = await cmd.output();
-
- if (code > 0) {
- throw new Error("git status failed");
- }
- const out = new TextDecoder().decode(stdout);
-
- if (out) {
- console.log("run tools/format.js");
- console.log(out);
- Deno.exit(1);
- }
- }
-}
-
-await main();
+const subcommand = Deno.args.includes("--check") ? "check" : "fmt";
+const configFile = join(ROOT_PATH, ".dprint.json");
+const execPath = getPrebuiltToolPath("dprint");
+const cmd = new Deno.Command(execPath, {
+ args: [subcommand, "--config=" + configFile],
+ cwd: ROOT_PATH,
+ stdout: "inherit",
+ stderr: "inherit",
+});
+
+const { code } = await cmd.output();
+Deno.exit(code);
diff --git a/tools/lint.js b/tools/lint.js
index c460951f5..caa761896 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -7,6 +7,28 @@ import {
join,
ROOT_PATH,
} from "./util.js";
+import { checkCopyright } from "./copyright_checker.js";
+
+let didLint = false;
+
+if (Deno.args.includes("--js")) {
+ await dlint();
+ await dlintPreferPrimordials();
+ didLint = true;
+}
+
+if (Deno.args.includes("--rs")) {
+ await clippy();
+ didLint = true;
+}
+
+if (!didLint) {
+ await dlint();
+ await dlintPreferPrimordials();
+ console.log("copyright checker");
+ await checkCopyright();
+ await clippy();
+}
async function dlint() {
const configFile = join(ROOT_PATH, ".dlint.json");
@@ -44,6 +66,7 @@ async function dlint() {
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
for (const chunk of chunks) {
const cmd = new Deno.Command(execPath, {
+ cwd: ROOT_PATH,
args: ["run", "--config=" + configFile, ...chunk],
stdout: "inherit",
stderr: "inherit",
@@ -77,6 +100,7 @@ async function dlintPreferPrimordials() {
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
for (const chunk of chunks) {
const cmd = new Deno.Command(execPath, {
+ cwd: ROOT_PATH,
args: ["run", "--rule", "prefer-primordials", ...chunk],
stdout: "inherit",
stderr: "inherit",
@@ -116,6 +140,7 @@ async function clippy() {
}
const cargoCmd = new Deno.Command("cargo", {
+ cwd: ROOT_PATH,
args: [
...cmd,
"--",
@@ -131,28 +156,3 @@ async function clippy() {
throw new Error("clippy failed");
}
}
-
-async function main() {
- await Deno.chdir(ROOT_PATH);
-
- let didLint = false;
-
- if (Deno.args.includes("--js")) {
- await dlint();
- await dlintPreferPrimordials();
- didLint = true;
- }
-
- if (Deno.args.includes("--rs")) {
- await clippy();
- didLint = true;
- }
-
- if (!didLint) {
- await dlint();
- await dlintPreferPrimordials();
- await clippy();
- }
-}
-
-await main();
diff --git a/tools/upload_wptfyi.js b/tools/upload_wptfyi.js
index 476c1981d..d57347eb0 100644
--- a/tools/upload_wptfyi.js
+++ b/tools/upload_wptfyi.js
@@ -1,3 +1,5 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
// This script pushes new WPT results to wpt.fyi. When the `--ghstatus` flag is
// passed, will automatically add a status check to the commit with a link to
// the wpt.fyi page.