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/util.js | |
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/util.js')
-rw-r--r-- | tools/util.js | 93 |
1 files changed, 84 insertions, 9 deletions
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; + } } |