Skip to content

ppx-dev-flags support #3482 #3715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@
"$ref": "#/definitions/ppx-specs",
"description": "PPX macros to pass to compiler. The syntax is package_name/binary, for example: `reason/reactjs_jsx_ppx_3.native`. Currenly searches in `node_modules`"
},
"ppx-dev-flags": {
"$ref": "#/definitions/ppx-specs",
"description": "Similar to `ppx-flags`, but only applied to dev directories, which is only a dev dependency. PPX macros to pass to compiler. The syntax is package_name/binary, for example: `reason/reactjs_jsx_ppx_3.native`. Currenly searches in `node_modules`"
},
"pp-flags": {
"$ref": "#/definitions/pp-specs",
"description": "preprocessors to pass to compiler. The syntax is package_name/binary, for example: `pp/syntax.exe`. Currenly searches in `node_modules`"
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_build_schemas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let name = "name"
(* let ocaml_config = "ocaml-config" *)
let bsdep = "bsdep"
let ppx_flags = "ppx-flags"
let ppx_dev_flags = "ppx-dev-flags"
let pp_flags = "pp-flags"
let bsc = "bsc"
let refmt = "refmt"
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ let interpret_json
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 = extract_ppx map ~cwd Bsb_build_schemas.ppx_flags;
ppx_dev_files = extract_ppx map ~cwd Bsb_build_schemas.ppx_dev_flags;
pp_file = pp_flags ;
bs_dependencies ;
bs_dev_dependencies ;
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_config_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type t =
external_includes : string list ;
bsc_flags : string list ;
ppx_files : ppx list ;
ppx_dev_files : ppx list;
pp_file : string option;
bs_dependencies : dependencies;
bs_dev_dependencies : dependencies;
Expand Down
14 changes: 8 additions & 6 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ let emit_impl_build
make_common_shadows package_specs
(Filename.dirname output_cmi)
group_dir_index in
let ast_rule =
match is_dev, is_re with
| true, true -> rules.build_ast_from_re_dev
| false, true -> rules.build_ast_from_re
| true, false -> rules.build_ast_dev
| false, false -> rules.build_ast in
Bsb_ninja_util.output_build oc
~output:output_mlast
~input
~rule:( if is_re then
rules.build_ast_from_re
else
rules.build_ast);
~rule:ast_rule;
if not no_intf_file then begin
Bsb_ninja_util.output_build oc
~output:output_mliast
Expand All @@ -128,8 +131,7 @@ let emit_impl_build
~input:(Bsb_config.proj_rel
(if is_re then filename_sans_extension ^ Literals.suffix_rei
else filename_sans_extension ^ Literals.suffix_mli))
~rule:(if is_re then rules.build_ast_from_re
else rules.build_ast)
~rule:ast_rule
;
Bsb_ninja_util.output_build oc
~output:output_cmi
Expand Down
3 changes: 2 additions & 1 deletion 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_dev_files ;
bs_dependencies;
bs_dev_dependencies;
refmt;
Expand Down Expand Up @@ -226,6 +226,7 @@ let output_ninja_and_namespace_map
let digest = Bsb_db_encode.write_build_cache ~dir:cwd_lib_bs bs_groups in
let rules : Bsb_ninja_rule.builtin =
Bsb_ninja_rule.make_custom_rules
~has_dev_ppx:(ppx_dev_files <> [])
~has_gentype:(gentype_config <> None)
~has_postbuild:(js_post_build_cmd <> None)
~has_ppx:(ppx_files <> [])
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_ninja_global_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let bsdep = "bsdep"
let bsc_flags = "bsc_flags"

let ppx_flags = "ppx_flags"
let ppx_dev_flags = "ppx_dev_flags"

let pp_flags = "pp_flags"

Expand Down
57 changes: 48 additions & 9 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ type command = string

type builtin = {
build_ast : t;
(** TODO: Implement it on top of pp_flags *)
build_ast_dev : t;
build_ast_from_re : t ;
build_ast_from_re_dev : t;
(* build_ast_from_rei : t ; *)


Expand Down Expand Up @@ -113,6 +114,7 @@ let make_custom_rules
~(has_gentype : bool)
~(has_postbuild : bool)
~(has_ppx : bool)
~(has_dev_ppx : bool)
~(has_pp : bool)
~(has_builtin : bool)
~(bs_suffix : bool)
Expand Down Expand Up @@ -151,7 +153,7 @@ let make_custom_rules
Buffer.add_string buf " $postbuild";
Buffer.contents buf
in
let mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx : string =
let mk_ast ~has_pp ~has_ppx ~has_dev_ppx ~has_reason_react_jsx : string =
Buffer.clear buf ;
Buffer.add_string buf "$bsc $warnings -color always";
(match has_pp with
Expand All @@ -167,20 +169,55 @@ let make_custom_rules
| _, Some Jsx_v3
-> Buffer.add_string buf " -bs-jsx 3"
);
if has_ppx then
Buffer.add_string buf " $ppx_flags";
(match has_dev_ppx, has_ppx with
| true, _ ->
Buffer.add_string buf " $dev_ppx_flags"
| false, _ ->
if has_ppx then
Buffer.add_string buf " $ppx_flags"
);
Buffer.add_string buf " $bsc_flags -c -o $out -bs-syntax-only -bs-binary-ast $in";
Buffer.contents buf
in

let build_ast =
define
~command:(mk_ast ~has_pp:(if has_pp then `regular else `none) ~has_ppx ~has_reason_react_jsx:false )
"build_ast_and_module_sets" in
~command:(mk_ast
~has_pp:(if has_pp then `regular else `none)
~has_ppx
~has_dev_ppx:false
~has_reason_react_jsx:false )
"build_ast" in
let build_ast_dev =
if has_dev_ppx then
define
~command:(mk_ast
~has_pp:(if has_pp then `regular else `none)
~has_ppx
~has_dev_ppx:true
~has_reason_react_jsx:false )
"build_ast_dev"
else build_ast in
let build_ast_from_re =
define
~command:(mk_ast ~has_pp:`refmt ~has_ppx ~has_reason_react_jsx:true)
"build_ast_and_module_sets_from_re" in

~command:(mk_ast
~has_pp:`refmt
~has_ppx
~has_dev_ppx:false
~has_reason_react_jsx:true)
"build_ast_from_re" in
let build_ast_from_re_dev =
if has_dev_ppx then
define
~command:(mk_ast
~has_pp:`refmt
~has_ppx
~has_dev_ppx:true
~has_reason_react_jsx:true)
"build_ast_from_re_dev"
else
build_ast_from_re
in
let copy_resources =
define
~command:(
Expand Down Expand Up @@ -245,7 +282,9 @@ let make_custom_rules
in
{
build_ast ;
build_ast_dev;
build_ast_from_re ;
build_ast_from_re_dev ;
(** platform dependent, on Win32,
invoking cmd.exe
*)
Expand Down
6 changes: 4 additions & 2 deletions jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ val get_name : t -> out_channel -> string
(***********************************************************)
(** A list of existing rules *)
type builtin = {

build_ast : t;
build_ast_dev : t;
build_ast_from_re : t ;

build_ast_from_re_dev : t ;
(** platform dependent, on Win32,
invoking cmd.exe
*)
Expand Down Expand Up @@ -77,6 +78,7 @@ val make_custom_rules :
has_gentype:bool ->
has_postbuild:bool ->
has_ppx:bool ->
has_dev_ppx:bool ->
has_pp:bool ->
has_builtin:bool ->
bs_suffix:bool ->
Expand Down
31 changes: 23 additions & 8 deletions jscomp/build_tests/scoped_ppx/bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"ppx-flags":
"ppx-flags": [
[
["@hongbo/ppx1/test.js", "-hello"],
["@hongbo/ppx1/test.js", "-heyy"],
"@hongbo/ppx1/test.js"
"@hongbo/ppx1/test.js",
"-hello"
],
"sources" : {
"dir": "src"
},
"name": "hello"
[
"@hongbo/ppx1/test.js",
"-heyy"
],
"@hongbo/ppx1/test.js"
],
"ppx-dev-flags" : [
"@hongbo/ppx1/test.js"
],
"sources": [
{
"dir": "src"
},
{
"dir": "examples",
"type": "dev"
}
],
"name": "hello",
"refmt":3
}
1 change: 1 addition & 0 deletions jscomp/build_tests/scoped_ppx/examples/hey.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = 3
1 change: 1 addition & 0 deletions jscomp/build_tests/scoped_ppx/examples/hi.re
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Js.log ("hi");
20 changes: 18 additions & 2 deletions jscomp/build_tests/scoped_ppx/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@ var cp = require("child_process");
var assert = require('assert')
cp.execSync(`bsb`, { cwd: __dirname, stdio: [0, 1, 2], encoding: "utf8" });

var output = cp.execSync(`bsb -- -t commands src/hello.mlast`, {
cp.exec(`bsb -- -t commands src/hello.mlast`, {
cwd: __dirname,
encoding: "utf8"
},(error,output)=>{
if(error!==null){
throw error
}
assert(/-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test(output))
});
assert(/-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test(output))


cp.exec(`bsb -- -t commands examples/hey.mlast`, {
cwd: __dirname,
encoding: "utf8"
},(error,output)=>{
if(error!==null){
throw error
}
assert(/-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test(output))
});


Loading