Skip to content

Commit ae01437

Browse files
authored
Make rewatch the default build system / cli (#7593)
* rescript_exe -> rescript_legacy_exe * rescript.exe -> rescript-legacy.exe * rewatch.exe -> rescript.exe * cli/rescript.js -> cli/rescript-legacy.js * cli/rewatch.js -> cli/rescript.js * rewatch_exe -> rescript_exe * rewatch.exe -> rescript.exe * Remove rewatch/postinstall.js * Rename runtime build scripts * Fix gentype tests * Build analysis tests with legacy build system * Build playground with legacy build system * Build more stuff with legacy build system * CHANGELOG * Testrepo: use pkg.pr.new * Fix installation test * Undo comment change
1 parent 8e060f2 commit ae01437

File tree

53 files changed

+336
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+336
-381
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ jobs:
332332

333333
- name: Build runtime/stdlib with rewatch
334334
if: ${{ runner.os != 'Windows' }}
335-
run: ./scripts/buildRuntimeRewatch.sh
335+
run: ./scripts/buildRuntime.sh
336336
shell: bash
337337

338338
- name: Build runtime/stdlib with bsb (Windows)
339339
if: ${{ runner.os == 'Windows' }}
340-
run: ./scripts/buildRuntime.sh
340+
run: ./scripts/buildRuntimeLegacy.sh
341341
shell: bash
342342

343343
- name: Check for changes in lib folder
@@ -510,7 +510,7 @@ jobs:
510510
- name: Build website
511511
if: steps.diffcheck.outputs.clean == 'false'
512512
run: |
513-
npm ci
513+
npm ci
514514
npm run build
515515
516516
- name: Commit and push
@@ -569,7 +569,7 @@ jobs:
569569
working-directory: ${{ steps.tmp-dir.outputs.path }}
570570

571571
- name: Test installation
572-
run: npx rescript -h && npx rescript build && cat src/Test.res.js
572+
run: npx rescript -h && npx rescript legacy build && cat src/Test.res.js
573573
shell: bash
574574
working-directory: ${{ steps.tmp-dir.outputs.path }}
575575

@@ -581,7 +581,7 @@ jobs:
581581
working-directory: rewatch/testrepo
582582

583583
- name: Run rewatch integration tests
584-
run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rewatch
584+
run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rescript
585585
shell: bash
586586

587587
publish:

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
#### :boom: Breaking Change
1616

17-
- The legacy rescript cli can be called through rewatch via `rewatch legacy`. Arguments to rewatch need to be passed after the subcommand. Argument `--compiler-args` is now a subcommand `compiler-args`. https://github.com/rescript-lang/rescript/pull/7551
17+
- New `rewatch` based build system. https://github.com/rescript-lang/rescript/pull/7551 https://github.com/rescript-lang/rescript/pull/7593
18+
- The new `rewatch` based build system is now the default and is exposed through the `rescript` command. The `rewatch` command has been removed.
19+
- The previous Ninja-based build system is now available via the `rescript legacy` subcommand.
20+
- Argument `--compiler-args` is now a subcommand `compiler-args`.
1821
- Remove `String.getSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571
1922
- Remove `String.getSymbolUnsafe` from standard library. https://github.com/rescript-lang/rescript/pull/7571
2023
- Remove `String.setSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dce:
1717

1818
rewatch:
1919
cargo build --manifest-path rewatch/Cargo.toml --release
20-
cp rewatch/target/release/rewatch rewatch
2120
./scripts/copyExes.js --rewatch
2221

2322
ninja/ninja:
@@ -53,10 +52,10 @@ reanalyze:
5352
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb
5453

5554
lib-bsb:
56-
./scripts/buildRuntime.sh
55+
./scripts/buildRuntimeLegacy.sh
5756

5857
lib:
59-
./scripts/buildRuntimeRewatch.sh
58+
./scripts/buildRuntime.sh
6059

6160
artifacts: lib
6261
./scripts/npmPack.js --updateArtifactList

analysis/examples/example-project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"scripts": {
77
"build": "rescript",
88
"start": "rescript build -w",
9-
"clean": "rescript clean -with-deps"
9+
"clean": "rescript clean"
1010
}
1111
}

