1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

chore: small cleanup of scripts in ./tools and run copyright checker in lint.js (#17393)

This commit is contained in:
David Sherret 2023-01-13 13:42:15 -05:00 committed by GitHub
parent 377f593273
commit 3d423e114e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 153 deletions

View file

@ -1,2 +1,4 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
export * from "./rebench.js";
export * from "./rebootstrap.js";

View file

@ -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++) {

View file

@ -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";

View file

@ -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();

View file

@ -2,6 +2,77 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
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) {
const { success, stdout } = await new Deno.Command("bash", {
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) {
try {
await bashOut(`which ${bin}`);
@ -67,52 +112,3 @@ async function binExists(bin) {
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();

View file

@ -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 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();
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 { code } = await cmd.output();
Deno.exit(code);

View file

@ -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();

View file

@ -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.