Skip to content

Commit 4e9da87

Browse files
committed
fix build, {j|..|j} implies deps on Js module which may not apply in our repo
1 parent b96cf2f commit 4e9da87

17 files changed

+226
-19
lines changed

Diff for: jscomp/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BYTE=ocamlc.opt$(EXE)
1010
OCAMLLEX=ocamllex.opt$(EXE)
1111
CAMLP4OF=camlp4of
1212
CAMLDEP=ocamldep.opt$(EXE)
13-
COMPFLAGS=-g -w +6-40-30-23 -warn-error +a-40-30-23
13+
COMPFLAGS=-g -w +6-40-30-23 -warn-error +a-40-30-23 -absname
1414
# COMPFLAGS+= -S
1515

1616

Diff for: jscomp/others/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(addsuffix .cmj, $(SOURCE_LIST)): $(addsuffix .cmj, $(MAP_FILES))
1313

1414
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST)) $(addsuffix .cmi, $(SOURCE_LIST))
1515

16-
BS_COMMON_FLAGS= -no-alias-deps -bs-no-version-header -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-package-name bs-platform
16+
BS_COMMON_FLAGS= -no-alias-deps -bs-no-version-header -absname -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-package-name bs-platform
1717

1818

1919
BS_FLAGS= $(BS_COMMON_FLAGS) $(BS_PKG_FLAGS)

Diff for: jscomp/others/bs_array.ml

+21
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,24 @@ let iterX f xs =
6262
f (Array.unsafe_get xs i)
6363
done
6464
*)
65+
66+
external createUnsafe : int -> 'a t = "Array" [@@bs.new]
67+
68+
let ofList xs =
69+
match xs with
70+
| [] -> [||]
71+
| l ->
72+
let a = createUnsafe (List.length l) in
73+
let rec fill i = function
74+
| [] -> a
75+
| hd::tl -> Array.unsafe_set a i hd; fill (i+1) tl in
76+
fill 0 l
77+
78+
let map f a =
79+
let l = Array.length a in
80+
let r = createUnsafe l in
81+
for i = 0 to l - 1 do
82+
Array.unsafe_set r i (f(Array.unsafe_get a i) [@bs])
83+
done;
84+
r
85+

Diff for: jscomp/others/bs_array.mli

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ val pushBack : 'a -> 'a t -> unit
3333
val memByRef : 'a -> 'a t -> bool
3434

3535
val iter : ('a -> unit [@bs]) -> 'a array -> unit
36+
37+
val ofList : 'a list -> 'a t
38+
39+
val map : ('a -> 'b [@bs]) -> 'a t -> 'b t

Diff for: jscomp/others/bs_option.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let isNone = function
3636

3737
let getExn x =
3838
match x with
39-
| None -> Js_exn.raiseError {j| $__LOC__: Bs.Option.unsafeGet|j}
39+
| None -> Js_exn.raiseError "Bs_option.getExn"
4040
| Some x -> x
4141

4242
let equal eq a b =

Diff for: jscomp/others/node_process.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type t =
3838
external process : t = "" [@@bs.module]
3939

4040
external exit : int -> unit = "" [@@bs.module "process"]
41-
41+
external cwd : unit -> string = "" [@@bs.module "process"]
4242
(** The process.uptime() method returns the number of seconds
4343
the current Node.js process has been running.) *)
4444
external uptime : t -> unit -> float = "" [@@bs.send]

Diff for: jscomp/others/node_process.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type t =
3636
external process : t = "" [@@bs.module]
3737

3838
external exit : int -> unit = "" [@@bs.module "process"]
39-
39+
external cwd : unit -> string = "" [@@bs.module "process"]
4040
(** The process.uptime() method returns the number of seconds
4141
the current Node.js process has been running.) *)
4242
external uptime : t -> unit -> float = "" [@@bs.send]

