Skip to content

Commit 91f8c1a

Browse files
author
Hongbo Zhang
committed
fix windows build #543
1 parent e9fec2d commit 91f8c1a

9 files changed

+171
-465
lines changed

jscomp/common/js_config.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ let int32 = "Caml_int32"
246246
let block = "Block"
247247
let js_primitive = "Js_primitive"
248248
let module_ = "Caml_module"
249-
let version = "0.8.4"
249+
let version = "0.8.5"
250250

251251

252252
let runtime_set =
@@ -305,3 +305,8 @@ let no_any_assert = ref false
305305
let set_no_any_assert () = no_any_assert := true
306306
let get_no_any_assert () = !no_any_assert
307307

308+
let is_windows =
309+
match Sys.os_type with
310+
| "Win32"
311+
| "Cygwin"-> true
312+
| _ -> false

jscomp/common/js_config.mli

+1
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ val is_same_file : unit -> bool
162162

163163
val tool_name : string
164164

165+
val is_windows : bool

jscomp/ext/ext_filename.ml

+5
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,8 @@ let find_package_json_dir cwd =
233233
aux cwd
234234

235235
let package_dir = lazy (find_package_json_dir (Lazy.force cwd))
236+
237+
let replace_backward_slash (x : string)=
238+
String.map (function
239+
|'\\'-> '/'
240+
| x -> x) x

jscomp/ext/ext_filename.mli

+2
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ val resolve_bs_package : cwd:string -> string -> string
6161

6262
val cwd : string Lazy.t
6363
val package_dir : string Lazy.t
64+
65+
val replace_backward_slash : string -> string

jscomp/js_program_loader.ml

+70-66
Original file line numberDiff line numberDiff line change
@@ -68,75 +68,79 @@ module S = Js_stmt_make
6868

