Skip to content

Remove handling of .ml/.mli sources from ninja.js #6857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions jscomp/test/arith_lexer.mll

This file was deleted.

10 changes: 0 additions & 10 deletions jscomp/test/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ rule cc_cmi
command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I test $in
description = $in -> $out




rule mll
command = $ocamllex $in
generator = true

o test/arith_lexer.ml : mll test/arith_lexer.mll
o test/number_lexer.ml : mll test/number_lexer.mll
o test/simple_lexer_test.ml : mll test/simple_lexer_test.mll
o test/406_primitive_test.cmi test/406_primitive_test.cmj : cc test/406_primitive_test.res | test/mt.cmj $bsc $stdlib runtime
o test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj : cc test/AsInUncurriedExternals.res | $bsc $stdlib runtime
o test/Coercion.cmi test/Coercion.cmj : cc test/Coercion.res | $bsc $stdlib runtime
Expand Down
30 changes: 0 additions & 30 deletions jscomp/test/number_lexer.mll

This file was deleted.

111 changes: 13 additions & 98 deletions scripts/ninja.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ var jsDir = path.join(__dirname, "..", "lib", "js");

var runtimeFiles = fs.readdirSync(runtimeDir, "ascii");
var runtimeMlFiles = runtimeFiles.filter(
x =>
!x.startsWith("bs_stdlib_mini") &&
(x.endsWith(".ml") || x.endsWith(".res")) &&
x !== "js.res"
x => !x.startsWith("bs_stdlib_mini") && x.endsWith(".res") && x !== "js.res",
);
var runtimeMliFiles = runtimeFiles.filter(
x =>
!x.startsWith("bs_stdlib_mini") &&
(x.endsWith(".mli") || x.endsWith(".resi")) &&
x !== "js.mli",
!x.startsWith("bs_stdlib_mini") && x.endsWith(".resi") && x !== "js.resi",
);
var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles);
var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))];
Expand Down Expand Up @@ -462,20 +457,6 @@ function cppoList(cwd, xs) {
})
.join("\n");
}
/**
*
* @param {string} cwd
* @param {string[]} xs
* @returns {string}
*/
function mllList(cwd, xs) {
return xs
.map(x => {
var output = baseName(x) + ".ml";
return ninjaQuickBuild(output, x, mllRuleName, cwd, [], [], []);
})
.join("\n");
}

