Repository navigation
Expand file tree
/
Copy pathcopyExes.js
More file actions
executable file
·67 lines (58 loc) · 1.61 KB
/
Copy pathcopyExes.js
File metadata and controls
executable file
·67 lines (58 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
// @ts-check
// Copy the Rust rewatch reference built by Cargo to the platform bin dir.
// The dune-built compiler binaries are copied by dune promotion instead
// (see compiler/sync/dune).
import * as child_process from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
import { parseArgs } from "node:util";
import { binDir } from "#cli/bins";
import { rewatchDir } from "#dev/paths";
const args = parseArgs({
args: process.argv.slice(2),
options: {
all: {
type: "boolean",
},
rewatch: {
type: "boolean",
},
},
});
const shouldCopyRewatch = args.values.all || args.values.rewatch;
if (shouldCopyRewatch) {
copyExe(
path.join(rewatchDir, "target", "release"),
"rescript",
"rescript-rust",
);
}
/**
* @param {string} dir
* @param {string} exe
* @param {string | undefined} renamed
*/
function copyExe(dir, exe, renamed) {
const ext = process.platform === "win32" ? ".exe" : "";
const src = path.join(dir, exe + ext);
const dest = path.join(binDir, `${renamed ?? exe}.exe`);
// For some reason, the copy operation fails in Windows CI if the file already exists.
if (process.platform === "win32" && fs.existsSync(dest)) {
fs.rmSync(dest);
}
let mode = 0o755;
if (fs.existsSync(dest)) {
mode = fs.statSync(dest).mode & 0o777;
fs.chmodSync(dest, mode | 0o200); // u+w
}
try {
fs.copyFileSync(src, dest);
if (process.platform !== "win32") {
fs.chmodSync(dest, mode | 0o200); // u+w
child_process.execSync(`strip ${dest}`);
}
} finally {
fs.chmodSync(dest, mode);
}
}