Skip to content

Commit b74a88d

Browse files
Use primary platform for genType
1 parent cf1f694 commit b74a88d

2 files changed

Lines changed: 43 additions & 25 deletions

File tree

‎rewatch/src/build/compile.rs‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,12 +825,19 @@ pub fn compiler_args(
825825
} else {
826826
Vec::new()
827827
};
828-
let gentype_arg = config.get_gentype_args(
829-
current_package_dirs,
830-
Some(bsb_project_root),
831-
&dep_paths,
832-
platform.map(|_| ""),
833-
);
828+
// Every platform implementation shares one interface and therefore one
829+
// GenType wrapper. Let the primary implementation generate it so separate
830+
// compiler processes do not repeatedly read and write the same output.
831+
let gentype_arg = if platform.is_some_and(|platform| !platform.primary) {
832+
vec![]
833+
} else {
834+
config.get_gentype_args(
835+
current_package_dirs,
836+
Some(bsb_project_root),
837+
&dep_paths,
838+
platform.map(|_| ""),
839+
)
840+
};
834841
let experimental_args = root_config.get_experimental_features_args();
835842
let warning_args = config.get_warning_args(is_local_dep, warn_error_override);
836843

@@ -1069,6 +1076,7 @@ fn compile_file(
10691076
let platform_dir = build_path_abs.join("__platform").join(&platform.name);
10701077
helpers::create_path(&platform_dir);
10711078
if package.config.gentype_config.is_some()
1079+
&& platform.primary
10721080
&& let Some(interface) = module.get_interface().as_ref()
10731081
{
10741082
let interface_dir = interface.path.parent().unwrap();

‎rewatch/tests/platforms/acceptance.test.mjs‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,35 @@ function project(t) {
4949
return root;
5050
}
5151

52-
function run(root, command = "build", succeeds = true) {
53-
const result = spawnSync(executable, [command], {
52+
function run(root, command = "build", succeeds = true, verbose = false) {
53+
const result = spawnSync(executable, verbose ? ["-vv", command] : [command], {
5454
cwd: root,
5555
env,
5656
encoding: "utf8",
5757
timeout: 30_000,
5858
});
59-
if (result.error) throw result.error;
60-
const output = result.stdout + result.stderr;
59+
const output = (result.stdout ?? "") + (result.stderr ?? "");
60+
if (result.error) {
61+
throw new Error(`${result.error.message}\n${output}`, {
62+
cause: result.error,
63+
});
64+
}
6165
if (succeeds) assert.equal(result.status, 0, output);
6266
else
6367
assert.notEqual(result.status, 0, "Expected Rewatch to reject the project");
6468
return output;
6569
}
6670

71+
function compilerArgs(root, file) {
72+
const result = spawnSync(executable, ["compiler-args", join("src", file)], {
73+
cwd: root,
74+
env,
75+
encoding: "utf8",
76+
});
77+
assert.equal(result.status, 0, result.stdout + result.stderr);
78+
return JSON.parse(result.stdout).compiler_args.map(normalizePaths);
79+
}
80+
6781
function hasExited(child) {
6882
return child.exitCode !== null || child.signalCode !== null;
6983
}
@@ -376,7 +390,10 @@ test("GenType wrappers import the logical platform module without an extension",
376390
"@genType\nlet platform: string",
377391
);
378392

379-
run(root);
393+
assert(compilerArgs(root, "Button.android.res").includes("-bs-gentype"));
394+
assert(!compilerArgs(root, "Button.ios.res").includes("-bs-gentype"));
395+
396+
run(root, "build", true, true);
380397

381398
const wrapper = join(root, "src/Button.gen.tsx");
382399
assert(existsSync(wrapper), `Missing ${wrapper}`);
@@ -595,22 +612,15 @@ test("a failed build records newly emitted platform outputs for later removal",
595612

596613
test("compiler-args reports the logical platform compilation", t => {
597614
const root = project(t);
598-
const result = spawnSync(
599-
executable,
600-
["compiler-args", join("src", "Button.ios.res")],
601-
{ cwd: root, env, encoding: "utf8" },
602-
);
603-
assert.equal(result.status, 0, result.stdout + result.stderr);
604-
const { compiler_args: rawCompilerArgs } = JSON.parse(result.stdout);
605-
const compilerArgs = rawCompilerArgs.map(normalizePaths);
606-
assert(compilerArgs.includes("-bs-platform-interface"));
615+
const args = compilerArgs(root, "Button.ios.res");
616+
assert(args.includes("-bs-platform-interface"));
607617
assert(
608-
compilerArgs.includes("__platform/ios/Button.cmj"),
609-
compilerArgs.join(" "),
618+
args.includes("__platform/ios/Button.cmj"),
619+
args.join(" "),
610620
);
611621
assert(
612-
compilerArgs.some(argument => argument.includes("commonjs:lib/js/src:.ios.js")),
613-
compilerArgs.join(" "),
622+
args.some(argument => argument.includes("commonjs:lib/js/src:.ios.js")),
623+
args.join(" "),
614624
);
615-
assert(compilerArgs.includes("-bs-read-cmi"));
625+
assert(args.includes("-bs-read-cmi"));
616626
});

0 commit comments

Comments
 (0)