Skip to content

Commit 568211c

Browse files
committed
Add vendor/ocaml.tar.gz so git submodule is not needed for developer who are not devs
Check getVersionPrefix is not hit in windows installation
1 parent 516cfcc commit 568211c

File tree

6 files changed

+47
-52
lines changed

6 files changed

+47
-52
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: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ 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;
30+
31+
/**
32+
* @type {string}
33+
*/
34+
var ocamlVersion;
35+
36+
/**
37+
*
38+
* @param {string} p
39+
*/
40+
function addPath(p) {
41+
process.env.PATH = p + path.delimiter + process.env.PATH;
42+
}
4143

4244
var ninja_bin_output = path.join(root_dir, "lib", "ninja.exe");
4345

@@ -196,6 +198,10 @@ function install() {
196198
var y = path.parse(file);
197199
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
198200
});
201+
var stdlib_dir = path.join(
202+
jscomp_dir,
203+
ocamlVersion.includes("4.02") ? "stdlib-402" : "stdlib-406"
204+
);
199205
installDirBy(stdlib_dir, ocaml_dir, function(file) {
200206
var y = path.parse(file);
201207
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
@@ -293,10 +299,15 @@ function copyPrebuiltCompilers() {
293299
*/
294300
function checkPrebuiltBscCompiler() {
295301
try {
296-
var version = cp.execFileSync(path.join(lib_dir, "bsc" + sys_extension), [
297-
"-v"
298-
]);
299-
console.log("checkoutput:", String(version));
302+
var version = String(
303+
cp.execFileSync(path.join(lib_dir, "bsc" + sys_extension), ["-v"])
304+
);
305+
306+
ocamlVersion = version.substr(
307+
version.indexOf(":") + 1,
308+
version.lastIndexOf(" ") - version.indexOf(":") - 1
309+
);
310+
console.log("checkoutput:", version, "ocaml version", ocamlVersion);
300311
console.log("Prebuilt compiler works good");
301312

302313
return true;
@@ -350,6 +361,8 @@ function provideCompiler() {
350361
if (checkPrebuiltBscCompiler()) {
351362
copyPrebuiltCompilers();
352363
} else {
364+
ocamlVersion = require("./buildocaml.js").getVersionPrefix();
365+
addPath(path.join(__dirname, "..", "native", ocamlVersion, "bin"));
353366
// when not having bsc.exe
354367
tryToProvideOCamlCompiler();
355368
// Note this ninja file only works under *nix due to the suffix

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)