analysis/examples/larger-project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"start": "rescript build -w",
77
"build": "rescript build",
8-
"clean": "rescript clean -with-deps"
8+
"clean": "rescript clean"
99
},
1010
"devDependencies": {
1111
"react": "^16.13.1",

cli/common/bins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const {
2222
ninja_exe,
2323
rescript_editor_analysis_exe,
2424
rescript_tools_exe,
25+
rescript_legacy_exe,
2526
rescript_exe,
26-
rewatch_exe,
2727
},
2828
} = mod;

cli/common/bsb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as os from "node:os";
77
import * as path from "node:path";
88
import { WebSocket } from "#lib/minisocket";
99

10-
import { rescript_exe } from "./bins.js";
10+
import { rescript_legacy_exe } from "./bins.js";
1111

1212
const cwd = process.cwd();
1313
const lockFileName = path.join(cwd, ".bsb.lock");
@@ -50,7 +50,7 @@ function acquireBuild(args, options) {
5050
return null;
5151
}
5252
try {
53-
ownerProcess = child_process.spawn(rescript_exe, args, {
53+
ownerProcess = child_process.spawn(rescript_legacy_exe, args, {
5454
stdio: "inherit",
5555
...options,
5656
});

cli/rescript-legacy.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env node
2+
3+
// @ts-check
4+
5+
// This script is supposed to be running in project root directory
6+
// It matters since we need read .sourcedirs(location)
7+
// and its content are file/directories with regard to project root
8+
9+
import * as fs from "node:fs";
10+
import * as tty from "node:tty";
11+
12+
import { bsc_exe, rescript_legacy_exe } from "./common/bins.js";
13+
import * as bsb from "./common/bsb.js";
14+
15+
const cwd = process.cwd();
16+
process.env.BSB_PROJECT_ROOT = cwd;
17+
18+
if (process.env.FORCE_COLOR === undefined) {
19+
if (tty.isatty(1)) {
20+
process.env.FORCE_COLOR = "1";
21+
process.env.NINJA_ANSI_FORCED = "1";
22+
}
23+
} else {
24+
if (
25+
process.env.FORCE_COLOR === "1" &&
26+
process.env.NINJA_ANSI_FORCED === undefined
27+
) {
28+
process.env.NINJA_ANSI_FORCED = "1";
29+
}
30+
if (process.argv.includes("-verbose")) {
31+
console.log(`FORCE_COLOR: "${process.env.FORCE_COLOR}"`);
32+
}
33+
}
34+
35+
const helpMessage = `Usage: rescript <options> <subcommand>
36+
37+
\`rescript\` is equivalent to \`rescript build\`
38+
39+
Options:
40+
-v, -version display version number
41+
-h, -help display help
42+
43+
Subcommands:
44+
build
45+
clean
46+
format
47+
dump
48+
help
49+
50+
Run \`rescript <subcommand> -h\` for subcommand help. Examples:
51+
rescript build -h
52+
rescript format -h`;
53+
54+
function onUncaughtException(err) {
55+
console.error("Uncaught Exception", err);
56+
bsb.releaseBuild();
57+
process.exit(1);
58+
}
59+
60+
function exitProcess() {
61+
bsb.releaseBuild();
62+
process.exit(0);
63+
}
64+
65+
process.on("uncaughtException", onUncaughtException);
66+
67+
// OS signal handlers
68+
// Ctrl+C
69+
process.on("SIGINT", exitProcess);
70+
// kill pid
71+
try {
72+
process.on("SIGUSR1", exitProcess);
73+
process.on("SIGUSR2", exitProcess);
74+
process.on("SIGTERM", exitProcess);
75+
process.on("SIGHUP", exitProcess);
76+
} catch (_e) {
77+
// Deno might throw an error here, see https://github.com/denoland/deno/issues/9995
78+
// TypeError: Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).
79+
}
80+
81+
const args = process.argv.slice(2);
82+
const argPatterns = {
83+
help: ["help", "-h", "-help", "--help"],
84+
version: ["version", "-v", "-version", "--version"],
85+
};
86+
87+
const helpArgIndex = args.findIndex(arg => argPatterns.help.includes(arg));
88+
const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-"));
89+
90+
if (
91+
helpArgIndex !== -1 &&
92+
(firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)
93+
) {
94+
console.log(helpMessage);
95+
} else if (argPatterns.version.includes(args[0])) {
96+
const packageSpec = JSON.parse(
97+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
98+
);
99+
100+
console.log(packageSpec.version);
101+
} else if (firstPositionalArgIndex !== -1) {
102+
const subcmd = args[firstPositionalArgIndex];
103+
const subcmdArgs = args.slice(firstPositionalArgIndex + 1);
104+
105+
switch (subcmd) {
106+
case "info": {
107+
bsb.info(subcmdArgs);
108+
break;
109+
}
110+
case "clean": {
111+
bsb.clean(subcmdArgs);
112+
break;
113+
}
114+
case "build": {
115+
bsb.build(subcmdArgs);
116+
break;
117+
}
118+
case "format": {
119+
const mod = await import("./rescript-legacy/format.js");
120+
await mod.main(subcmdArgs, rescript_legacy_exe, bsc_exe);
121+
break;
122+
}
123+
case "dump": {
124+
const mod = await import("./rescript-legacy/dump.js");
125+
mod.main(subcmdArgs, rescript_legacy_exe, bsc_exe);
126+
break;
127+
}
128+
default: {
129+
console.error(`Error: Unknown command "${subcmd}".\n${helpMessage}`);
130+
process.exit(2);
131+
}
132+
}
133+
} else {
134+
bsb.build(args);
135+
}

cli/rescript/dump.js renamed to cli/rescript-legacy/dump.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const specs = [];
1616

1717
/**
1818
* @param {string[]} argv
19-
* @param {string} rescript_exe
19+
* @param {string} rescript_legacy_exe
2020
* @param {string} bsc_exe
2121
*/
22-
export function main(argv, rescript_exe, bsc_exe) {
22+
export function main(argv, rescript_legacy_exe, bsc_exe) {
2323
let target;
2424
arg.parse_exn(dump_usage, argv, specs, xs => {
2525
if (xs.length !== 1) {
@@ -34,9 +34,13 @@ export function main(argv, rescript_exe, bsc_exe) {
3434
process.exit(2);
3535
}
3636

37-
let output = child_process.spawnSync(rescript_exe, ["build", "--", target], {
38-
encoding: "utf-8",
39-
});
37+
let output = child_process.spawnSync(
38+
rescript_legacy_exe,
39+
["build", "--", target],
40+
{
41+
encoding: "utf-8",
42+
},
43+
);
4044
if (output.status !== 0) {
4145
console.log(output.stdout);
4246
console.error(output.stderr);

cli/rescript/format.js renamed to cli/rescript-legacy/format.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) {
143143

144144
/**
145145
* @param {string[]} argv
146-
* @param {string} rescript_exe
146+
* @param {string} rescript_legacy_exe
147147
* @param {string} bsc_exe
148148
*/
149-
export async function main(argv, rescript_exe, bsc_exe) {
149+
export async function main(argv, rescript_legacy_exe, bsc_exe) {
150150
const isSupportedFile = hasExtension(formattedFileExtensions);
151151
const isSupportedStd = hasExtension(formattedStdExtensions);
152152

@@ -179,7 +179,7 @@ export async function main(argv, rescript_exe, bsc_exe) {
179179
// -all
180180
// TODO: check the rest arguments
181181
const output = child_process.spawnSync(
182-
rescript_exe,
182+
rescript_legacy_exe,
183183
["info", "-list-files"],
184184
{
185185
encoding: "utf-8",

0 commit comments

Comments
 (0)