Skip to content

Commit

Permalink
Enable bisect_ppx via dune-workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie You <youstephanie98@gmail.com>
  • Loading branch information
stephanieyou committed Apr 28, 2020
1 parent f260f47 commit 4393704
Show file tree
Hide file tree
Showing 17 changed files with 215 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ opam_install_test_deps () {
ocaml-migrate-parsetree \
result.1.4 \
utop.2.4.2 \
mdx.1.6.0
mdx.1.6.0 \
bisect_ppx
# We install Coq separatedly as to be more resistant w.r.t. the 10
# minutes Travis timeout; the travis_wait hack doesn't work well
# with Dune's current setup. Note that Travis caching should help
Expand Down
15 changes: 10 additions & 5 deletions src/dune/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ let write_dot_dune_dir ~build_dir ~ocamlc ~ocaml_config_vars =

let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
~host_context ~host_toolchain ~profile ~fdo_target_exe
~dynamically_linked_foreign_archives =
~dynamically_linked_foreign_archives ~bisect_enabled =
let prog_not_found_in_path prog =
Utils.program_not_found prog ~context:name ~loc:None
in
Expand Down Expand Up @@ -485,6 +485,7 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
; ccomp_type = Ocaml_config.ccomp_type ocfg
; profile
; ocaml_version = Ocaml_config.version_string ocfg
; bisect_enabled
}
in
if Option.is_some fdo_target_exe then
Expand Down Expand Up @@ -597,10 +598,10 @@ let extend_paths t ~env =
Env.extend ~vars env

let default ~merlin ~env_nodes ~env ~targets ~fdo_target_exe
~dynamically_linked_foreign_archives =
~dynamically_linked_foreign_archives ~bisect_enabled =
let path = Env.path env in
create ~kind:Default ~path ~env ~env_nodes ~merlin ~targets ~fdo_target_exe
~dynamically_linked_foreign_archives
~dynamically_linked_foreign_archives ~bisect_enabled

let opam_version =
let f opam =
Expand Down Expand Up @@ -631,7 +632,7 @@ let opam_version =

let create_for_opam ~root ~env ~env_nodes ~targets ~profile ~switch ~name
~merlin ~host_context ~host_toolchain ~fdo_target_exe
~dynamically_linked_foreign_archives =
~dynamically_linked_foreign_archives ~bisect_enabled =
let opam =
match Memo.Lazy.force opam with
| None -> Utils.program_not_found "opam" ~loc:None
Expand Down Expand Up @@ -682,6 +683,7 @@ let create_for_opam ~root ~env ~env_nodes ~targets ~profile ~switch ~name
~kind:(Opam { root; switch })
~profile ~targets ~path ~env ~env_nodes ~name ~merlin ~host_context
~host_toolchain ~fdo_target_exe ~dynamically_linked_foreign_archives
~bisect_enabled

let instantiate_context env (workspace : Workspace.t)
~(context : Workspace.Context.t) ~host_context =
Expand All @@ -701,6 +703,7 @@ let instantiate_context env (workspace : Workspace.t)
; loc = _
; fdo_target_exe
; dynamically_linked_foreign_archives
; bisect_enabled
} ->
let merlin =
workspace.merlin_context = Some (Workspace.Context.name context)
Expand All @@ -716,6 +719,7 @@ let instantiate_context env (workspace : Workspace.t)
let env = extend_paths ~env paths in
default ~env ~env_nodes ~profile ~targets ~name ~merlin ~host_context
~host_toolchain ~fdo_target_exe ~dynamically_linked_foreign_archives
~bisect_enabled
| Opam
{ base =
{ targets
Expand All @@ -728,6 +732,7 @@ let instantiate_context env (workspace : Workspace.t)
; loc = _
; fdo_target_exe
; dynamically_linked_foreign_archives
; bisect_enabled
}
; switch
; root
Expand All @@ -736,7 +741,7 @@ let instantiate_context env (workspace : Workspace.t)
let env = extend_paths ~env paths in
create_for_opam ~root ~env_nodes ~env ~profile ~switch ~name ~merlin
~targets ~host_context ~host_toolchain:toolchain ~fdo_target_exe
~dynamically_linked_foreign_archives
~dynamically_linked_foreign_archives ~bisect_enabled

module Create = struct
module Output = struct
Expand Down
45 changes: 44 additions & 1 deletion src/dune/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,29 @@ module Preprocess_map = struct
List.fold_left (Preprocess.pps pp) ~init:acc ~f:(fun acc (loc, pp) ->
Lib_name.Map.set acc pp loc))
|> Lib_name.Map.foldi ~init:[] ~f:(fun pp loc acc -> (loc, pp) :: acc)