/**
*
Expand Down Expand Up @@ -541,9 +522,9 @@ function replaceCmj(x) {
* @param {string} y
*/
function sourceToTarget(y) {
if (y.endsWith(".ml") || y.endsWith(".res")) {
if (y.endsWith(".res")) {
return replaceExt(y, ".cmj");
} else if (y.endsWith(".mli") || y.endsWith(".resi")) {
} else if (y.endsWith(".resi")) {
return replaceExt(y, ".cmi");
}
return y;
Expand Down Expand Up @@ -629,7 +610,6 @@ function ocamlDepForBscAsync(files, dir, depsMap) {
* By default `ocamldep.opt` only list dependencies in its args
*/
function depModulesForBscAsync(files, dir, depsMap) {
let ocamlFiles = files.filter(x => x.endsWith(".ml") || x.endsWith(".mli"));
let resFiles = files.filter(x => x.endsWith(".res") || x.endsWith(".resi"));
/**
*
Expand Down Expand Up @@ -667,9 +647,7 @@ function depModulesForBscAsync(files, dir, depsMap) {
return [
new Promise((resolve, reject) => {
cp.exec(
`${bsc_exe} -modules -bs-syntax-only ${resFiles.join(
" ",
)} ${ocamlFiles.join(" ")}`,
`${bsc_exe} -modules -bs-syntax-only ${resFiles.join(" ")}`,
config,
cb(resolve, reject),
);
Expand All @@ -678,7 +656,7 @@ function depModulesForBscAsync(files, dir, depsMap) {
}

/**
* @typedef {('HAS_ML' | 'HAS_MLI' | 'HAS_BOTH' | 'HAS_RES' | 'HAS_RESI' | 'HAS_BOTH_RES')} FileInfo
* @typedef {('HAS_RES' | 'HAS_RESI' | 'HAS_BOTH_RES')} FileInfo
* @param {string[]} sourceFiles
* @returns {Map<string, FileInfo>}
* We make a set to ensure that `sourceFiles` are not duplicated
Expand All @@ -692,38 +670,23 @@ function collectTarget(sourceFiles) {
var { ext, name } = path.parse(x);
var existExt = allTargets.get(name);
if (existExt === undefined) {
if (ext === ".ml") {
allTargets.set(name, "HAS_ML");
} else if (ext === ".mli") {
allTargets.set(name, "HAS_MLI");
} else if (ext === ".res") {
if (ext === ".res") {
allTargets.set(name, "HAS_RES");
} else if (ext === ".resi") {
allTargets.set(name, "HAS_RESI");
}
} else {
switch (existExt) {
case "HAS_ML":
if (ext === ".mli") {
allTargets.set(name, "HAS_BOTH");
}
break;
case "HAS_RES":
if (ext === ".resi") {
allTargets.set(name, "HAS_BOTH_RES");
}
break;
case "HAS_MLI":
if (ext === ".ml") {
allTargets.set(name, "HAS_BOTH");
}
break;
case "HAS_RESI":
if (ext === ".res") {
allTargets.set(name, "HAS_BOTH_RES");
}
break;
case "HAS_BOTH":
case "HAS_BOTH_RES":
break;
}
Expand All @@ -744,15 +707,12 @@ function scanFileTargets(allTargets, collIn) {
allTargets.forEach((ext, mod) => {
switch (ext) {
case "HAS_RESI":
case "HAS_MLI":
coll.push(`${mod}.cmi`);
break;
case "HAS_BOTH_RES":
case "HAS_BOTH":
coll.push(`${mod}.cmi`, `${mod}.cmj`);
break;
case "HAS_RES":
case "HAS_ML":
coll.push(`${mod}.cmi`, `${mod}.cmj`);
break;
}
Expand All @@ -776,8 +736,6 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
allTargets.forEach((x, mod) => {
let ouptput_cmj = mod + ".cmj";
let output_cmi = mod + ".cmi";
let input_ml = mod + ".ml";
let input_mli = mod + ".mli";
let input_res = mod + ".res";
let input_resi = mod + ".resi";
/**
Expand All @@ -800,26 +758,16 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
);
};
switch (x) {
case "HAS_BOTH":
mk([ouptput_cmj], [input_ml], "cc_cmi");
mk([output_cmi], [input_mli]);
break;
case "HAS_BOTH_RES":
mk([ouptput_cmj], [input_res], "cc_cmi");
mk([output_cmi], [input_resi]);
break;
case "HAS_RES":
mk([output_cmi, ouptput_cmj], [input_res]);
break;
case "HAS_ML":
mk([output_cmi, ouptput_cmj], [input_ml]);
break;
case "HAS_RESI":
mk([output_cmi], [input_resi]);
break;
case "HAS_MLI":
mk([output_cmi], [input_mli]);
break;
}
});
return build_stmts;
Expand Down Expand Up @@ -867,13 +815,10 @@ ${ninjaQuickBuildList([
var allFileTargetsInRuntime = scanFileTargets(allTargets, manualDeps);
allTargets.forEach((ext, mod) => {
switch (ext) {
case "HAS_MLI":
case "HAS_BOTH":
case "HAS_RESI":
case "HAS_BOTH_RES":
updateDepsKVsByFile(mod + ".cmi", manualDeps, depsMap);
break;
case "HAS_ML":
case "HAS_RES":
updateDepsKVsByFile(mod + ".cmj", manualDeps, depsMap);
break;
Expand Down Expand Up @@ -907,13 +852,6 @@ rule ${cppoRuleName}
generator = true
`;

var mllRuleName = `mll`;
var mllRule = `
rule ${mllRuleName}
command = $ocamllex $in
generator = true
`;

async function othersNinja(devmode = true) {
var compilerTarget = pseudoTarget("$bsc");
var externalDeps = [
Expand Down Expand Up @@ -962,24 +900,18 @@ ${ninjaQuickBuildList([
var jsPrefixSourceFiles = othersDirFiles.filter(
x =>
x.startsWith("js") &&
(x.endsWith(".ml") ||
x.endsWith(".mli") ||
x.endsWith(".res") ||
x.endsWith(".resi")) &&
(x.endsWith(".res") || x.endsWith(".resi")) &&
!x.includes(".cppo") &&
!x.includes(".pp") &&
!x.includes("#") &&
x !== "js.res"
x !== "js.res",
);
var othersFiles = othersDirFiles.filter(
x =>
!x.startsWith("js") &&
x !== "belt.res" &&
x !== "belt_internals.resi" &&
(x.endsWith(".ml") ||
x.endsWith(".mli") ||
x.endsWith(".res") ||
x.endsWith(".resi")) &&
(x.endsWith(".res") || x.endsWith(".resi")) &&
!x.includes("#") &&
!x.includes(".cppo"),
);
Expand All @@ -994,7 +926,7 @@ ${ninjaQuickBuildList([
var jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, externalDeps);
jsOutput.push(phony(js_package, fileTargets(allJsTargets), ninjaCwd));

// Note compiling belt.ml still try to read
// Note compiling belt.res still try to read
// belt_xx.cmi we need enforce the order to
// avoid data race issues
var beltPackage = fileTarget("belt.cmi");
Expand All @@ -1008,7 +940,6 @@ ${ninjaQuickBuildList([
var allOthersTarget = scanFileTargets(beltTargets, []);
var beltOutput = generateNinja(depsMap, beltTargets, ninjaCwd, externalDeps);
beltOutput.push(phony(othersTarget, fileTargets(allOthersTarget), ninjaCwd));
// ninjaBuild([`belt_HashSetString.ml`,])
writeFileAscii(
path.join(othersDir, ninjaOutput),
templateOthersRules +
Expand Down Expand Up @@ -1081,13 +1012,10 @@ ${ninjaQuickBuildList([
]);
targets.forEach((ext, mod) => {
switch (ext) {
case "HAS_MLI":
case "HAS_BOTH":
case "HAS_RESI":
case "HAS_BOTH_RES":
updateDepsKVByFile(mod + ".cmi", "pervasives.cmj", depsMap);
break;
case "HAS_ML":
case "HAS_RES":
updateDepsKVByFile(mod + ".cmj", "pervasives.cmj", depsMap);
break;
Expand Down Expand Up @@ -1157,23 +1085,10 @@ async function testNinja() {
var templateTestRules = `
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
${ruleCC(ninjaCwd)}


${mllRule}
${mllList(ninjaCwd, [
"arith_lexer.mll",
"number_lexer.mll",
"simple_lexer_test.mll",
])}
`;
var testDirFiles = fs.readdirSync(testDir, "ascii");
var sources = testDirFiles.filter(x => {
return (
x.endsWith(".resi") ||
x.endsWith(".res") ||
x.endsWith(".ml") ||
x.endsWith(".mli")
);
return x.endsWith(".resi") || x.endsWith(".res");
});

let depsMap = createDepsMapWithTargets(sources);
Expand Down Expand Up @@ -1216,7 +1131,7 @@ function runJSCheckAsync(depsMap) {
fs.readFile(jsFile, "utf8", function (err, fileContent) {
if (err === null) {
var deps = getDeps(fileContent).map(x => path.parse(x).name + ".cmj");
fs.exists(path.join(runtimeDir, name + ".mli"), exist => {
fs.exists(path.join(runtimeDir, name + ".resi"), exist => {
if (exist) {
deps.push(name + ".cmi");
}
Expand Down