tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
deno: update update script to changed deno
06kellyjac
4 years ago
c034a141
9611f031
+113
-118
5 changed files
expand all
collapse all
unified
split
pkgs
development
web
deno
update
common.ts
deps.ts
librusty_v8.ts
src.ts
update.ts
+12
-22
pkgs/development/web/deno/update/common.ts
···
3
3
}
4
4
5
5
const decode = (buffer: Uint8Array) => new TextDecoder("utf-8").decode(buffer);
6
6
-
const run = async (command: string, args: string[]) => {
7
7
-
const cmd = Deno.run(
8
8
-
{ cmd: [command, ...args], stdout: "piped", stderr: "piped" },
9
9
-
);
6
6
+
const decodeTrim = (b: Uint8Array) => decode(b).trimEnd();
7
7
+
export const run = async (command: string, args: string[]) => {
8
8
+
const cmd = Deno.run({
9
9
+
cmd: [command, ...args],
10
10
+
stdout: "piped",
11
11
+
stderr: "piped",
12
12
+
});
10
13
if (!(await cmd.status()).success) {
11
11
-
const error = await cmd.stderrOutput().then((b) => decode(b).trimEnd());
14
14
+
const error = await cmd.stderrOutput().then(decodeTrim);
12
15
// Known error we can ignore
13
16
if (error.includes("'allow-unsafe-native-code-during-evaluation'")) {
14
17
// Extract the target sha256 out of the error
···
23
26
}
24
27
throw new Error(error);
25
28
}
26
26
-
return cmd.output().then((b) => decode(b).trimEnd());
29
29
+
return cmd.output().then(decodeTrim);
27
30
};
28
31
29
32
// Exports
30
33
export const versionRegExp = /\d+\.\d+\.\d+/;
31
31
-
export const sha256RegExp = /[a-z0-9]{52}/;
32
32
-
33
33
-
export async function commit(
34
34
-
name: string,
35
35
-
oldVer: string,
36
36
-
newVer: string,
37
37
-
files: string[],
38
38
-
) {
39
39
-
await run("git", ["add", ...files]);
40
40
-
await run("git", ["commit", "-m", `${name}: ${oldVer} -> ${newVer}`]);
41
41
-
}
34
34
+
export const sha256RegExp = /[a-z0-9]{52}|sha256-.{44}/;
42
35
43
36
export const getExistingVersion = async (filePath: string) =>
44
44
-
read(filePath).then((s) =>
45
45
-
s.match(genValueRegExp("version", versionRegExp))?.shift() || ""
37
37
+
read(filePath).then(
38
38
+
(s) => s.match(genValueRegExp("version", versionRegExp))?.shift() || "",
46
39
);
47
40
48
41
export const getLatestVersion = (owner: string, repo: string) =>
···
57
50
58
51
export const logger = (name: string) =>
59
52
(...a: any) => console.log(`[${name}]`, ...a);
60
60
-
61
61
-
export const nixPrefetch = (args: string[]) => run("nix-prefetch", args);
62
62
-
export const nixPrefetchURL = (args: string[]) => run("nix-prefetch-url", args);
63
53
64
54
export const read = Deno.readTextFile;
65
55
export const write = Deno.writeTextFile;
-79
pkgs/development/web/deno/update/deps.ts
···
1
1
-
import {
2
2
-
getExistingVersion,
3
3
-
genValueRegExp,
4
4
-
logger,
5
5
-
nixPrefetchURL,
6
6
-
versionRegExp,
7
7
-
write,
8
8
-
} from "./common.ts";
9
9
-
10
10
-
const log = logger("deps");
11
11
-
12
12
-
export interface Architecture {
13
13
-
nix: string;
14
14
-
rust: string;
15
15
-
}
16
16
-
interface PrefetchResult {
17
17
-
arch: Architecture;
18
18
-
sha256: string;
19
19
-
}
20
20
-
21
21
-
const getRustyV8Version = async (
22
22
-
owner: string,
23
23
-
repo: string,
24
24
-
version: string,
25
25
-
) =>
26
26
-
fetch(
27
27
-
`https://github.com/${owner}/${repo}/raw/${version}/core/Cargo.toml`,
28
28
-
)
29
29
-
.then((res) => res.text())
30
30
-
.then((txt) =>
31
31
-
txt.match(genValueRegExp("rusty_v8", versionRegExp))?.shift()
32
32
-
);
33
33
-
34
34
-
const archShaTasks = (version: string, arches: Architecture[]) =>
35
35
-
arches.map(async (arch: Architecture): Promise<PrefetchResult> => {
36
36
-
log("Fetching:", arch.nix);
37
37
-
const sha256 = await nixPrefetchURL(
38
38
-
[`https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch.rust}.a`],
39
39
-
);
40
40
-
log("Done: ", arch.nix);
41
41
-
return { arch, sha256 };
42
42
-
});
43
43
-
44
44
-
const templateDeps = (version: string, deps: PrefetchResult[]) =>
45
45
-
`# auto-generated file -- DO NOT EDIT!
46
46
-
{}:
47
47
-
rec {
48
48
-
librusty_v8 = {
49
49
-
version = "${version}";
50
50
-
sha256s = {
51
51
-
${deps.map((d) => ` ${d.arch.nix} = "${d.sha256}";`).join("\n")}
52
52
-
};
53
53
-
};
54
54
-
}
55
55
-
`;
56
56
-
57
57
-
export async function updateDeps(
58
58
-
filePath: string,
59
59
-
owner: string,
60
60
-
repo: string,
61
61
-
denoVersion: string,
62
62
-
arches: Architecture[],
63
63
-
) {
64
64
-
log("Starting deps update");
65
65
-
// 0.0.0
66
66
-
const version = await getRustyV8Version(owner, repo, denoVersion);
67
67
-
if (typeof version !== "string") {
68
68
-
throw "no librusty_v8 version";
69
69
-
}
70
70
-
log("librusty_v8 version:", version);
71
71
-
const existingVersion = await getExistingVersion(filePath);
72
72
-
if (version === existingVersion) {
73
73
-
log("Version already matches latest, skipping...");
74
74
-
return;
75
75
-
}
76
76
-
const archShaResults = await Promise.all(archShaTasks(version, arches));
77
77
-
await write(filePath, templateDeps(version, archShaResults));
78
78
-
log("Finished deps update");
79
79
-
}
+92
pkgs/development/web/deno/update/librusty_v8.ts
···
1
1
+
import {
2
2
+
genValueRegExp,
3
3
+
getExistingVersion,
4
4
+
logger,
5
5
+
run,
6
6
+
versionRegExp,
7
7
+
write,
8
8
+
} from "./common.ts";
9
9
+
10
10
+
const log = logger("librusty_v8");
11
11
+
12
12
+
export interface Architecture {
13
13
+
nix: string;
14
14
+
rust: string;
15
15
+
}
16
16
+
interface PrefetchResult {
17
17
+
arch: Architecture;
18
18
+
sha256: string;
19
19
+
}
20
20
+
21
21
+
const getLibrustyV8Version = async (
22
22
+
owner: string,
23
23
+
repo: string,
24
24
+
version: string,
25
25
+
) =>
26
26
+
fetch(`https://github.com/${owner}/${repo}/raw/${version}/core/Cargo.toml`)
27
27
+
.then((res) => res.text())
28
28
+
.then((txt) =>
29
29
+
txt.match(genValueRegExp("rusty_v8", versionRegExp))?.shift()
30
30
+
);
31
31
+
32
32
+
const fetchArchShaTasks = (version: string, arches: Architecture[]) =>
33
33
+
arches.map(
34
34
+
async (arch: Architecture): Promise<PrefetchResult> => {
35
35
+
log("Fetching:", arch.nix);
36
36
+
const sha256 = await run("nix-prefetch", [
37
37
+
`
38
38
+
{ fetchurl }:
39
39
+
fetchurl {
40
40
+
url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch.rust}.a";
41
41
+
}
42
42
+
`,
43
43
+
]);
44
44
+
log("Done: ", arch.nix);
45
45
+
return { arch, sha256 };
46
46
+
},
47
47
+
);
48
48
+
49
49
+
const templateDeps = (version: string, deps: PrefetchResult[]) =>
50
50
+
`# auto-generated file -- DO NOT EDIT!
51
51
+
{ rust, stdenv, fetchurl }:
52
52
+
53
53
+
let
54
54
+
arch = rust.toRustTarget stdenv.hostPlatform;
55
55
+
fetch_librusty_v8 = args: fetchurl {
56
56
+
name = "librusty_v8-\${args.version}";
57
57
+
url = "https://github.com/denoland/rusty_v8/releases/download/v\${args.version}/librusty_v8_release_\${arch}.a";
58
58
+
sha256 = args.shas.\${stdenv.hostPlatform.system};
59
59
+
meta = { inherit (args) version; };
60
60
+
};
61
61
+
in
62
62
+
fetch_librusty_v8 {
63
63
+
version = "${version}";
64
64
+
shas = {
65
65
+
${deps.map(({ arch, sha256 }) => ` ${arch.nix} = "${sha256}";`).join("\n")}
66
66
+
};
67
67
+
}
68
68
+
`;
69
69
+
70
70
+
export async function updateLibrustyV8(
71
71
+
filePath: string,
72
72
+
owner: string,
73
73
+
repo: string,
74
74
+
denoVersion: string,
75
75
+
arches: Architecture[],
76
76
+
) {
77
77
+
log("Starting librusty_v8 update");
78
78
+
// 0.0.0
79
79
+
const version = await getLibrustyV8Version(owner, repo, denoVersion);
80
80
+
if (typeof version !== "string") {
81
81
+
throw "no librusty_v8 version";
82
82
+
}
83
83
+
log("librusty_v8 version:", version);
84
84
+
const existingVersion = await getExistingVersion(filePath);
85
85
+
if (version === existingVersion) {
86
86
+
log("Version already matches latest, skipping...");
87
87
+
return;
88
88
+
}
89
89
+
const archShaResults = await Promise.all(fetchArchShaTasks(version, arches));
90
90
+
await write(filePath, templateDeps(version, archShaResults));
91
91
+
log("Finished deps update");
92
92
+
}
+5
-5
pkgs/development/web/deno/update/src.ts
···
1
1
import {
2
2
genValueRegExp,
3
3
logger,
4
4
-
nixPrefetch,
5
4
read,
5
5
+
run,
6
6
sha256RegExp,
7
7
versionRegExp,
8
8
write,
···
16
16
const log = logger("src");
17
17
18
18
const prefetchSha256 = (nixpkgs: string, version: string) =>
19
19
-
nixPrefetch(["-f", nixpkgs, "deno.src", "--rev", version]);
19
19
+
run("nix-prefetch", ["-f", nixpkgs, "deno.src", "--rev", version]);
20
20
const prefetchCargoSha256 = (nixpkgs: string) =>
21
21
-
nixPrefetch(
22
22
-
[`{ sha256 }: (import ${nixpkgs} {}).deno.cargoDeps.overrideAttrs (_: { outputHash = sha256; })`],
21
21
+
run(
22
22
+
"nix-prefetch",
23
23
+
[`{ sha256 }: (import ${nixpkgs} {}).deno.cargoDeps.overrideAttrs (_: { inherit sha256; })`],
23
24
);
24
25
25
26
const replace = (str: string, replacers: Replacer[]) =>
···
53
54
[
54
55
genVerReplacer("version", trimVersion),
55
56
genShaReplacer("sha256", sha256),
56
56
-
genShaReplacer("cargoSha256", ""), // Empty ready for prefetchCargoSha256
57
57
],
58
58
);
59
59
log("Fetching cargoSha256 for:", sha256);
+4
-12
pkgs/development/web/deno/update/update.ts
···
2
2
/*
3
3
#!nix-shell -i "deno run --allow-net --allow-run --allow-read --allow-write" -p deno git nix-prefetch
4
4
*/
5
5
-
import {
6
6
-
commit,
7
7
-
getExistingVersion,
8
8
-
getLatestVersion,
9
9
-
logger,
10
10
-
} from "./common.ts";
11
11
-
import { Architecture, updateDeps } from "./deps.ts";
5
5
+
import { getExistingVersion, getLatestVersion, logger } from "./common.ts";
6
6
+
import { Architecture, updateLibrustyV8 } from "./librusty_v8.ts";
12
7
import { updateSrc } from "./src.ts";
13
8
14
9
const log = logger("update");
···
19
14
const repo = "deno";
20
15
const denoDir = `${nixpkgs}/pkgs/development/web/${repo}`;
21
16
const src = `${denoDir}/default.nix`;
22
22
-
const deps = `${denoDir}/deps.nix`;
17
17
+
const librusty_v8 = `${denoDir}/librusty_v8.nix`;
23
18
const architectures: Architecture[] = [
24
19
{ nix: "x86_64-linux", rust: "x86_64-unknown-linux-gnu" },
25
20
{ nix: "aarch64-linux", rust: "aarch64-unknown-linux-gnu" },
···
42
37
43
38
const tasks = [
44
39
updateSrc(src, nixpkgs, version),
45
45
-
updateDeps(deps, owner, repo, version, architectures),
40
40
+
updateLibrustyV8(librusty_v8, owner, repo, version, architectures),
46
41
];
47
42
await Promise.all(tasks);
48
43
log("Updating deno complete");
49
49
-
log("Commiting");
50
50
-
await commit(repo, existingVersion, trimVersion, [src, deps]);
51
51
-
log("Done");