Diff for: jscomp/test/.depend

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bench.cmj : ../stdlib/array.cmj
7474
bigarray_test.cmj : ../stdlib/int32.cmj ../stdlib/complex.cmj \
7575
../stdlib/bigarray.cmj
7676
boolean_test.cmj : test_bool_equal.cmj mt.cmj
77-
bs_array_test.cmj : ../runtime/js.cmj
77+
bs_array_test.cmj : mt.cmj ../runtime/js.cmj ../others/bs.cmj
7878
bs_auto_uncurry.cmj : ../runtime/js.cmj
7979
bs_auto_uncurry_test.cmj : mt.cmj ../others/js_array.cmj ../runtime/js.cmj
8080
bs_ignore_effect.cmj : mt.cmj

Diff for: jscomp/test/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ $(addsuffix .cmj, $(OTHERS)): ../runtime/js.cmj
172172

173173
# It is okay to test deprecated API
174174
COMPFLAGS+= $(MODULE_FLAGS) -w -40 -warn-error A+8-3-30-26
175-
COMPFLAGS+= -bs-no-version-header -bs-no-error-unused-attribute -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform
175+
COMPFLAGS+= -bs-no-version-header -absname -bs-no-error-unused-attribute -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform
176176

177177

178178
$(TESTS): $(CAMLC)

Diff for: jscomp/test/bs_array_test.js

+56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
'use strict';
22

3+
var Mt = require("./mt.js");
4+
var Block = require("../../lib/js/block.js");
5+
var Bs_array = require("../../lib/js/bs_array.js");
6+
7+
var suites = [/* [] */0];
8+
9+
var test_id = [0];
10+
11+
function eq(loc, x, y) {
12+
test_id[0] = test_id[0] + 1 | 0;
13+
suites[0] = /* :: */[
14+
/* tuple */[
15+
loc + (" id " + test_id[0]),
16+
function () {
17+
return /* Eq */Block.__(0, [
18+
x,
19+
y
20+
]);
21+
}
22+
],
23+
suites[0]
24+
];
25+
return /* () */0;
26+
}
327