let add_bisect t =
let bisect_ppx =
let bisect_name = Lib_name.parse_string_exn (Loc.none, "bisect_ppx") in
(Loc.none, bisect_name)
in
Per_module.map t ~f:(fun pp ->
match pp with
| Preprocess.No_preprocessing ->
let loc = Loc.none in
let pps = [ bisect_ppx ] in
let flags = [] in
let staged = false in
Preprocess.Pps { loc; pps; flags; staged }
| Preprocess.Pps { loc; pps; flags; staged } ->
let pps = bisect_ppx :: pps in
Preprocess.Pps { loc; pps; flags; staged }
| Action (loc, _) | Future_syntax loc ->
User_error.raise ~loc
[ Pp.text
"Preprocessing with actions and future syntax cannot be used \
in conjunction with (bisect_ppx)"
])
end

module Lint = struct
Expand Down Expand Up @@ -359,6 +382,7 @@ module Buildable = struct
; flags : Ocaml_flags.Spec.t
; js_of_ocaml : Js_of_ocaml.t
; allow_overlapping_dependencies : bool
; bisect_ppx : bool
}

let decode ~in_library ~allow_re_export =
Expand Down Expand Up @@ -424,6 +448,8 @@ module Buildable = struct
field "js_of_ocaml" Js_of_ocaml.decode ~default:Js_of_ocaml.default
and+ allow_overlapping_dependencies =
field_b "allow_overlapping_dependencies"
and+ bisect_ppx =
field_b "bisect_ppx" ~check:(Dune_lang.Syntax.since Stanza.syntax (2, 5))
and+ version = Dune_lang.Syntax.get_exn Stanza.syntax in
let foreign_stubs =
foreign_stubs
Expand Down Expand Up @@ -468,6 +494,7 @@ module Buildable = struct
; flags
; js_of_ocaml
; allow_overlapping_dependencies
; bisect_ppx
}

let has_foreign t =
Expand All @@ -481,6 +508,12 @@ module Buildable = struct
Per_module.get t.preprocess dummy_name
else
Preprocess.No_preprocessing

let preprocess t ~(lib_config: Lib_config.t) =
if t.bisect_ppx && lib_config.bisect_enabled then
Preprocess_map.add_bisect t.preprocess
else
t.preprocess
end

module Public_lib = struct
Expand Down Expand Up @@ -1031,7 +1064,17 @@ module Library = struct
let synopsis = conf.synopsis in
let sub_systems = conf.sub_systems in
let ppx_runtime_deps = conf.ppx_runtime_libraries in
let pps = Preprocess_map.pps conf.buildable.preprocess in
let pps =
let pps_without_bisect = Preprocess_map.pps conf.buildable.preprocess in
if lib_config.bisect_enabled && conf.buildable.bisect_ppx then
let bisect_ppx =
let bisect_name = Lib_name.parse_string_exn (Loc.none, "bisect_ppx") in
(Loc.none, bisect_name)
in
bisect_ppx :: pps_without_bisect
else
pps_without_bisect
in
let virtual_deps = conf.virtual_deps in
let dune_version = Some conf.dune_version in
let implements = conf.implements in
Expand Down
4 changes: 4 additions & 0 deletions src/dune/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ module Buildable : sig
; flags : Ocaml_flags.Spec.t
; js_of_ocaml : Js_of_ocaml.t
; allow_overlapping_dependencies : bool
; bisect_ppx : bool
}

