Skip to content

Commit

Permalink
tentative fix for #3709
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Jul 30, 2019
1 parent 67a629f commit acf9c7b
Show file tree
Hide file tree
Showing 11 changed files with 14,865 additions and 14,859 deletions.
5 changes: 3 additions & 2 deletions jscomp/bsb/bsb_build_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ let (//) = Ext_path.combine


(*TODO: optimize *)
let ppx_flags xs =
let ppx_flags (xs : Bsb_config_types.ppx list) =
flag_concat "-ppx"
(Ext_list.map xs Filename.quote)
(Ext_list.map xs
(fun x -> if x.args = [] then Filename.quote x.name else assert false))

let pp_flag (xs : string) =
"-pp " ^ Filename.quote xs
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_build_util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Use:
ppx_flags [ppxs]
]}
*)
val ppx_flags : string list -> string
val ppx_flags : Bsb_config_types.ppx list -> string

val pp_flag : string -> string

Expand Down
17 changes: 14 additions & 3 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ let extract_string_list (map : json_map) (field : string) : string list =
Bsb_exception.config_error config (field ^ " expect an array")


let extract_ppx (map : json_map) (cwd : string) =
let args = extract_string_list map Bsb_build_schemas.ppx_flags in

Ext_list.map_split_opt args (fun p ->
if p = "" then Bsb_exception.invalid_spec "invalid ppx, empty string found"
else
let result =
Bsb_build_util.resolve_bsb_magic_file ~cwd ~desc:Bsb_build_schemas.ppx_flags p
in
let some_file = Some result.path in
some_file, if result.checked then some_file else None
)