428
console.log(/* int array */[
529
1,
@@ -14,4 +38,36 @@ console.log(/* int array */[
1438
return x + y | 0;
1539
}, 0));
1640

41+
eq("File \"bs_array_test.ml\", line 22, characters 5-12", Bs_array.ofList(/* :: */[
42+
1,
43+
/* :: */[
44+
2,
45+
/* :: */[
46+
3,
47+
/* [] */0
48+
]
49+
]
50+
]), /* int array */[
51+
1,
52+
2,
53+
3
54+
]);
55+
56+
eq("File \"bs_array_test.ml\", line 23, characters 6-13", Bs_array.map(function (x) {
57+
return x + 1 | 0;
58+
}, /* int array */[
59+
1,
60+
2,
61+
3
62+
]), /* int array */[
63+
2,
64+
3,
65+
4
66+
]);
67+
68+
Mt.from_pair_suites("File \"bs_array_test.ml\", line 27, characters 23-30", suites[0]);
69+
70+
exports.suites = suites;
71+
exports.test_id = test_id;
72+
exports.eq = eq;
1773
/* Not a pure module */

Diff for: jscomp/test/bs_array_test.ml

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11

2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y =
5+
incr test_id ;
6+
suites :=
7+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
8+
9+
210
type 'a t = 'a Js.Array.t
311
let () =
412
[| 1; 2; 3; 4 |]
513
|> Js.Array.filter (fun x -> x > 2)
614
|> Js.Array.mapi (fun x i -> x + i)
715
|> Js.Array.reduce (fun x y -> x + y) 0
816
|> Js.log
17+
18+
19+
20+
21+
let () =
22+
eq __LOC__ (Bs.Array.ofList [1;2;3]) [|1;2;3|];
23+
eq __LOC__
24+
( Bs.Array.map (fun [@bs] x -> x + 1) [|1;2;3|] )
25+
[|2;3;4|]
26+
27+
;; Mt.from_pair_suites __LOC__ !suites

Diff for: jscomp/watch-build.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
export OCAMLPARAM='_,bin-annot=1,annot=1'
6+
export OCAMLRUNPARAM=b
7+
export BS_DEBUG=true
8+
export npm_package_name=bs-platform
9+
10+
echo "Checking"
11+
make -r -j5 check
12+
echo "Linking"
13+
make -r -j2 bin/bsc.exe bin/bsb.exe
14+
echo "Making libs"
15+
make libs
16+
echo "Making test"
17+
make -C test -j30 all
18+
19+
echo "Update depend, snapshot"
20+
make -j7 depend snapshotml
21+
make -C test depend
22+
make -C runtime depend
23+
make -C others depend
24+
echo "Done"

Diff for: jscomp/xwatcher/xwatcher_current.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var lock = Xwatcher_util.makeLock(/* () */0);
2626
var events = Xwatcher_util.makeEventObj(/* () */0);
2727

2828
function exec() {
29-
return Xwatcher_util.buildWithShell("make -r -j5 check", events, lock, function () {
29+
return Xwatcher_util.buildWithShell("./watch-build.sh", events, lock, function () {
3030
return /* () */0;
3131
});
3232
}
@@ -50,7 +50,11 @@ Bs_array.iter(function (x) {
5050
"core",
5151
"syntax",
5252
"ext",
53-
"depends"
53+
"depends",
54+
"others",
55+
"ounit",
56+
"ounit_tests",
57+
"test"
5458
]);
5559

5660
exec(/* () */0);

Diff for: jscomp/xwatcher/xwatcher_current.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let jscomp =
2626

2727
let lock = Xwatcher_util.makeLock ()
2828
let events = Xwatcher_util.makeEventObj ()
29-
let command = "make -r -j5 check"
29+
let command = "./watch-build.sh"
3030
let exec () =
3131
buildWithShell command events lock (fun [@bs] () -> ())
3232
let watch dir =
@@ -43,7 +43,7 @@ let () =
4343
Node.Process.putEnvVar "BS_VSCODE" "1";
4444
Bs.Array.iter (fun [@bs] x ->
4545
ignore @@ watch (Node.Path.join [|jscomp; x|])
46-
) [| "core"; "syntax"; "ext"; "depends"; "others"|];
46+
) [| "core"; "syntax"; "ext"; "depends"; "others"; "ounit"; "ounit_tests"; "test"|];
4747
(* watch jscomp_core ; *)
4848
exec ()
4949

Diff for: lib/js/bs_array.js

+35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var List = require("./list.js");
34

45
function filterInPlace(p, a) {
56
var i = 0;
@@ -37,9 +38,43 @@ function iter(f, xs) {
3738
return /* () */0;
3839
}
3940

41+
function ofList(xs) {
42+
if (xs) {
43+
var a = new Array(List.length(xs));
44+
var _i = 0;
45+
var _param = xs;
46+
while(true) {
47+
var param = _param;
48+
var i = _i;
49+
if (param) {
50+
a[i] = param[0];
51+
_param = param[1];
52+
_i = i + 1 | 0;
53+
continue ;
54+
55+
} else {
56+
return a;
57+
}
58+
};
59+
} else {
60+
return /* array */[];
61+
}
62+
}
63+
64+
function map(f, a) {
65+
var l = a.length;
66+
var r = new Array(l);
67+
for(var i = 0 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
68+
r[i] = f(a[i]);
69+
}
70+
return r;
71+
}
72+
4073
exports.filterInPlace = filterInPlace;
4174
exports.empty = empty;
4275
exports.pushBack = pushBack;
4376
exports.memByRef = memByRef;
4477
exports.iter = iter;
78+
exports.ofList = ofList;
79+
exports.map = map;
4580
/* No side effect */

Diff for: lib/js/bs_option.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function getExn(x) {
2525
if (x) {
2626
return x[0];
2727
} else {
28-
var str = " " + (String("File \"bs_option.ml\", line 39, characters 34-42") + ": Bs.Option.unsafeGet");
29-
throw new Error(str);
28+
throw new Error("Bs_option.getExn");
3029
}
3130
}
3231

0 commit comments

Comments
 (0)