mirror of
https://github.com/denoland/deno.git
synced 2025-02-23 13:43:31 -05:00
chore: small cleanup of scripts in ./tools and run copyright checker in lint.js (#17393)
This commit is contained in:
parent
9806dcc914
commit
0eb68246da
8 changed files with 121 additions and 153 deletions
|
@ -1,2 +1,4 @@
|
||||||
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
export * from "./rebench.js";
|
export * from "./rebench.js";
|
||||||
export * from "./rebootstrap.js";
|
export * from "./rebootstrap.js";
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
export function benchSync(name, n, innerLoop) {
|
export function benchSync(name, n, innerLoop) {
|
||||||
const t1 = Date.now();
|
const t1 = Date.now();
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
|
|
|
@ -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 { dirname, fromFileUrl, join } from "../../test_util/std/path/mod.ts";
|
||||||
import { expandGlobSync } from "../../test_util/std/fs/mod.ts";
|
import { expandGlobSync } from "../../test_util/std/fs/mod.ts";
|
||||||
|
|
||||||
|
|
|
@ -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.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { getSources, ROOT_PATH } from "./util.js";
|
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, [
|
const sourceFiles = await getSources(ROOT_PATH, [
|
||||||
// js and ts
|
// js and ts
|
||||||
"*.js",
|
"*.js",
|
||||||
|
@ -28,7 +28,6 @@ async function checkCopyright() {
|
||||||
":!:cli/tsc/*typescript.js",
|
":!:cli/tsc/*typescript.js",
|
||||||
":!:cli/tsc/compiler.d.ts",
|
":!:cli/tsc/compiler.d.ts",
|
||||||
":!:test_util/wpt/**",
|
":!:test_util/wpt/**",
|
||||||
":!:tools/**", // these files are starts with `#!/usr/bin/env`
|
|
||||||
":!:cli/tools/init/templates/**",
|
":!:cli/tools/init/templates/**",
|
||||||
|
|
||||||
// rust
|
// rust
|
||||||
|
@ -58,8 +57,9 @@ async function checkCopyright() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use .includes(...) because the first line might be a shebang
|
||||||
if (
|
if (
|
||||||
!fileText.startsWith(
|
!fileText.includes(
|
||||||
"// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.",
|
"// 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) {
|
if (totalCount > 0) {
|
||||||
Deno.exit(1);
|
throw new Error(`Copyright checker had ${totalCount} errors.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
if (import.meta.main) {
|
||||||
await Deno.chdir(ROOT_PATH);
|
|
||||||
|
|
||||||
await checkCopyright();
|
await checkCopyright();
|
||||||
}
|
}
|
||||||
|
|
||||||
await main();
|
|
||||||
|
|
|
@ -2,6 +2,77 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
import { join, ROOT_PATH as ROOT } from "./util.js";
|
import { join, ROOT_PATH as ROOT } from "./util.js";
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build bench with frame pointers
|
||||||
|
await bashThrough(
|
||||||
|
`RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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() {
|
||||||
|
// TODO(AaronO): maybe reimplement with fs.walk
|
||||||
|
// it's important to prune the walked tree so this is fast (<50ms)
|
||||||
|
const prunedDirs = ["third_party", ".git", "target", "docs", "test_util"];
|
||||||
|
const pruneExpr = prunedDirs.map((d) => `-path ${ROOT}/${d}`).join(" -o ");
|
||||||
|
return (await bashOut(`
|
||||||
|
find ${ROOT} -type d \
|
||||||
|
\\( ${pruneExpr} \\) \
|
||||||
|
-prune -false -o \
|
||||||
|
-path "${ROOT}/*/benches/*" -type f -name "*.rs" \
|
||||||
|
| xargs basename | cut -f1 -d.
|
||||||
|
`)).split("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function latestBenchBin(name) {
|
||||||
|
return bashOut(`ls -t "${ROOT}/target/release/deps/${name}"* | head -n 1`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function runFlamegraph(benchBin, benchFilter, outputFile) {
|
||||||
|
return bashThrough(
|
||||||
|
`sudo -E flamegraph -o ${outputFile} ${benchBin} ${benchFilter ?? ""}`,
|
||||||
|
// Set $PROFILING env so benches can improve their flamegraphs
|
||||||
|
{ env: { "PROFILING": "1" } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function bashOut(subcmd) {
|
async function bashOut(subcmd) {
|
||||||
const { success, stdout } = await new Deno.Command("bash", {
|
const { success, stdout } = await new Deno.Command("bash", {
|
||||||
args: ["-c", subcmd],
|
args: ["-c", subcmd],
|
||||||
|
@ -33,32 +104,6 @@ async function bashThrough(subcmd, opts = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function availableBenches() {
|
|
||||||
// TODO(AaronO): maybe reimplement with fs.walk
|
|
||||||
// it's important to prune the walked tree so this is fast (<50ms)
|
|
||||||
const prunedDirs = ["third_party", ".git", "target", "docs", "test_util"];
|
|
||||||
const pruneExpr = prunedDirs.map((d) => `-path ${ROOT}/${d}`).join(" -o ");
|
|
||||||
return (await bashOut(`
|
|
||||||
find ${ROOT} -type d \
|
|
||||||
\\( ${pruneExpr} \\) \
|
|
||||||
-prune -false -o \
|
|
||||||
-path "${ROOT}/*/benches/*" -type f -name "*.rs" \
|
|
||||||
| xargs basename | cut -f1 -d.
|
|
||||||
`)).split("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function latestBenchBin(name) {
|
|
||||||
return bashOut(`ls -t "${ROOT}/target/release/deps/${name}"* | head -n 1`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function runFlamegraph(benchBin, benchFilter, outputFile) {
|
|
||||||
return bashThrough(
|
|
||||||
`sudo -E flamegraph -o ${outputFile} ${benchBin} ${benchFilter ?? ""}`,
|
|
||||||
// Set $PROFILING env so benches can improve their flamegraphs
|
|
||||||
{ env: { "PROFILING": "1" } },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function binExists(bin) {
|
async function binExists(bin) {
|
||||||
try {
|
try {
|
||||||
await bashOut(`which ${bin}`);
|
await bashOut(`which ${bin}`);
|
||||||
|
@ -67,52 +112,3 @@ async function binExists(bin) {
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build bench with frame pointers
|
|
||||||
await bashThrough(
|
|
||||||
`RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Run
|
|
||||||
await main();
|
|
||||||
|
|
|
@ -2,45 +2,15 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js";
|
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js";
|
||||||
|
|
||||||
async function dprint() {
|
const subcommand = Deno.args.includes("--check") ? "check" : "fmt";
|
||||||
const configFile = join(ROOT_PATH, ".dprint.json");
|
const configFile = join(ROOT_PATH, ".dprint.json");
|
||||||
const execPath = getPrebuiltToolPath("dprint");
|
const execPath = getPrebuiltToolPath("dprint");
|
||||||
const cmd = new Deno.Command(execPath, {
|
const cmd = new Deno.Command(execPath, {
|
||||||
args: ["fmt", "--config=" + configFile],
|
args: [subcommand, "--config=" + configFile],
|
||||||
|
cwd: ROOT_PATH,
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
});
|
});
|
||||||
|
|
||||||
const { code } = await cmd.output();
|
const { code } = await cmd.output();
|
||||||
|
Deno.exit(code);
|
||||||
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();
|
|
||||||
|
|
|
@ -7,6 +7,28 @@ import {
|
||||||
join,
|
join,
|
||||||
ROOT_PATH,
|
ROOT_PATH,
|
||||||
} from "./util.js";
|
} 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() {
|
async function dlint() {
|
||||||
const configFile = join(ROOT_PATH, ".dlint.json");
|
const configFile = join(ROOT_PATH, ".dlint.json");
|
||||||
|
@ -44,6 +66,7 @@ async function dlint() {
|
||||||
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const cmd = new Deno.Command(execPath, {
|
const cmd = new Deno.Command(execPath, {
|
||||||
|
cwd: ROOT_PATH,
|
||||||
args: ["run", "--config=" + configFile, ...chunk],
|
args: ["run", "--config=" + configFile, ...chunk],
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
|
@ -77,6 +100,7 @@ async function dlintPreferPrimordials() {
|
||||||
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const cmd = new Deno.Command(execPath, {
|
const cmd = new Deno.Command(execPath, {
|
||||||
|
cwd: ROOT_PATH,
|
||||||
args: ["run", "--rule", "prefer-primordials", ...chunk],
|
args: ["run", "--rule", "prefer-primordials", ...chunk],
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
|
@ -116,6 +140,7 @@ async function clippy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const cargoCmd = new Deno.Command("cargo", {
|
const cargoCmd = new Deno.Command("cargo", {
|
||||||
|
cwd: ROOT_PATH,
|
||||||
args: [
|
args: [
|
||||||
...cmd,
|
...cmd,
|
||||||
"--",
|
"--",
|
||||||
|
@ -131,28 +156,3 @@ async function clippy() {
|
||||||
throw new Error("clippy failed");
|
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();
|
|
||||||
|
|
|
@ -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
|
// 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
|
// passed, will automatically add a status check to the commit with a link to
|
||||||
// the wpt.fyi page.
|
// the wpt.fyi page.
|
||||||
|
|
Loading…
Add table
Reference in a new issue