Skip to content

Commit

Permalink
fix windows build #543
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed Jul 21, 2016
1 parent e9fec2d commit 91f8c1a
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 465 deletions.
7 changes: 6 additions & 1 deletion jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let int32 = "Caml_int32"
let block = "Block"
let js_primitive = "Js_primitive"
let module_ = "Caml_module"
let version = "0.8.4"
let version = "0.8.5"


let runtime_set =
Expand Down Expand Up @@ -305,3 +305,8 @@ let no_any_assert = ref false
let set_no_any_assert () = no_any_assert := true
let get_no_any_assert () = !no_any_assert

let is_windows =
match Sys.os_type with
| "Win32"
| "Cygwin"-> true
| _ -> false
1 change: 1 addition & 0 deletions jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ val is_same_file : unit -> bool

val tool_name : string

val is_windows : bool
5 changes: 5 additions & 0 deletions jscomp/ext/ext_filename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,8 @@ let find_package_json_dir cwd =
aux cwd

let package_dir = lazy (find_package_json_dir (Lazy.force cwd))

let replace_backward_slash (x : string)=
String.map (function
|'\\'-> '/'
| x -> x) x
2 changes: 2 additions & 0 deletions jscomp/ext/ext_filename.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ val resolve_bs_package : cwd:string -> string -> string

val cwd : string Lazy.t
val package_dir : string Lazy.t

val replace_backward_slash : string -> string
136 changes: 70 additions & 66 deletions jscomp/js_program_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,75 +68,79 @@ module S = Js_stmt_make

