Skip to content

Commit 9a429f7

Browse files
authored
Merge pull request #3812 from BuckleScript/fix_3674
fix #3674
2 parents 516cfcc + 689814a commit 9a429f7

File tree

6 files changed

+73
-122
lines changed

6 files changed

+73
-122
lines changed

jscomp/core/ocaml_options.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ let show_config () =
253253

254254
let bs_version_string =
255255
"BuckleScript " ^ Bs_version.version ^
256-
" (Using OCaml" ^ Config.version ^ " )"
256+
" ( Using OCaml:" ^ Config.version ^ " )"
257257

258258
let print_version_string () =
259259
print_string bs_version_string;

lib/4.02.3/whole_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123692,7 +123692,7 @@ let show_config () =
123692123692

123693123693
let bs_version_string =
123694123694
"BuckleScript " ^ Bs_version.version ^
123695-
" (Using OCaml" ^ Config.version ^ " )"
123695+
" ( Using OCaml:" ^ Config.version ^ " )"
123696123696

123697123697
let print_version_string () =
123698123698
print_string bs_version_string;

scripts/buildocaml.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var cp = require("child_process");
44
var path = require("path");
55
var fs = require("fs");
66

7+
var ocamlSrcDir = path.join(__dirname, "..", "ocaml");
78
/**
89
* @type {string}
910
*/
@@ -18,36 +19,18 @@ function getVersionPrefix() {
1819
return cached;
1920
}
2021

21-
var file = path.join(__dirname, "..", "OCAML_VERSION");
22-
if (fs.existsSync(file)) {
23-
console.log(`${file} is used in version detection`)
24-
var version = fs.readFileSync(file, "ascii");
25-
cached = version.substr(0, version.indexOf("+"));
26-
return cached;
27-
}
28-
29-
30-
file = path.join(__dirname, "..", "ocaml", "VERSION");
31-
if (fs.existsSync(file)) {
32-
console.log(`${file} is used in version detection`)
33-
var version = fs.readFileSync(file, "ascii");
34-
cached = version.substr(0, version.indexOf("+"));
35-
return cached;
22+
var file = path.join(__dirname, "..", "ocaml", "VERSION");
23+
if (!fs.existsSync(file)) {
24+
cp.execSync(`tar xzvf ../vendor/ocaml.tar.gz`, {
25+
cwd: ocamlSrcDir,
26+
stdio: [0, 1, 2]
27+
});
3628
}
37-
38-
39-
console.warn(
40-
"You should create OCAML_VERSION or ocaml/VERSION file to specify OCaml version like '4.02.3+buckle-master'"
41-
);
42-
console.warn(`for example,
43-
bucklescript>cat ocaml/VERSION
44-
4.02.3+BS
45-
46-
# The version string is the first line of this file.
47-
# It must be in the format described in stdlib/sys.mli
48-
`);
4929

50-
throw new Error("version file not found");
30+
console.log(`${file} is used in version detection`);
31+
var version = fs.readFileSync(file, "ascii");
32+
cached = version.substr(0, version.indexOf("+"));
33+
return cached;
5134
}
5235
exports.getVersionPrefix = getVersionPrefix;
5336