6969
let (//) = Filename.concat
7070

71-
let string_of_module_id (module_system : Lam_module_ident.system)
71+
let string_of_module_id
72+
(module_system : Lam_module_ident.system)
7273
(x : Lam_module_ident.t) : string =
73-
match x.kind with
74-
| Runtime
75-
| Ml ->
76-
let id = x.id in
77-
let file = Printf.sprintf "%s.js" id.name in
78-
let modulename = String.uncapitalize id.name in
79-
let rebase dep =
80-
Ext_filename.node_relative_path
81-
(`Dir (Js_config.get_output_dir module_system !Location.input_name)) dep
82-
in
83-
let dependency_pkg_info =
84-
Lam_compile_env.get_package_path_from_cmj module_system x
85-
in
86-
let current_pkg_info =
87-
Js_config.get_current_package_name_and_path module_system
88-
in
89-
begin match module_system, dependency_pkg_info, current_pkg_info with
90-
| _, `NotFound , _ ->
91-
Ext_pervasives.failwithf ~loc:__LOC__
92-
" @[%s not found in search path - while compiling %s @] "
93-
file !Location.input_name
94-
| `Goog , `Found (package_name, x), _ ->
95-
package_name ^ "." ^ String.uncapitalize id.name
96-
| `Goog, (`Empty | `Package_script _), _
97-
->
98-
Ext_pervasives.failwithf ~loc:__LOC__
99-
" @[%s was not compiled with goog support in search path - while compiling %s @] "
100-
file !Location.input_name
101-
| (`AmdJS | `NodeJS),
102-
( `Empty | `Package_script _) ,
103-
`Found _ ->
104-
Ext_pervasives.failwithf ~loc:__LOC__
105-
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
106-
file !Location.input_name
107-
| _ , _, `NotFound -> assert false
108-
| (`AmdJS | `NodeJS),
109-
`Found(package_name, x),
110-
`Found(current_package, path) ->
111-
if current_package = package_name then
112-
rebase (`File (
113-
Lazy.force Ext_filename.package_dir // x // modulename))
114-
else
115-
package_name // x // modulename
116-
| (`AmdJS | `NodeJS), `Found(package_name, x),
117-
`Package_script(current_package)
118-
->
119-
if current_package = package_name then
120-
rebase (`File (
121-
Lazy.force Ext_filename.package_dir // x // modulename))
122-
else
123-
package_name // x // modulename
124-
| (`AmdJS | `NodeJS), `Found(package_name, x), `Empty
125-
-> package_name // x // modulename
126-
| (`AmdJS | `NodeJS),
127-
(`Empty | `Package_script _) ,
128-
(`Empty | `Package_script _)
129-
->
130-
begin match Config_util.find file with
131-
| file ->
132-
rebase (`File file)
133-
| exception Not_found ->
74+
let result =
75+
match x.kind with
76+
| Runtime
77+
| Ml ->
78+
let id = x.id in
79+
let file = Printf.sprintf "%s.js" id.name in
80+
let modulename = String.uncapitalize id.name in
81+
let rebase dep =
82+
Ext_filename.node_relative_path
83+
(`Dir (Js_config.get_output_dir module_system !Location.input_name)) dep
84+
in
85+
let dependency_pkg_info =
86+
Lam_compile_env.get_package_path_from_cmj module_system x
87+
in
88+
let current_pkg_info =
89+
Js_config.get_current_package_name_and_path module_system
90+
in
91+
begin match module_system, dependency_pkg_info, current_pkg_info with
92+
| _, `NotFound , _ ->
13493
Ext_pervasives.failwithf ~loc:__LOC__
135-
"@[%s was not found in search path - while compiling %s @] "
94+
" @[%s not found in search path - while compiling %s @] "
13695
file !Location.input_name
137-
end
138-
end
139-
| External name -> name
96+
| `Goog , `Found (package_name, x), _ ->
97+
package_name ^ "." ^ String.uncapitalize id.name
98+
| `Goog, (`Empty | `Package_script _), _
99+
->
100+
Ext_pervasives.failwithf ~loc:__LOC__
101+
" @[%s was not compiled with goog support in search path - while compiling %s @] "
102+
file !Location.input_name
103+
| (`AmdJS | `NodeJS),
104+
( `Empty | `Package_script _) ,
105+
`Found _ ->
106+
Ext_pervasives.failwithf ~loc:__LOC__
107+
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
108+
file !Location.input_name
109+
| _ , _, `NotFound -> assert false
110+
| (`AmdJS | `NodeJS),
111+
`Found(package_name, x),
112+
`Found(current_package, path) ->
113+
if current_package = package_name then
114+
rebase (`File (
115+
Lazy.force Ext_filename.package_dir // x // modulename))
116+
else
117+
package_name // x // modulename
118+
| (`AmdJS | `NodeJS), `Found(package_name, x),
119+
`Package_script(current_package)
120+
->
121+
if current_package = package_name then
122+
rebase (`File (
123+
Lazy.force Ext_filename.package_dir // x // modulename))
124+
else
125+
package_name // x // modulename
126+
| (`AmdJS | `NodeJS), `Found(package_name, x), `Empty
127+
-> package_name // x // modulename
128+
| (`AmdJS | `NodeJS),
129+
(`Empty | `Package_script _) ,
130+
(`Empty | `Package_script _)
131+
->
132+
begin match Config_util.find file with
133+
| file ->
134+
rebase (`File file)
135+
| exception Not_found ->
136+
Ext_pervasives.failwithf ~loc:__LOC__
137+
"@[%s was not found in search path - while compiling %s @] "
138+
file !Location.input_name
139+
end
140+
end
141+
| External name -> name in
142+
if Js_config.is_windows then Ext_filename.replace_backward_slash result
143+
else result
140144

141145

142146

jscomp/test/Makefile

+56-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,64 @@ CAMLC=../bin/bsc
44

55
INCLUDES= -I ../stdlib -I ../runtime -I ../others/
66

7-
SOURCE_LIST := $(shell cat test.mllib)
7+
OTHERS := a test_ari test_export2 test_internalOO test_obj_simple_ffi test_scope \
8+
test_switch arith_lexer test_array test_external test_is_js test_order \
9+
test_trywith arith_parser test_array_primitive test_js_ffi test_pack \
10+
test_seq test_u arith_syntax test_bug test_ffi test_let test_per\
11+
test_set unitest_string b test_bytes test_fib test_list test_pervasive simple_lexer_test\
12+
demo_binding demo test_char test_generative_module test_literal test_primitive test_simple_obj\
13+
empty_obj fib test_common test_include map_find_test test_react test_small\
14+
number_lexer test_demo inline_map_test test_nat64 test_react_case test_string\
15+
qcc test_exception inline_map2_test test_obj test_runtime_encoding test_string_case\
16+
buffer_test test_format test_simple_include test_exception_escape test_simple_pattern_match\
17+
test_nested_let test_tuple_destructring test_string_switch test_pervasives2\
18+
test_pervasives3 test_non_export test_const_elim test_int_map_find test_for_map\
19+
test_string_map bdd test_simple_tailcall test_bool_equal test_match_exception\
20+
test_sprintf test_functor_dead_code test_global_print test_side_effect_functor\
21+
test_static_catch_ident test_order_tailcall test_google_closure test_dup_param\
22+
test_simple_ref test_incr_ref ocaml_array ticker test_filename test_alias mt\
23+
mock_mt array_test test_nullary test_for_map2 int_map test_tuple\
24+
list_test map_test lexer_test google_closure_test boolean_test equal_exception_test\
25+
lazy_test ext_string ext_bytes a_string_test ext_filename a_filename_test test_nested_print\
26+
a_scope_bug a_recursive_type test_array_append ext_list a_list_test test_type_based_arity\
27+
abstract_type curry test_formatter test_cps test_closure test_for_loop test_while_closure\
28+
test_while_side_effect for_side_effect_test cps_test for_loop_test queue_test libqueue_test\
29+
libarg_test loop_suites_test const_block_test stack_test test_stack\
30+
complex_while_loop hashtbl_test int_hashtbl_test cont_int_fold_test test_incomplete\
31+
test_ramification string_test rec_value_test test_string_const string_runtime_test\
32+
of_string_test tailcall_inline_test obj_test demo_page complex_test inline_edge_cases\
33+
inline_regression_test primitive_reg_test test_eq equal_test typeof_test lib_js_test\
34+
small_inline_test ari_regress_test record_with_test complex_if_test module_parameter_test\
35+
regression_print global_exception_regression_test printf_test format_regression loop_regression_test\
36+
and_or_tailcall_test const_defs const_defs_test genlex_test cross_module_inline_test runtime_encoding_test\
37+
obj_magic_test caml_compare_test rec_module_test guide_for_ext local_exception_test js_obj_test extensible_variant_test\
38+
ext_log lam_current_unit test_zero_nullable int64_test string_literal_print_test js_bool_test class_type_ffi_test unsafe_ppx_test\
39+
js_date js_date_test es6_module_test int_overflow_test float_test bigarray_test float_of_bits_test swap_test int64_mul_div_test\
40+
ffi_test shift_test debugger_test caml_format_test js_val epsilon_test io_test random_test ffi_js\
41+
stringmatch_test printf_sim test_external_unit ext_array int32_test hamming_test pr_regression_test\
42+
to_string_test print_alpha_test ffi_arity_test digest_test string_get_set_test exception_raise_test\
43+
class_test debug_keep_test demo_int_map const_test class3_test class4_test class5_test class6_test\
44+
class7_test class8_test class_repr pq_test mt_global event_ffi hash_test exception_value_test sprintf_reg_test\
45+
scanf_test testing tscanf_test scanf_reference_error_regression_test sprintf_reg_test scanf_io fail_comp\
46+
stack_comp_test float_array float_record tfloat_record_test basic_module_test offset\
47+
pr6726 undef_regression_test tuple_alloc test_unsupported_primitive module_alias ext_pervasives\
48+
test_const_propogate limits_test ext_sys test_unsafe_obj_ffi module_missing_conversion\
49+
ocaml_proto_test test_unsafe_obj_ffi_ppx ppx_apply_test test_http_server\
50+
http_types ignore_test test_index obj_literal_ppx_test obj_literal_ppx\
51+
gpr_405_test attr_test uncurry_glob_test nested_obj_test nested_obj_literal\
52+
method_name_test format_test config1_test config2_test largest_int_flow\
53+
noassert test_unsafe_cmp gpr_441 gpr_459_test promise chain_code_test\
54+
method_chain recursive_module recursive_module_test simplify_lambda_632o\
55+
div_by_zero_test unsafe_this obj_type_test polymorphism_test class_error_message\
56+
test_bs_this class_setter_getter gpr496_test local_class_type test_regex ffi_array_test\
57+
derive_dyntype derive_type_test nested_include simple_derive_test simple_derive_use\
58+
mutual_non_recursive_type external_ppx optional_ffi_test poly_variant_test
59+
60+
SOURCE_LIST := js_dyn $(OTHERS)
861
TESTS := $(addsuffix .cmj, $(SOURCE_LIST) )
962
## since we use ppx
10-
$(addsuffix .cmi, $(SOURCE_LIST)): ../runtime/js.cmi
11-
63+
$(addsuffix .cmi, $(OTHERS)): ../runtime/js.cmi js_dyn.cmi
64+
$(addsuffix .cmj, $(OTHERS)): ../runtime/js.cmj js_dyn.cmj
1265

1366
COMPFLAGS+= $(MODULE_FLAGS) -w -40
1467
COMPFLAGS+= -bs-no-version-header -bs-diagnose -bs-cross-module-opt -bs-package-name $(npm_package_name)

jscomp/test/ext_filename.js

+30-18
Original file line numberDiff line numberDiff line change
@@ -351,26 +351,38 @@ var package_dir = Block.__(246, [function () {
351351
));
352352
}]);
353353

354+
function replace_backward_slash(x) {
355+
return $$String.map(function (x) {
356+
if (x !== 92) {
357+
return x;
358+
}
359+
else {
360+
return /* "/" */47;
361+
}
362+
}, x);
363+
}
364+
354365
var $slash$slash = Filename.concat;
355366

356367
var node_modules_length = 12;
357368

358-
exports.node_sep = node_sep;
359-
exports.node_parent = node_parent;
360-
exports.node_current = node_current;
361-
exports.cwd = cwd;
362-
exports.$slash$slash = $slash$slash;
363-
exports.combine = combine;
364-
exports.path_as_directory = path_as_directory;
365-
exports.absolute_path = absolute_path;
366-
exports.chop_extension = chop_extension;
367-
exports.try_chop_extension = try_chop_extension;
368-
exports.relative_path = relative_path;
369-
exports.node_modules = node_modules;
370-
exports.node_modules_length = node_modules_length;
371-
exports.package_json = package_json;
372-
exports.node_relative_path = node_relative_path;
373-
exports.resolve_bs_package = resolve_bs_package;
374-
exports.find_package_json_dir = find_package_json_dir;
375-
exports.package_dir = package_dir;
369+
exports.node_sep = node_sep;
370+
exports.node_parent = node_parent;
371+
exports.node_current = node_current;
372+
exports.cwd = cwd;
373+
exports.$slash$slash = $slash$slash;
374+
exports.combine = combine;
375+
exports.path_as_directory = path_as_directory;
376+
exports.absolute_path = absolute_path;
377+
exports.chop_extension = chop_extension;
378+
exports.try_chop_extension = try_chop_extension;
379+
exports.relative_path = relative_path;
380+
exports.node_modules = node_modules;
381+
exports.node_modules_length = node_modules_length;
382+
exports.package_json = package_json;
383+
exports.node_relative_path = node_relative_path;
384+
exports.resolve_bs_package = resolve_bs_package;
385+
exports.find_package_json_dir = find_package_json_dir;
386+
exports.package_dir = package_dir;
387+
exports.replace_backward_slash = replace_backward_slash;
376388
/* Filename Not a pure module */

0 commit comments

Comments
 (0)