diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-08-19 09:56:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-19 09:56:12 +0530 |
commit | c2259f78eb8180731bb562740695ab6e58c790e7 (patch) | |
tree | b080b42ef86b3aa3802e7b3b7309d31cdf5f7ef8 /tools | |
parent | 0e4469c7a1d9afcffc53d714e6db4491e552d5c9 (diff) |
chore: remove third_party submodule (#20201)
removes third_party submodule, tools are installed on-demand.
- removed `load_test` and websocket benchmark (covered by benchy)
- removed node/bun http benchmarks (covered by benchy)
- `dlint` & `dprint` downloaded on-demand.
- `wrk` & `hyperfine` downloaded before CI benchmark run.
Install locally using: `./tools/install_prebuilt.js wrk hyperfine`
#### updating dlint/dprint
update version in `tools/util.js` and place binary in
`denoland/deno_third_party`.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/format.js | 6 | ||||
-rwxr-xr-x | tools/install_prebuilt.js | 8 | ||||
-rwxr-xr-x | tools/lint.js | 15 | ||||
-rw-r--r-- | tools/util.js | 93 |
4 files changed, 99 insertions, 23 deletions
diff --git a/tools/format.js b/tools/format.js index bd34b1cfd..b2296ede6 100755 --- a/tools/format.js +++ b/tools/format.js @@ -1,10 +1,10 @@ -#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run +#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run --allow-net // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js"; +import { getPrebuilt, join, ROOT_PATH } from "./util.js"; const subcommand = Deno.args.includes("--check") ? "check" : "fmt"; const configFile = join(ROOT_PATH, ".dprint.json"); -const execPath = getPrebuiltToolPath("dprint"); +const execPath = await getPrebuilt("dprint"); const cmd = new Deno.Command(execPath, { args: [subcommand, "--config=" + configFile], cwd: ROOT_PATH, diff --git a/tools/install_prebuilt.js b/tools/install_prebuilt.js new file mode 100755 index 000000000..831bda487 --- /dev/null +++ b/tools/install_prebuilt.js @@ -0,0 +1,8 @@ +#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-net +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { getPrebuilt } from "./util.js"; + +const args = Deno.args.slice(); +for (const arg of args) { + await getPrebuilt(arg); +} diff --git a/tools/lint.js b/tools/lint.js index ce043f300..78fc7a84c 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -1,12 +1,6 @@ -#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run +#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run --allow-net // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - buildMode, - getPrebuiltToolPath, - getSources, - join, - ROOT_PATH, -} from "./util.js"; +import { buildMode, getPrebuilt, getSources, join, ROOT_PATH } from "./util.js"; import { checkCopyright } from "./copyright_checker.js"; let didLint = false; @@ -33,7 +27,7 @@ if (!didLint) { async function dlint() { const configFile = join(ROOT_PATH, ".dlint.json"); - const execPath = getPrebuiltToolPath("dlint"); + const execPath = await getPrebuilt("dlint"); const sourceFiles = await getSources(ROOT_PATH, [ "*.js", @@ -41,7 +35,6 @@ async function dlint() { ":!:.github/mtime_cache/action.js", ":!:cli/tests/testdata/swc_syntax_error.ts", ":!:cli/tests/testdata/error_008_checkjs.js", - ":!:cli/bench/http/node*.js", ":!:cli/bench/testdata/npm/*", ":!:cli/bench/testdata/express-router.js", ":!:cli/bench/testdata/react-dom.js", @@ -92,7 +85,7 @@ async function dlint() { // which is different from other lint rules. This is why this dedicated function // is needed. async function dlintPreferPrimordials() { - const execPath = getPrebuiltToolPath("dlint"); + const execPath = await getPrebuilt("dlint"); const sourceFiles = await getSources(ROOT_PATH, [ "runtime/**/*.js", "ext/**/*.js", diff --git a/tools/util.js b/tools/util.js index a8121b308..92ab18a7f 100644 --- a/tools/util.js +++ b/tools/util.js @@ -6,11 +6,18 @@ import { resolve, toFileUrl, } from "../test_util/std/path/mod.ts"; +import { wait } from "https://deno.land/x/wait@0.1.13/mod.ts"; export { dirname, fromFileUrl, join, resolve, toFileUrl }; export { existsSync, walk } from "../test_util/std/fs/mod.ts"; export { TextLineStream } from "../test_util/std/streams/text_line_stream.ts"; export { delay } from "../test_util/std/async/delay.ts"; +// [toolName] --version output +const versions = { + "dprint": "dprint 0.40.0", + "dlint": "dlint 0.47.0", +}; + export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url))); async function getFilesFromGit(baseDir, args) { @@ -100,14 +107,82 @@ export function buildPath() { return join(ROOT_PATH, "target", buildMode()); } +const platformDirName = { + "windows": "win", + "darwin": "mac", + "linux": "linux64", +}[Deno.build.os]; + +const executableSuffix = Deno.build.os === "windows" ? ".exe" : ""; + +export async function getPrebuilt(toolName) { + const toolPath = getPrebuiltToolPath(toolName); + try { + await Deno.stat(toolPath); + const versionOk = await verifyVersion(toolName); + if (!versionOk) { + throw new Error("Version mismatch"); + } + } catch { + await downloadPrebuilt(toolName); + } + + return toolPath; +} + +const PREBUILT_PATH = join(ROOT_PATH, "third_party", "prebuilt"); +const PREBUILT_TOOL_DIR = join(PREBUILT_PATH, platformDirName); + export function getPrebuiltToolPath(toolName) { - const PREBUILT_PATH = join(ROOT_PATH, "third_party", "prebuilt"); - - const platformDirName = { - "windows": "win", - "darwin": "mac", - "linux": "linux64", - }[Deno.build.os]; - const executableSuffix = Deno.build.os === "windows" ? ".exe" : ""; - return join(PREBUILT_PATH, platformDirName, toolName + executableSuffix); + return join(PREBUILT_TOOL_DIR, toolName + executableSuffix); +} + +const downloadUrl = + `https://raw.githubusercontent.com/denoland/deno_third_party/master/prebuilt/${platformDirName}`; + +export async function downloadPrebuilt(toolName) { + const spinner = wait("Downloading prebuilt tool: " + toolName).start(); + const toolPath = getPrebuiltToolPath(toolName); + + try { + await Deno.mkdir(PREBUILT_TOOL_DIR, { recursive: true }); + + const url = `${downloadUrl}/${toolName}${executableSuffix}`; + + const resp = await fetch(url); + const file = await Deno.open(toolPath, { + create: true, + write: true, + mode: 0o755, + }); + + await resp.body.pipeTo(file.writable); + } catch (e) { + spinner.fail(); + throw e; + } + + spinner.succeed(); +} + +export async function verifyVersion(toolName) { + const requiredVersion = versions[toolName]; + if (!requiredVersion) { + return true; + } + + try { + const toolPath = getPrebuiltToolPath(toolName); + const cmd = new Deno.Command(toolPath, { + args: ["--version"], + stdout: "piped", + stderr: "inherit", + }); + const output = await cmd.output(); + const version = new TextDecoder().decode(output.stdout).trim(); + return version == requiredVersion; + } catch (e) { + console.error(e); + return false; + } } |