@@ -56,12 +39,11 @@ exports.getVersionPrefix = getVersionPrefix;
5639
* @param {boolean} config
5740
*/
5841
function build(config) {
59-
var ocamlSrcDir = path.join(__dirname, "..", "ocaml");
6042
if (!fs.existsSync(ocamlSrcDir)) {
6143
fs.mkdirSync(ocamlSrcDir);
6244
}
6345
if (!fs.existsSync(path.join(ocamlSrcDir, "VERSION"))) {
64-
cp.execSync(`tar xzvf ../ocaml.tar.gz`, {
46+
cp.execSync(`tar xzvf ../vendor/ocaml.tar.gz`, {
6547
cwd: ocamlSrcDir,
6648
stdio: [0, 1, 2]
6749
});

scripts/install.js

Lines changed: 54 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ var is_windows = config.is_windows;
2727
var sys_extension = config.sys_extension;
2828

2929
process.env.BS_RELEASE_BUILD = "true";
30-
var ocamlVersion = require("./buildocaml.js").getVersionPrefix();
31-
var stdlib_dir = path.join(
32-
jscomp_dir,
33-
ocamlVersion.includes("4.02") ? "stdlib-402" : "stdlib-406"
34-
);
35-
// Add vendor bin path
36-
// So that second try will work
37-
process.env.PATH =
38-
path.join(__dirname, "..", "native", ocamlVersion, "bin") +
39-
path.delimiter +
40-
process.env.PATH;
4130

4231
var ninja_bin_output = path.join(root_dir, "lib", "ninja.exe");
4332

@@ -187,7 +176,11 @@ function ensureExists(dir) {
187176
fs.mkdirSync(dir);
188177
}
189178
}
190-
function install() {
179+
180+
/**
181+
* @param {string} stdlib
182+
*/
183+
function install(stdlib) {
191184
installDirBy(runtime_dir, ocaml_dir, function(file) {
192185
var y = path.parse(file);
193186
return y.name === "js" || y.ext.includes("cm");
@@ -196,58 +189,13 @@ function install() {
196189
var y = path.parse(file);
197190
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
198191
});
192+
var stdlib_dir = path.join(jscomp_dir, stdlib);
199193
installDirBy(stdlib_dir, ocaml_dir, function(file) {
200194
var y = path.parse(file);
201195
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
202196
});
203197
}
204198

205-
/**
206-
* raise an exception if not matched
207-
*/
208-
function matchedCompilerExn() {
209-
var output = cp.execSync("ocamlc.opt -v", { encoding: "ascii" });
210-
211-
if (output.indexOf(ocamlVersion) >= 0) {
212-
console.log(output);
213-
console.log("Use the compiler above");
214-
} else {
215-
console.log(
216-
"version",
217-
output,
218-
"needed version",
219-
ocamlVersion,
220-
"No matched compiler found, may re-try"
221-
);
222-
throw "";
223-
}
224-
}
225-
function tryToProvideOCamlCompiler() {
226-
try {
227-
if (process.env.BS_ALWAYS_BUILD_YOUR_COMPILER) {
228-
throw "FORCED TO REBUILD";
229-
}
230-
matchedCompilerExn();
231-
} catch (e) {
232-
console.log(
233-
"Build a local version of OCaml compiler, it may take a couple of minutes"
234-
);
235-
try {
236-
require("./buildocaml.js").build(true);
237-
} catch (e) {
238-
console.log(e.stdout.toString());
239-
console.log(e.stderr.toString());
240-
console.log(
241-
"Building a local version of the OCaml compiler failed, check the output above for more information. A possible problem is that you don't have a compiler installed."
242-
);
243-
throw e;
244-
}
245-
console.log("configure again with local ocaml installed");
246-
matchedCompilerExn();
247-
console.log("config finished");
248-
}
249-
}
250-
251199
/**
252200
*
253201
* @param {string} sys_extension
@@ -289,31 +237,42 @@ function copyPrebuiltCompilers() {
289237
}
290238

291239
/**
292-
* @returns {boolean}
240+
* @returns {string|undefined}
293241
*/
294242
function checkPrebuiltBscCompiler() {
295243
try {
296-
var version = cp.execFileSync(path.join(lib_dir, "bsc" + sys_extension), [
297-
"-v"
298-
]);
299-
console.log("checkoutput:", String(version));
244+
var version = String(
245+
cp.execFileSync(path.join(lib_dir, "bsc" + sys_extension), ["-v"])
246+
);
247+
248+
var myOCamlVersion = version.substr(
249+
version.indexOf(":") + 1,
250+
version.lastIndexOf(" ") - version.indexOf(":") - 1
251+
);
252+
console.log("checkoutput:", version, "ocaml version", myOCamlVersion);
300253
console.log("Prebuilt compiler works good");
301254

302-
return true;
255+
return myOCamlVersion;
303256
} catch (e) {
304257
console.log("No working prebuilt buckleScript compiler");
305-
return false;
258+
if (is_windows) {
259+
throw new Error("no prebuilt bsc compiler on windows");
260+
}
261+
return;
306262
}
307263
}
308-
309-
function buildLibs() {
264+
/**
265+
*
266+
* @param {string} stdlib
267+
*/
268+
function buildLibs(stdlib) {
310269
ensureExists(lib_dir);
311270
ensureExists(ocaml_dir);
312271
ensureExists(path.join(lib_dir, "js"));
313272
ensureExists(path.join(lib_dir, "es6"));
314273
process.env.NINJA_IGNORE_GENERATOR = "true";
315274
var releaseNinja = `
316-
stdlib = ${ocamlVersion.includes("4.06") ? "stdlib-406" : "stdlib-402"}
275+
stdlib = ${stdlib}
317276
subninja runtime/release.ninja
318277
subninja others/release.ninja
319278
subninja $stdlib/release.ninja
@@ -341,23 +300,35 @@ build all: phony runtime others $stdlib
341300
console.log("Build finished");
342301
}
343302

303+
/**
304+
* @returns {string}
305+
*/
344306
function provideCompiler() {
345-
// FIXME: weird logic
346-
// if (fs.existsSync(path.join(lib_dir,'ocaml','pervasives.cmi'))) {
347-
// console.log('Found pervasives.cmi, assume it was already built')
348-
// return true // already built before
349-
// }
350-
if (checkPrebuiltBscCompiler()) {
307+
var myVersion = checkPrebuiltBscCompiler();
308+
if (myVersion !== undefined) {
351309
copyPrebuiltCompilers();
310+
return myVersion;
352311
} else {
353-
// when not having bsc.exe
354-
tryToProvideOCamlCompiler();
312+
myVersion = require("./buildocaml.js").getVersionPrefix();
313+
var ocamlopt = path.join(
314+
__dirname,
315+
"..",
316+
"native",
317+
myVersion,
318+
"bin",
319+
"ocamlopt.opt"
320+
);
321+
if (!fs.existsSync(ocamlopt)) {
322+
require("./buildocaml.js").build(true);
323+
} else {
324+
console.log(ocamlopt, "is already there");
325+
}
355326
// Note this ninja file only works under *nix due to the suffix
356327
// under windows require '.exe'
357328
var releaseNinja = require("./ninjaFactory.js").libNinja({
358-
ocamlopt: "ocamlopt.opt",
329+
ocamlopt: ocamlopt,
359330
ext: ".exe",
360-
INCL: ocamlVersion,
331+
INCL: myVersion,
361332
isWin: is_windows
362333
});
363334

@@ -368,17 +339,15 @@ function provideCompiler() {
368339
stdio: [0, 1, 2]
369340
});
370341
fs.unlinkSync(filePath);
342+
return myVersion;
371343
}
372344
}
373345

374346
provideNinja();
375347

376-
if (is_windows) {
377-
copyPrebuiltCompilers();
378-
} else {
379-
provideCompiler();
380-
}
348+
var ocamlVersion = provideCompiler();
381349

382-
buildLibs();
350+
var stdlib = ocamlVersion.includes("4.02") ? "stdlib-402" : "stdlib-406";
383351

384-
install();
352+
buildLibs(stdlib);
353+
install(stdlib);

scripts/prebuilt.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ function createOCamlTar() {
5555
if (os.platform() === hostPlatform) {
5656
cp.execSync(`git -C ocaml status -uno`, { cwd: root, stdio: [0, 1, 2] });
5757
cp.execSync(
58-
`git -C ocaml archive --format=tar.gz HEAD -o ../ocaml.tar.gz`,
58+
`git -C ocaml archive --format=tar.gz HEAD -o ../vendor/ocaml.tar.gz`,
5959
{ cwd: root, stdio: [0, 1, 2] }
6060
);
61-
fs.copyFileSync(
62-
path.join(root, "ocaml", "VERSION"),
63-
path.join(root, "OCAML_VERSION")
64-
);
61+
// fs.copyFileSync(
62+
// path.join(root, "ocaml", "VERSION"),
63+
// path.join(root, "OCAML_VERSION")
64+
// );
6565
}
6666
}
6767
createOCamlTar();

vendor/ocaml.tar.gz

8.46 MB
Binary file not shown.

0 commit comments

Comments
 (0)