Skip to content

Commit

Permalink
#766:enable specifying flags when compiling binaries from inline tests
Browse files Browse the repository at this point in the history
Signed-off-by: lubegasimon <lubegasimon73@gmail.com>
  • Loading branch information
lubegasimon committed Aug 6, 2020
1 parent 897a8fa commit 5e204ce
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dune/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
else
l
in
let flags = SC.ocaml_flags sctx ~dir exes.buildable in
let flags = SC.ocaml_flags sctx ~dir exes.buildable.flags in
let link_deps = Dep_conf_eval.unnamed ~expander exes.link_deps in
let foreign_archives = exes.buildable.foreign_archives |> List.map ~f:snd in
let link_flags =
Expand Down
9 changes: 7 additions & 2 deletions src/dune/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ include Sub_system.Register_end_point (struct
; deps : Dep_conf.t list
; modes : Mode_conf.Set.t
; flags : Ordered_set_lang.Unexpanded.t
; compile_flags : Ordered_set_lang.Unexpanded.t
; backend : (Loc.t * Lib_name.t) option
; libraries : (Loc.t * Lib_name.t) list
}
Expand All @@ -182,6 +183,7 @@ include Sub_system.Register_end_point (struct
(let+ loc = loc
and+ deps = field "deps" (repeat Dep_conf.decode) ~default:[]
and+ flags = Ordered_set_lang.Unexpanded.field "flags"
and+ compile_flags = Ordered_set_lang.Unexpanded.field "compile_flags"
and+ backend = field_o "backend" (located Lib_name.decode)
and+ libraries =
field "libraries" (repeat (located Lib_name.decode)) ~default:[]
Expand All @@ -190,7 +192,7 @@ include Sub_system.Register_end_point (struct
(Dune_lang.Syntax.since syntax (1, 11) >>> Mode_conf.Set.decode)
~default:Mode_conf.Set.default
in
{ loc; deps; flags; backend; libraries; modes })
{ loc; deps; flags; compile_flags; backend; libraries; modes })

(* We don't use this at the moment, but we could implement it for debugging
purposes *)
Expand Down Expand Up @@ -280,7 +282,10 @@ include Sub_system.Register_end_point (struct
Compilation_context.create () ~super_context:sctx ~expander ~scope
~obj_dir ~modules ~opaque:(Explicit false) ~requires_compile:runner_libs
~requires_link:(lazy runner_libs)
~flags:(Ocaml_flags.of_list [ "-w"; "-24"; "-g" ])
~flags:
(Ocaml_flags.append_common
(Super_context.ocaml_flags sctx ~dir lib.buildable.flags)
[ "-w"; "-24"; "-g" ])
~js_of_ocaml:(Some lib.buildable.js_of_ocaml) ~dynlink:false
~package:(Option.map lib.public ~f:Dune_file.Public_lib.package)
in
Expand Down
2 changes: 1 addition & 1 deletion src/dune/lib_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ let cctx (lib : Library.t) ~sctx ~source_modules ~dir ~expander ~scope
else
Required
in
let flags = Super_context.ocaml_flags sctx ~dir lib.buildable in
let flags = Super_context.ocaml_flags sctx ~dir lib.buildable.flags in
let obj_dir = Library.obj_dir ~dir lib in
let vimpl = Virtual_rules.impl sctx ~lib ~scope in
let ctx = Super_context.context sctx in
Expand Down
4 changes: 2 additions & 2 deletions src/dune/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ let build_dir_is_vendored build_dir =
in
Option.value ~default:false opt

let ocaml_flags t ~dir (x : Dune_file.Buildable.t) =
let ocaml_flags t ~dir (f : Ocaml_flags.Spec.t) =
let expander = Env_tree.expander t.env_tree ~dir in
let flags =
Ocaml_flags.make ~spec:x.flags
Ocaml_flags.make ~spec:f
~default:(get_node t.env_tree ~dir |> Env_node.ocaml_flags)
~eval:(Expander.expand_and_eval_set expander)
in
Expand Down
2 changes: 1 addition & 1 deletion src/dune/super_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ val internal_lib_names : t -> Lib_name.Set.t
(** Compute the ocaml flags based on the directory environment and a buildable
stanza *)
val ocaml_flags :
t -> dir:Path.Build.t -> Dune_file.Buildable.t -> Ocaml_flags.t
t -> dir:Path.Build.t -> Ocaml_flags.Spec.t -> Ocaml_flags.t

val foreign_flags :
t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name compile_flags_test)
(inline_tests
(backend foo)
(compile_flags -bar)))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.7)
7 changes: 7 additions & 0 deletions test/blackbox-tests/test-cases/inline_tests/dune-file.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ package:
Entering directory 'dune-file-user'
inline_test_runner_foo_tests alias runtest
414243

We run the inline tests with a program that passes in specifc compile flags:

$ export OCAMLPATH=$PWD/_install/lib; dune runtest --root dune-file-compile-flags
Entering directory 'dune-file-compile-flags'
inline_test_runner_compile_flags_test alias runtest
414243

0 comments on commit 5e204ce

Please sign in to comment.