(** Check if the buildable has any foreign stubs or archives. *)
val has_foreign : t -> bool

(** Preprocessing specification used by all modules or [No_preprocessing] *)
val single_preprocess : t -> Preprocess.t

(** Includes bisect_ppx if specified by [lib_config] *)
val preprocess : t -> lib_config:Lib_config.t -> Preprocess_map.t
end

module Public_lib : sig
Expand Down
16 changes: 11 additions & 5 deletions src/dune/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
let ml_sources = Dir_contents.ocaml dir_contents in
Ml_sources.modules_of_executables ml_sources ~first_exe ~obj_dir
in
let ctx = SC.context sctx in
let preprocess =
Dune_file.Buildable.preprocess exes.buildable ~lib_config:ctx.lib_config
in
let pp =
Preprocessing.make sctx ~dir ~dep_kind:Required ~scope ~expander
~preprocess:exes.buildable.preprocess
~preprocess
~preprocessor_deps:exes.buildable.preprocessor_deps
~lint:exes.buildable.lint ~lib_name:None
in
Expand All @@ -44,7 +48,6 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
(Module_name.to_string mod_name)
])
in
let ctx = SC.context sctx in
let explicit_js_mode = Dune_project.explicit_js_mode (Scope.project scope) in
let linkages =
let module L = Dune_file.Executables.Link_mode in
Expand Down Expand Up @@ -170,11 +173,14 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
let rules ~sctx ~dir ~dir_contents ~scope ~expander
(exes : Dune_file.Executables.t) =
let dune_version = Scope.project scope |> Dune_project.dune_version in
let ctx = SC.context sctx in
let pps =
Dune_file.Preprocess_map.pps
(Dune_file.Buildable.preprocess exes.buildable ~lib_config:ctx.lib_config)
in
let compile_info =
Lib.DB.resolve_user_written_deps_for_exes (Scope.libs scope) exes.names
exes.buildable.libraries
~pps:(Dune_file.Preprocess_map.pps exes.buildable.preprocess)
~dune_version
exes.buildable.libraries ~pps ~dune_version
~allow_overlaps:exes.buildable.allow_overlapping_dependencies
~variants:exes.variants ~optional:exes.optional
~forbidden_libraries:exes.forbidden_libraries
Expand Down
12 changes: 8 additions & 4 deletions src/dune/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end = struct
(Some loc, Install.Entry.make Stublibs a))
]

let keep_if ~external_lib_deps_mode expander =
let keep_if ~(ctx : Context.t) ~external_lib_deps_mode expander =
if external_lib_deps_mode then
fun ~scope:_ ->
Option.some
Expand All @@ -155,10 +155,14 @@ end = struct
let dune_version =
Scope.project scope |> Dune_project.dune_version
in
let pps =
Dune_file.Preprocess_map.pps
(Dune_file.Buildable.preprocess exes.buildable
~lib_config:ctx.lib_config)
in
Lib.DB.resolve_user_written_deps_for_exes (Scope.libs scope)
exes.names exes.buildable.libraries
~pps:(Dune_file.Preprocess_map.pps exes.buildable.preprocess)
~dune_version
~pps ~dune_version
~allow_overlaps:exes.buildable.allow_overlapping_dependencies
~variants:exes.variants ~optional:exes.optional
in
Expand Down Expand Up @@ -231,7 +235,7 @@ end = struct
in
let keep_if =
let external_lib_deps_mode = !Clflags.external_lib_deps_mode in
keep_if ~external_lib_deps_mode
keep_if ~ctx ~external_lib_deps_mode
in
Dir_with_dune.deep_fold stanzas ~init ~f:(fun d stanza acc ->
let { Dir_with_dune.ctx_dir = dir; scope; _ } = d in
Expand Down
1 change: 1 addition & 0 deletions src/dune/lib_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type t =
; ccomp_type : Ocaml_config.Ccomp_type.t
; profile : Profile.t
; ocaml_version : string
; bisect_enabled : bool
}