let (//) = Filename.concat

let string_of_module_id (module_system : Lam_module_ident.system)
let string_of_module_id
(module_system : Lam_module_ident.system)
(x : Lam_module_ident.t) : string =
match x.kind with
| Runtime
| Ml ->
let id = x.id in
let file = Printf.sprintf "%s.js" id.name in
let modulename = String.uncapitalize id.name in
let rebase dep =
Ext_filename.node_relative_path
(`Dir (Js_config.get_output_dir module_system !Location.input_name)) dep
in
let dependency_pkg_info =
Lam_compile_env.get_package_path_from_cmj module_system x
in
let current_pkg_info =
Js_config.get_current_package_name_and_path module_system
in
begin match module_system, dependency_pkg_info, current_pkg_info with
| _, `NotFound , _ ->
Ext_pervasives.failwithf ~loc:__LOC__
" @[%s not found in search path - while compiling %s @] "
file !Location.input_name
| `Goog , `Found (package_name, x), _ ->
package_name ^ "." ^ String.uncapitalize id.name
| `Goog, (`Empty | `Package_script _), _
->
Ext_pervasives.failwithf ~loc:__LOC__
" @[%s was not compiled with goog support in search path - while compiling %s @] "
file !Location.input_name
| (`AmdJS | `NodeJS),
( `Empty | `Package_script _) ,
`Found _ ->
Ext_pervasives.failwithf ~loc:__LOC__
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
file !Location.input_name
| _ , _, `NotFound -> assert false
| (`AmdJS | `NodeJS),
`Found(package_name, x),
`Found(current_package, path) ->
if current_package = package_name then
rebase (`File (
Lazy.force Ext_filename.package_dir // x // modulename))
else
package_name // x // modulename
| (`AmdJS | `NodeJS), `Found(package_name, x),
`Package_script(current_package)
->
if current_package = package_name then
rebase (`File (
Lazy.force Ext_filename.package_dir // x // modulename))
else
package_name // x // modulename
| (`AmdJS | `NodeJS), `Found(package_name, x), `Empty
-> package_name // x // modulename
| (`AmdJS | `NodeJS),
(`Empty | `Package_script _) ,
(`Empty | `Package_script _)
->
begin match Config_util.find file with
| file ->
rebase (`File file)
| exception Not_found ->
let result =
match x.kind with
| Runtime
| Ml ->
let id = x.id in
let file = Printf.sprintf "%s.js" id.name in
let modulename = String.uncapitalize id.name in
let rebase dep =
Ext_filename.node_relative_path
(`Dir (Js_config.get_output_dir module_system !Location.input_name)) dep
in
let dependency_pkg_info =
Lam_compile_env.get_package_path_from_cmj module_system x
in
let current_pkg_info =
Js_config.get_current_package_name_and_path module_system
in
begin match module_system, dependency_pkg_info, current_pkg_info with
| _, `NotFound , _ ->
Ext_pervasives.failwithf ~loc:__LOC__
"@[%s was not found in search path - while compiling %s @] "
" @[%s not found in search path - while compiling %s @] "
file !Location.input_name
end
end
| External name -> name
| `Goog , `Found (package_name, x), _ ->
package_name ^ "." ^ String.uncapitalize id.name
| `Goog, (`Empty | `Package_script _), _
->
Ext_pervasives.failwithf ~loc:__LOC__
" @[%s was not compiled with goog support in search path - while compiling %s @] "
file !Location.input_name
| (`AmdJS | `NodeJS),
( `Empty | `Package_script _) ,
`Found _ ->
Ext_pervasives.failwithf ~loc:__LOC__
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
file !Location.input_name
| _ , _, `NotFound -> assert false
| (`AmdJS | `NodeJS),
`Found(package_name, x),
`Found(current_package, path) ->
if current_package = package_name then
rebase (`File (
Lazy.force Ext_filename.package_dir // x // modulename))
else
package_name // x // modulename
| (`AmdJS | `NodeJS), `Found(package_name, x),
`Package_script(current_package)
->
if current_package = package_name then
rebase (`File (
Lazy.force Ext_filename.package_dir // x // modulename))
else
package_name // x // modulename
| (`AmdJS | `NodeJS), `Found(package_name, x), `Empty
-> package_name // x // modulename
| (`AmdJS | `NodeJS),
(`Empty | `Package_script _) ,
(`Empty | `Package_script _)
->
begin match Config_util.find file with
| file ->
rebase (`File file)
| exception Not_found ->
Ext_pervasives.failwithf ~loc:__LOC__
"@[%s was not found in search path - while compiling %s @] "
file !Location.input_name
end
end
| External name -> name in
if Js_config.is_windows then Ext_filename.replace_backward_slash result
else result



Expand Down
59 changes: 56 additions & 3 deletions jscomp/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,64 @@ CAMLC=../bin/bsc

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

SOURCE_LIST := $(shell cat test.mllib)
OTHERS := a test_ari test_export2 test_internalOO test_obj_simple_ffi test_scope \
test_switch arith_lexer test_array test_external test_is_js test_order \
test_trywith arith_parser test_array_primitive test_js_ffi test_pack \
test_seq test_u arith_syntax test_bug test_ffi test_let test_per\
test_set unitest_string b test_bytes test_fib test_list test_pervasive simple_lexer_test\
demo_binding demo test_char test_generative_module test_literal test_primitive test_simple_obj\
empty_obj fib test_common test_include map_find_test test_react test_small\
number_lexer test_demo inline_map_test test_nat64 test_react_case test_string\
qcc test_exception inline_map2_test test_obj test_runtime_encoding test_string_case\
buffer_test test_format test_simple_include test_exception_escape test_simple_pattern_match\
test_nested_let test_tuple_destructring test_string_switch test_pervasives2\
test_pervasives3 test_non_export test_const_elim test_int_map_find test_for_map\
test_string_map bdd test_simple_tailcall test_bool_equal test_match_exception\
test_sprintf test_functor_dead_code test_global_print test_side_effect_functor\
test_static_catch_ident test_order_tailcall test_google_closure test_dup_param\
test_simple_ref test_incr_ref ocaml_array ticker test_filename test_alias mt\
mock_mt array_test test_nullary test_for_map2 int_map test_tuple\
list_test map_test lexer_test google_closure_test boolean_test equal_exception_test\
lazy_test ext_string ext_bytes a_string_test ext_filename a_filename_test test_nested_print\
a_scope_bug a_recursive_type test_array_append ext_list a_list_test test_type_based_arity\
abstract_type curry test_formatter test_cps test_closure test_for_loop test_while_closure\
test_while_side_effect for_side_effect_test cps_test for_loop_test queue_test libqueue_test\
libarg_test loop_suites_test const_block_test stack_test test_stack\
complex_while_loop hashtbl_test int_hashtbl_test cont_int_fold_test test_incomplete\
test_ramification string_test rec_value_test test_string_const string_runtime_test\
of_string_test tailcall_inline_test obj_test demo_page complex_test inline_edge_cases\
inline_regression_test primitive_reg_test test_eq equal_test typeof_test lib_js_test\
small_inline_test ari_regress_test record_with_test complex_if_test module_parameter_test\
regression_print global_exception_regression_test printf_test format_regression loop_regression_test\
and_or_tailcall_test const_defs const_defs_test genlex_test cross_module_inline_test runtime_encoding_test\
obj_magic_test caml_compare_test rec_module_test guide_for_ext local_exception_test js_obj_test extensible_variant_test\
ext_log lam_current_unit test_zero_nullable int64_test string_literal_print_test js_bool_test class_type_ffi_test unsafe_ppx_test\
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\
ffi_test shift_test debugger_test caml_format_test js_val epsilon_test io_test random_test ffi_js\
stringmatch_test printf_sim test_external_unit ext_array int32_test hamming_test pr_regression_test\
to_string_test print_alpha_test ffi_arity_test digest_test string_get_set_test exception_raise_test\
class_test debug_keep_test demo_int_map const_test class3_test class4_test class5_test class6_test\
class7_test class8_test class_repr pq_test mt_global event_ffi hash_test exception_value_test sprintf_reg_test\
scanf_test testing tscanf_test scanf_reference_error_regression_test sprintf_reg_test scanf_io fail_comp\
stack_comp_test float_array float_record tfloat_record_test basic_module_test offset\
pr6726 undef_regression_test tuple_alloc test_unsupported_primitive module_alias ext_pervasives\
test_const_propogate limits_test ext_sys test_unsafe_obj_ffi module_missing_conversion\
ocaml_proto_test test_unsafe_obj_ffi_ppx ppx_apply_test test_http_server\
http_types ignore_test test_index obj_literal_ppx_test obj_literal_ppx\
gpr_405_test attr_test uncurry_glob_test nested_obj_test nested_obj_literal\
method_name_test format_test config1_test config2_test largest_int_flow\
noassert test_unsafe_cmp gpr_441 gpr_459_test promise chain_code_test\
method_chain recursive_module recursive_module_test simplify_lambda_632o\
div_by_zero_test unsafe_this obj_type_test polymorphism_test class_error_message\
test_bs_this class_setter_getter gpr496_test local_class_type test_regex ffi_array_test\
derive_dyntype derive_type_test nested_include simple_derive_test simple_derive_use\
mutual_non_recursive_type external_ppx optional_ffi_test poly_variant_test

SOURCE_LIST := js_dyn $(OTHERS)
TESTS := $(addsuffix .cmj, $(SOURCE_LIST) )
## since we use ppx
$(addsuffix .cmi, $(SOURCE_LIST)): ../runtime/js.cmi

$(addsuffix .cmi, $(OTHERS)): ../runtime/js.cmi js_dyn.cmi
$(addsuffix .cmj, $(OTHERS)): ../runtime/js.cmj js_dyn.cmj

COMPFLAGS+= $(MODULE_FLAGS) -w -40
COMPFLAGS+= -bs-no-version-header -bs-diagnose -bs-cross-module-opt -bs-package-name $(npm_package_name)
Expand Down
48 changes: 30 additions & 18 deletions jscomp/test/ext_filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,26 +351,38 @@ var package_dir = Block.__(246, [function () {
));
}]);

function replace_backward_slash(x) {
return $$String.map(function (x) {
if (x !== 92) {
return x;
}
else {
return /* "/" */47;
}
}, x);
}

var $slash$slash = Filename.concat;

var node_modules_length = 12;

exports.node_sep = node_sep;
exports.node_parent = node_parent;
exports.node_current = node_current;
exports.cwd = cwd;
exports.$slash$slash = $slash$slash;
exports.combine = combine;
exports.path_as_directory = path_as_directory;
exports.absolute_path = absolute_path;
exports.chop_extension = chop_extension;
exports.try_chop_extension = try_chop_extension;
exports.relative_path = relative_path;
exports.node_modules = node_modules;
exports.node_modules_length = node_modules_length;
exports.package_json = package_json;
exports.node_relative_path = node_relative_path;
exports.resolve_bs_package = resolve_bs_package;
exports.find_package_json_dir = find_package_json_dir;
exports.package_dir = package_dir;
exports.node_sep = node_sep;
exports.node_parent = node_parent;
exports.node_current = node_current;
exports.cwd = cwd;
exports.$slash$slash = $slash$slash;
exports.combine = combine;
exports.path_as_directory = path_as_directory;
exports.absolute_path = absolute_path;
exports.chop_extension = chop_extension;
exports.try_chop_extension = try_chop_extension;
exports.relative_path = relative_path;
exports.node_modules = node_modules;
exports.node_modules_length = node_modules_length;
exports.package_json = package_json;
exports.node_relative_path = node_relative_path;
exports.resolve_bs_package = resolve_bs_package;
exports.find_package_json_dir = find_package_json_dir;
exports.package_dir = package_dir;
exports.replace_backward_slash = replace_backward_slash;
/* Filename Not a pure module */
Loading

0 comments on commit 91f8c1a

Please sign in to comment.