let extract_js_post_build (map : json_map) cwd : string option =
let js_post_build_cmd = ref None in
Expand Down Expand Up @@ -395,7 +407,7 @@ let interpret_json
extract_dependencies map cwd Bsb_build_schemas.bs_dev_dependencies
else [] in
let args = extract_string_list map Bsb_build_schemas.ppx_flags in
let ppx_files, ppx_checked_files =
let ppx_files, _ =
Ext_list.map_split_opt args (fun p ->
if p = "" then Bsb_exception.invalid_spec "invalid ppx, empty string found"
else
Expand Down Expand Up @@ -426,8 +438,7 @@ let interpret_json
warning = extract_warning map;
external_includes = extract_string_list map Bsb_build_schemas.bs_external_includes;
bsc_flags = extract_string_list map Bsb_build_schemas.bsc_flags ;
ppx_files ;
ppx_checked_files ;
ppx_files = Ext_list.map ppx_files (fun x -> {Bsb_config_types.name = x; args = []});
pp_file = pp_flags ;
bs_dependencies ;
bs_dev_dependencies ;
Expand Down
8 changes: 6 additions & 2 deletions jscomp/bsb/bsb_config_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type gentype_config = {
path : string (* resolved *)
}
type command = string

type ppx = {
name : string;
args : string list
}
type t =
{
package_name : string ;
Expand All @@ -56,8 +61,7 @@ type t =
(* CapitalPackage *)
external_includes : string list ;
bsc_flags : string list ;
ppx_files : string list ;
ppx_checked_files : string list ;
ppx_files : ppx list ;
pp_file : string option;
bs_dependencies : dependencies;
bs_dev_dependencies : dependencies;
Expand Down
13 changes: 11 additions & 2 deletions jscomp/bsb/bsb_merlin_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ let merlin_file_gen ~cwd
if generate_merlin then begin
let buffer = Buffer.create 1024 in
output_merlin_namespace buffer namespace;
Ext_list.iter ppx_files (fun x ->
Buffer.add_string buffer (merlin_flg_ppx ^ x )
Ext_list.iter ppx_files (fun ppx ->
Buffer.add_string buffer merlin_flg_ppx;
if ppx.args = [] then
Buffer.add_string buffer ppx.name
else
let fmt : _ format =
if Ext_sys.is_windows_or_cygwin then
"\"%s %s\""
else "'%s %s'" in
Buffer.add_string buffer
(Printf.sprintf fmt ppx.name (String.concat " " ppx.args))
);
Ext_option.iter pp_file (fun x ->
Buffer.add_string buffer (merlin_flg_pp ^ x)
Expand Down
14 changes: 1 addition & 13 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ let emit_impl_build
(package_specs : Bsb_package_specs.t)
(group_dir_index : Bsb_dir_index.t)
oc
~has_checked_ppx
~bs_suffix
~(no_intf_file : bool)
js_post_build_cmd
Expand Down Expand Up @@ -112,13 +111,10 @@ let emit_impl_build
let common_shadows =
make_common_shadows package_specs
(Filename.dirname output_cmi)
group_dir_index in
let implicit_deps = (if has_checked_ppx then [ "$ppx_checked_files" ] else []) in

group_dir_index in
Bsb_ninja_util.output_build oc
~output:output_mlast
~input
~implicit_deps
~rule:( if is_re then
rules.build_ast_and_module_sets_from_re
else
Expand All @@ -134,7 +130,6 @@ let emit_impl_build
else filename_sans_extension ^ Literals.suffix_mli))
~rule:(if is_re then rules.build_ast_and_module_sets_from_rei
else rules.build_ast_and_module_sets)
~implicit_deps
;
Bsb_ninja_util.output_build oc
~output:output_cmi
Expand All @@ -155,7 +150,6 @@ let emit_impl_build
~inputs:(if not no_intf_file then [output_mliast] else [])
~input:output_mlast
~rule:rules.build_bin_deps
~implicit_deps
?shadows:(if Bsb_dir_index.is_lib_dir group_dir_index then None
else Some [{Bsb_ninja_util.key = Bsb_build_schemas.bsb_dir_group ;
op =
Expand Down Expand Up @@ -200,7 +194,6 @@ let handle_module_info
(group_dir_index : Bsb_dir_index.t)
(package_specs : Bsb_package_specs.t)
js_post_build_cmd
~has_checked_ppx
~bs_suffix
oc module_name
( {name_sans_extension = input} as module_info : Bsb_db.module_info)
Expand All @@ -210,7 +203,6 @@ let handle_module_info
package_specs
group_dir_index
oc
~has_checked_ppx
~bs_suffix
~no_intf_file:(module_info.mli_info = Mli_empty)
~is_re:module_info.is_re
Expand All @@ -222,7 +214,6 @@ let handle_module_info

let handle_file_group
oc
~(has_checked_ppx : bool)
~bs_suffix
~(rules : Bsb_ninja_rule.builtin)
~package_specs
Expand All @@ -243,7 +234,6 @@ let handle_file_group
if installable then
String_hash_set.add files_to_install (Bsb_db.filename_sans_suffix_of_module_info module_info);
(handle_module_info rules
~has_checked_ppx
~bs_suffix
group.dir_index
package_specs js_post_build_cmd
Expand All @@ -257,7 +247,6 @@ let handle_file_group

let handle_file_groups
oc
~has_checked_ppx
~package_specs
~bs_suffix
~js_post_build_cmd
Expand All @@ -268,7 +257,6 @@ let handle_file_groups
Ext_list.iter file_groups
(handle_file_group
oc
~has_checked_ppx
~bs_suffix ~package_specs ~rules ~js_post_build_cmd
files_to_install
namespace
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_ninja_file_groups.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

val handle_file_groups :
out_channel ->
has_checked_ppx:bool ->
package_specs:Bsb_package_specs.t ->
bs_suffix:bool ->
js_post_build_cmd:string option ->
Expand Down
14 changes: 2 additions & 12 deletions jscomp/bsb/bsb_ninja_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let output_ninja_and_namespace_map
bsc_flags ;
pp_file;
ppx_files ;
ppx_checked_files;
bs_dependencies;
bs_dev_dependencies;
refmt;
Expand Down Expand Up @@ -155,16 +155,7 @@ let output_ninja_and_namespace_map
(Ext_filename.maybe_quote x.package_install_path) oc
)
;
(*
TODO:
see https://github.com/ninja-build/ninja/issues/1375
*)
(match ppx_checked_files with
| first_ppx_checked_file :: _ ->
Bsb_ninja_util.output_kv Bsb_ninja_global_vars.ppx_checked_files
first_ppx_checked_file oc
| [] -> ())
;


Bsb_ninja_util.output_kvs
[|
Expand Down Expand Up @@ -254,7 +245,6 @@ let output_ninja_and_namespace_map
~rule:rules.copy_resources);
(** Generate build statement for each file *)
Bsb_ninja_file_groups.handle_file_groups oc
~has_checked_ppx:(ppx_checked_files <> [])
~bs_suffix
~rules
~js_post_build_cmd
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_ninja_global_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let bsdep = "bsdep"
let bsc_flags = "bsc_flags"

let ppx_flags = "ppx_flags"
let ppx_checked_files = "ppx_checked_files"

let pp_flags = "pp_flags"


Expand Down
Loading

0 comments on commit acf9c7b

Please sign in to comment.