let var_map =
Expand Down
1 change: 1 addition & 0 deletions src/dune/lib_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type t =
; ccomp_type : Ocaml_config.Ccomp_type.t
; profile : Profile.t
; ocaml_version : string
; bisect_enabled : bool
}

val allowed_in_enabled_if : (string * Dune_lang.Syntax.Version.t) list
Expand Down
7 changes: 5 additions & 2 deletions src/dune/lib_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,14 @@ let cctx (lib : Library.t) ~sctx ~source_modules ~dir ~expander ~scope
let flags = Super_context.ocaml_flags sctx ~dir lib.buildable 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
let preprocess =
Dune_file.Buildable.preprocess lib.buildable ~lib_config:ctx.lib_config
in
(* Preprocess before adding the alias module as it doesn't need preprocessing *)
let pp =
Preprocessing.make sctx ~dir ~dep_kind ~scope
~preprocess:lib.buildable.preprocess ~expander
~preprocess ~expander
~preprocessor_deps:lib.buildable.preprocessor_deps
~lint:lib.buildable.lint
~lib_name:(Some (snd lib.name))
Expand All @@ -354,7 +358,6 @@ let cctx (lib : Library.t) ~sctx ~source_modules ~dir ~expander ~scope
let modules = Vimpl.impl_modules vimpl modules in
let requires_compile = Lib.Compile.direct_requires compile_info in
let requires_link = Lib.Compile.requires_link compile_info in
let ctx = Super_context.context sctx in
let dynlink =
Dynlink_supported.get lib.dynlink ctx.supports_shared_libraries
in
Expand Down
8 changes: 6 additions & 2 deletions src/dune/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,14 @@ let get_installed_binaries stanzas ~(context : Context.t) =
let compile_info =
let project = Scope.project d.scope in
let dune_version = Dune_project.dune_version project in
let pps =
Dune_file.Preprocess_map.pps
(Dune_file.Buildable.preprocess exes.buildable
~lib_config:context.lib_config)
in
Lib.DB.resolve_user_written_deps_for_exes (Scope.libs d.scope)
exes.names exes.buildable.libraries
~pps:(Dune_file.Preprocess_map.pps exes.buildable.preprocess)
~dune_version
~pps ~dune_version
~allow_overlaps:exes.buildable.allow_overlapping_dependencies
~variants:exes.variants ~optional:exes.optional
in
Expand Down
8 changes: 6 additions & 2 deletions src/dune/virtual_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let setup_copy_rules_for_impl ~sctx ~dir vimpl =
Modules.iter_no_vlib vlib_modules ~f:(fun m -> copy_objs m)

let impl sctx ~(lib : Dune_file.Library.t) ~scope =
let ctx = Super_context.context sctx in
Option.map lib.implements ~f:(fun (loc, implements) ->
match Lib.DB.find (Scope.libs scope) implements with
| None ->
Expand Down Expand Up @@ -108,10 +109,13 @@ let impl sctx ~(lib : Dune_file.Library.t) ~scope =
let dir = Lib_info.src_dir info in
Dir_contents.get sctx ~dir
in
let preprocess =
Dune_file.Buildable.preprocess lib.buildable
~lib_config:ctx.lib_config
in
let modules =
let pp_spec =
Pp_spec.make lib.buildable.preprocess
(Super_context.context sctx).version
Pp_spec.make preprocess (Super_context.context sctx).version
in
Dir_contents.ocaml dir_contents
|> Ml_sources.modules_of_library ~name
Expand Down
Loading

0 comments on commit 4393704

Please sign in to comment.