Skip to content

Commit 3a11d60

Browse files
authored
Remove handling of .ml/.mli sources from ninja.js (#6857)
* Remove handling of .ml/.mli sources from ninja.js * Remove jscomp/test/*.mll
1 parent 5fb1622 commit 3a11d60

File tree

4 files changed

+13
-168
lines changed

4 files changed

+13
-168
lines changed

jscomp/test/arith_lexer.mll

-30
This file was deleted.

jscomp/test/build.ninja

-10
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ rule cc_cmi
88
command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I test $in
99
description = $in -> $out
1010

11-
12-
13-
14-
rule mll
15-
command = $ocamllex $in
16-
generator = true
17-
18-
o test/arith_lexer.ml : mll test/arith_lexer.mll
19-
o test/number_lexer.ml : mll test/number_lexer.mll
20-
o test/simple_lexer_test.ml : mll test/simple_lexer_test.mll
2111
o test/406_primitive_test.cmi test/406_primitive_test.cmj : cc test/406_primitive_test.res | test/mt.cmj $bsc $stdlib runtime
2212
o test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj : cc test/AsInUncurriedExternals.res | $bsc $stdlib runtime
2313
o test/Coercion.cmi test/Coercion.cmj : cc test/Coercion.res | $bsc $stdlib runtime

jscomp/test/number_lexer.mll

-30
This file was deleted.

scripts/ninja.js

+13-98
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ var jsDir = path.join(__dirname, "..", "lib", "js");
1616

1717
var runtimeFiles = fs.readdirSync(runtimeDir, "ascii");
1818
var runtimeMlFiles = runtimeFiles.filter(
19-
x =>
20-
!x.startsWith("bs_stdlib_mini") &&
21-
(x.endsWith(".ml") || x.endsWith(".res")) &&
22-
x !== "js.res"
19+
x => !x.startsWith("bs_stdlib_mini") && x.endsWith(".res") && x !== "js.res",
2320
);
2421
var runtimeMliFiles = runtimeFiles.filter(
2522
x =>
26-
!x.startsWith("bs_stdlib_mini") &&
27-
(x.endsWith(".mli") || x.endsWith(".resi")) &&
28-
x !== "js.mli",
23+
!x.startsWith("bs_stdlib_mini") && x.endsWith(".resi") && x !== "js.resi",
2924
);
3025
var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles);
3126
var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))];
@@ -462,20 +457,6 @@ function cppoList(cwd, xs) {
462457
})
463458
.join("\n");
464459
}
465-
/**
466-
*
467-
* @param {string} cwd
468-
* @param {string[]} xs
469-
* @returns {string}
470-
*/
471-
function mllList(cwd, xs) {
472-
return xs
473-
.map(x => {
474-
var output = baseName(x) + ".ml";
475-
return ninjaQuickBuild(output, x, mllRuleName, cwd, [], [], []);
476-
})
477-
.join("\n");
478-
}
479460

480461
/**
481462
*
@@ -541,9 +522,9 @@ function replaceCmj(x) {
541522
* @param {string} y
542523
*/
543524
function sourceToTarget(y) {
544-
if (y.endsWith(".ml") || y.endsWith(".res")) {
525+
if (y.endsWith(".res")) {
545526
return replaceExt(y, ".cmj");
546-
} else if (y.endsWith(".mli") || y.endsWith(".resi")) {
527+
} else if (y.endsWith(".resi")) {
547528
return replaceExt(y, ".cmi");
548529
}
549530
return y;
@@ -629,7 +610,6 @@ function ocamlDepForBscAsync(files, dir, depsMap) {
629610
* By default `ocamldep.opt` only list dependencies in its args
630611
*/
631612
function depModulesForBscAsync(files, dir, depsMap) {
632-
let ocamlFiles = files.filter(x => x.endsWith(".ml") || x.endsWith(".mli"));
633613
let resFiles = files.filter(x => x.endsWith(".res") || x.endsWith(".resi"));
634614
/**
635615
*
@@ -667,9 +647,7 @@ function depModulesForBscAsync(files, dir, depsMap) {
667647
return [
668648
new Promise((resolve, reject) => {
669649
cp.exec(
670-
`${bsc_exe} -modules -bs-syntax-only ${resFiles.join(
671-
" ",
672-
)} ${ocamlFiles.join(" ")}`,
650+
`${bsc_exe} -modules -bs-syntax-only ${resFiles.join(" ")}`,
673651
config,
674652
cb(resolve, reject),
675653
);
@@ -678,7 +656,7 @@ function depModulesForBscAsync(files, dir, depsMap) {
678656
}
679657

680658
/**
681-
* @typedef {('HAS_ML' | 'HAS_MLI' | 'HAS_BOTH' | 'HAS_RES' | 'HAS_RESI' | 'HAS_BOTH_RES')} FileInfo
659+
* @typedef {('HAS_RES' | 'HAS_RESI' | 'HAS_BOTH_RES')} FileInfo
682660
* @param {string[]} sourceFiles
683661
* @returns {Map<string, FileInfo>}
684662
* We make a set to ensure that `sourceFiles` are not duplicated
@@ -692,38 +670,23 @@ function collectTarget(sourceFiles) {
692670
var { ext, name } = path.parse(x);
693671
var existExt = allTargets.get(name);
694672
if (existExt === undefined) {
695-
if (ext === ".ml") {
696-
allTargets.set(name, "HAS_ML");
697-
} else if (ext === ".mli") {
698-
allTargets.set(name, "HAS_MLI");
699-
} else if (ext === ".res") {
673+
if (ext === ".res") {
700674
allTargets.set(name, "HAS_RES");
701675
} else if (ext === ".resi") {
702676
allTargets.set(name, "HAS_RESI");
703677
}
704678
} else {
705679
switch (existExt) {
706-
case "HAS_ML":
707-
if (ext === ".mli") {
708-
allTargets.set(name, "HAS_BOTH");
709-
}
710-
break;
711680
case "HAS_RES":
712681
if (ext === ".resi") {
713682
allTargets.set(name, "HAS_BOTH_RES");
714683
}
715684
break;
716-
case "HAS_MLI":
717-
if (ext === ".ml") {
718-
allTargets.set(name, "HAS_BOTH");
719-
}
720-
break;
721685
case "HAS_RESI":
722686
if (ext === ".res") {
723687
allTargets.set(name, "HAS_BOTH_RES");
724688
}
725689
break;
726-
case "HAS_BOTH":
727690
case "HAS_BOTH_RES":
728691
break;
729692
}
@@ -744,15 +707,12 @@ function scanFileTargets(allTargets, collIn) {
744707
allTargets.forEach((ext, mod) => {
745708
switch (ext) {
746709
case "HAS_RESI":
747-
case "HAS_MLI":
748710
coll.push(`${mod}.cmi`);
749711
break;
750712
case "HAS_BOTH_RES":
751-
case "HAS_BOTH":
752713
coll.push(`${mod}.cmi`, `${mod}.cmj`);
753714
break;
754715
case "HAS_RES":
755-
case "HAS_ML":
756716
coll.push(`${mod}.cmi`, `${mod}.cmj`);
757717
break;
758718
}
@@ -776,8 +736,6 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
776736
allTargets.forEach((x, mod) => {
777737
let ouptput_cmj = mod + ".cmj";
778738
let output_cmi = mod + ".cmi";
779-
let input_ml = mod + ".ml";
780-
let input_mli = mod + ".mli";
781739
let input_res = mod + ".res";
782740
let input_resi = mod + ".resi";
783741
/**
@@ -800,26 +758,16 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
800758
);
801759
};
802760
switch (x) {
803-
case "HAS_BOTH":
804-
mk([ouptput_cmj], [input_ml], "cc_cmi");
805-
mk([output_cmi], [input_mli]);
806-
break;
807761
case "HAS_BOTH_RES":
808762
mk([ouptput_cmj], [input_res], "cc_cmi");
809763
mk([output_cmi], [input_resi]);
810764
break;
811765
case "HAS_RES":
812766
mk([output_cmi, ouptput_cmj], [input_res]);
813767
break;
814-
case "HAS_ML":
815-
mk([output_cmi, ouptput_cmj], [input_ml]);
816-
break;
817768
case "HAS_RESI":
818769
mk([output_cmi], [input_resi]);
819770
break;
820-
case "HAS_MLI":
821-
mk([output_cmi], [input_mli]);
822-
break;
823771
}
824772
});
825773
return build_stmts;
@@ -867,13 +815,10 @@ ${ninjaQuickBuildList([
867815
var allFileTargetsInRuntime = scanFileTargets(allTargets, manualDeps);
868816
allTargets.forEach((ext, mod) => {
869817
switch (ext) {
870-
case "HAS_MLI":
871-
case "HAS_BOTH":
872818
case "HAS_RESI":
873819
case "HAS_BOTH_RES":
874820
updateDepsKVsByFile(mod + ".cmi", manualDeps, depsMap);
875821
break;
876-
case "HAS_ML":
877822
case "HAS_RES":
878823
updateDepsKVsByFile(mod + ".cmj", manualDeps, depsMap);
879824
break;
@@ -907,13 +852,6 @@ rule ${cppoRuleName}
907852
generator = true
908853
`;
909854

910-
var mllRuleName = `mll`;
911-
var mllRule = `
912-
rule ${mllRuleName}
913-
command = $ocamllex $in
914-
generator = true
915-
`;
916-
917855
async function othersNinja(devmode = true) {
918856
var compilerTarget = pseudoTarget("$bsc");
919857
var externalDeps = [
@@ -962,24 +900,18 @@ ${ninjaQuickBuildList([
962900
var jsPrefixSourceFiles = othersDirFiles.filter(
963901
x =>
964902
x.startsWith("js") &&
965-
(x.endsWith(".ml") ||
966-
x.endsWith(".mli") ||
967-
x.endsWith(".res") ||
968-
x.endsWith(".resi")) &&
903+
(x.endsWith(".res") || x.endsWith(".resi")) &&
969904
!x.includes(".cppo") &&
970905
!x.includes(".pp") &&
971906
!x.includes("#") &&
972-
x !== "js.res"
907+
x !== "js.res",
973908
);
974909
var othersFiles = othersDirFiles.filter(
975910
x =>
976911
!x.startsWith("js") &&
977912
x !== "belt.res" &&
978913
x !== "belt_internals.resi" &&
979-
(x.endsWith(".ml") ||
980-
x.endsWith(".mli") ||
981-
x.endsWith(".res") ||
982-
x.endsWith(".resi")) &&
914+
(x.endsWith(".res") || x.endsWith(".resi")) &&
983915
!x.includes("#") &&
984916
!x.includes(".cppo"),
985917
);
@@ -994,7 +926,7 @@ ${ninjaQuickBuildList([
994926
var jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, externalDeps);
995927
jsOutput.push(phony(js_package, fileTargets(allJsTargets), ninjaCwd));
996928

997-
// Note compiling belt.ml still try to read
929+
// Note compiling belt.res still try to read
998930
// belt_xx.cmi we need enforce the order to
999931
// avoid data race issues
1000932
var beltPackage = fileTarget("belt.cmi");
@@ -1008,7 +940,6 @@ ${ninjaQuickBuildList([
1008940
var allOthersTarget = scanFileTargets(beltTargets, []);
1009941
var beltOutput = generateNinja(depsMap, beltTargets, ninjaCwd, externalDeps);
1010942
beltOutput.push(phony(othersTarget, fileTargets(allOthersTarget), ninjaCwd));
1011-
// ninjaBuild([`belt_HashSetString.ml`,])
1012943
writeFileAscii(
1013944
path.join(othersDir, ninjaOutput),
1014945
templateOthersRules +
@@ -1081,13 +1012,10 @@ ${ninjaQuickBuildList([
10811012
]);
10821013
targets.forEach((ext, mod) => {
10831014
switch (ext) {
1084-
case "HAS_MLI":
1085-
case "HAS_BOTH":
10861015
case "HAS_RESI":
10871016
case "HAS_BOTH_RES":
10881017
updateDepsKVByFile(mod + ".cmi", "pervasives.cmj", depsMap);
10891018
break;
1090-
case "HAS_ML":
10911019
case "HAS_RES":
10921020
updateDepsKVByFile(mod + ".cmj", "pervasives.cmj", depsMap);
10931021
break;
@@ -1157,23 +1085,10 @@ async function testNinja() {
11571085
var templateTestRules = `
11581086
bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others
11591087
${ruleCC(ninjaCwd)}
1160-
1161-
1162-
${mllRule}
1163-
${mllList(ninjaCwd, [
1164-
"arith_lexer.mll",
1165-
"number_lexer.mll",
1166-
"simple_lexer_test.mll",
1167-
])}
11681088
`;
11691089
var testDirFiles = fs.readdirSync(testDir, "ascii");
11701090
var sources = testDirFiles.filter(x => {
1171-
return (
1172-
x.endsWith(".resi") ||
1173-
x.endsWith(".res") ||
1174-
x.endsWith(".ml") ||
1175-
x.endsWith(".mli")
1176-
);
1091+
return x.endsWith(".resi") || x.endsWith(".res");
11771092
});
11781093

11791094
let depsMap = createDepsMapWithTargets(sources);
@@ -1216,7 +1131,7 @@ function runJSCheckAsync(depsMap) {
12161131
fs.readFile(jsFile, "utf8", function (err, fileContent) {
12171132
if (err === null) {
12181133
var deps = getDeps(fileContent).map(x => path.parse(x).name + ".cmj");
1219-
fs.exists(path.join(runtimeDir, name + ".mli"), exist => {
1134+
fs.exists(path.join(runtimeDir, name + ".resi"), exist => {
12201135
if (exist) {
12211136
deps.push(name + ".cmi");
12221137
}

0 commit comments

Comments
 (0)