diff --git a/src/super_context.ml b/src/super_context.ml index 94b1f74a553f..15fa86a51505 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -279,7 +279,20 @@ let cxx_flags_gather t ~dir ~(lib : Library.t) ccg = let local_binaries t ~dir = Env.local_binaries t ~dir let dump_env t ~dir = - Ocaml_flags.dump (Env.ocaml_flags t ~dir) + let open Build.O in + let o_dump = Ocaml_flags.dump (Env.ocaml_flags t ~dir) in + let c_flags = Env.c_flags t ~dir in + let cxx_flags = Env.cxx_flags t ~dir in + let c_dump = + Build.fanout c_flags cxx_flags + >>^ fun (c_flags, cxx_flags) -> + List.map ~f:Dune_lang.Encoder.(pair string (list string)) + [ "c_flags", c_flags + ; "cxx_flags", cxx_flags + ] + in (* combine o_dump and c_dump *) + (o_dump &&& c_dump) >>^ (fun (x, y) -> x @ y) + let resolve_program t ~dir ?hint ~loc bin = let artifacts = Env.artifacts_host t ~dir in diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 099fb9963861..fd73e31681f5 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -255,6 +255,14 @@ test-cases/env-bins (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name env-cflags) + (deps (package dune) (source_tree test-cases/env-cflags)) + (action + (chdir + test-cases/env-cflags + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name env-dune-file) (deps (package dune) (source_tree test-cases/env-dune-file)) @@ -1243,6 +1251,7 @@ (alias env) (alias env-and-flags-include) (alias env-bins) + (alias env-cflags) (alias env-dune-file) (alias env-tracking) (alias env-var-expansion) @@ -1393,6 +1402,7 @@ (alias env) (alias env-and-flags-include) (alias env-bins) + (alias env-cflags) (alias env-dune-file) (alias env-tracking) (alias env-var-expansion) diff --git a/test/blackbox-tests/test-cases/env-cflags/bin/dune b/test/blackbox-tests/test-cases/env-cflags/bin/dune new file mode 100644 index 000000000000..e347ed876ee0 --- /dev/null +++ b/test/blackbox-tests/test-cases/env-cflags/bin/dune @@ -0,0 +1,4 @@ +(env + (default + (c_flags "in bin") + (cxx_flags "in bin"))) diff --git a/test/blackbox-tests/test-cases/env-cflags/dune b/test/blackbox-tests/test-cases/env-cflags/dune new file mode 100644 index 000000000000..26d4672910d6 --- /dev/null +++ b/test/blackbox-tests/test-cases/env-cflags/dune @@ -0,0 +1,4 @@ +(env + (default + (c_flags :standard ":standard + in .") + (cxx_flags :standard ":standard + in ."))) diff --git a/test/blackbox-tests/test-cases/env-cflags/dune-project b/test/blackbox-tests/test-cases/env-cflags/dune-project new file mode 100644 index 000000000000..de4fc2092005 --- /dev/null +++ b/test/blackbox-tests/test-cases/env-cflags/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) diff --git a/test/blackbox-tests/test-cases/env-cflags/run.t b/test/blackbox-tests/test-cases/env-cflags/run.t new file mode 100644 index 000000000000..8783c53d9cf3 --- /dev/null +++ b/test/blackbox-tests/test-cases/env-cflags/run.t @@ -0,0 +1,26 @@ + $ dune printenv --profile default . + ( + (flags (-w -40)) + (ocamlc_flags (-g)) + (ocamlopt_flags (-g)) + (c_flags (":standard + in .")) + (cxx_flags (":standard + in .")) + ) + + $ dune printenv --profile default src + ( + (flags (-w -40)) + (ocamlc_flags (-g)) + (ocamlopt_flags (-g)) + (c_flags (":standard + in ." ":standard + in src")) + (cxx_flags (":standard + in ." ":standard + in src")) + ) + + $ dune printenv --profile default bin + ( + (flags (-w -40)) + (ocamlc_flags (-g)) + (ocamlopt_flags (-g)) + (c_flags ("in bin")) + (cxx_flags ("in bin")) + ) diff --git a/test/blackbox-tests/test-cases/env-cflags/src/dune b/test/blackbox-tests/test-cases/env-cflags/src/dune new file mode 100644 index 000000000000..8a82a489c2c7 --- /dev/null +++ b/test/blackbox-tests/test-cases/env-cflags/src/dune @@ -0,0 +1,5 @@ +(env + (default + (c_flags :standard ":standard + in src") + (cxx_flags :standard ":standard + in src") + )) diff --git a/test/blackbox-tests/test-cases/env/run.t b/test/blackbox-tests/test-cases/env/run.t index e255c02bf2b6..0b911c0494ee 100644 --- a/test/blackbox-tests/test-cases/env/run.t +++ b/test/blackbox-tests/test-cases/env/run.t @@ -3,24 +3,32 @@ (flags (-w -40 ":standard + in .")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) $ dune printenv --profile default src ( (flags (-w -40 ":standard + in ." ":standard + in src")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) $ dune printenv --profile default bin ( (flags ("in bin")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) $ dune printenv --profile default vendor ( (flags (-w -40 ":standard + in .")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) Vendored project without env customization, the global default should @@ -31,6 +39,8 @@ apply: (flags (-w -40)) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) Vendored project with env customization, the global default + @@ -41,11 +51,15 @@ customization of vendored project should apply: (flags (-w -40 ":standard + in vendor/with-env-customization")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) $ dune printenv --profile default vendor/with-env-customization/src ( (flags ("in vendor/with-env-customization/src")) (ocamlc_flags (-g)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) ) diff --git a/test/blackbox-tests/test-cases/workspaces/run.t b/test/blackbox-tests/test-cases/workspaces/run.t index 093e53c27a92..bd1a95efbf1c 100644 --- a/test/blackbox-tests/test-cases/workspaces/run.t +++ b/test/blackbox-tests/test-cases/workspaces/run.t @@ -61,4 +61,6 @@ Workspaces also allow you to set the env for a context: (flags (-w -40 -machin)) (ocamlc_flags (-g -verbose)) (ocamlopt_flags (-g)) + (c_flags ()) + (cxx_flags ()) )