From 232acdd92f46254c2cfbf768da9cb07410976b89 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Mon, 5 Mar 2018 16:33:03 +0000 Subject: [PATCH] Libraries and executables can allow overlapping dependencies --- doc/jbuild.rst | 6 ++++++ src/gen_rules.ml | 6 +++++- src/jbuild.ml | 12 ++++++++---- src/jbuild.mli | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/jbuild.rst b/doc/jbuild.rst index 3270ee28..54287dc5 100644 --- a/doc/jbuild.rst +++ b/doc/jbuild.rst @@ -177,6 +177,9 @@ modules you want. such modules to avoid surprises. ```` must be a subset of the modules listed in the ``(modules ...)`` field. +- ``(allow_overlapping_dependencies)`` allows external dependencies to + overlap with libraries that are present in the workspace + Note that when binding C libraries, Jbuilder doesn't provide special support for tools such as ``pkg-config``, however it integrates easily with `configurator `__ by using ``(c_flags (:include @@ -263,6 +266,9 @@ binary at the same place as where ``ocamlc`` was found, or when there is a - ``(modules_without_implementation )`` is the same as the corresponding field of `library`_ +- ``(allow_overlapping_dependencies)`` is the same as the + corresponding field of `library`_ + executables ----------- diff --git a/src/gen_rules.ml b/src/gen_rules.ml index bbcf4b18..6e813b56 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -559,7 +559,10 @@ module Gen(P : Install_rules.Params) = struct |> String.concat ~sep:"\n") >>> Build.write_file_dyn (Path.relative dir file.name))); - let compile_info = Lib.DB.get_compile_info (Scope.libs scope) lib.name in + let compile_info = + Lib.DB.get_compile_info (Scope.libs scope) lib.name + ~allow_overlaps:lib.buildable.allow_overlapping_dependencies + in let requires, real_requires = SC.Libs.requires sctx compile_info ~dir ~has_dot_merlin:true @@ -810,6 +813,7 @@ module Gen(P : Install_rules.Params) = struct Lib.DB.resolve_user_written_deps (Scope.libs scope) exes.buildable.libraries ~pps:(Jbuild.Preprocess_map.pps exes.buildable.preprocess) + ~allow_overlaps:exes.buildable.allow_overlapping_dependencies in let requires, real_requires = SC.Libs.requires sctx ~dir diff --git a/src/jbuild.ml b/src/jbuild.ml index 621997cd..7957b8d5 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -476,6 +476,7 @@ module Buildable = struct ; ocamlc_flags : Ordered_set_lang.Unexpanded.t ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t ; js_of_ocaml : Js_of_ocaml.t + ; allow_overlapping_dependencies : bool } let modules_field name = @@ -487,8 +488,6 @@ module Buildable = struct >>= fun preprocess -> field "preprocessor_deps" (list Dep_conf.t) ~default:[] >>= fun preprocessor_deps -> - (* CR-someday jdimino: remove this. There are still a few Jane Street packages using - this *) field "lint" Lint.t ~default:Lint.default >>= fun lint -> modules_field "modules" @@ -500,7 +499,10 @@ module Buildable = struct field_oslu "flags" >>= fun flags -> field_oslu "ocamlc_flags" >>= fun ocamlc_flags -> field_oslu "ocamlopt_flags" >>= fun ocamlopt_flags -> - field "js_of_ocaml" (Js_of_ocaml.t) ~default:Js_of_ocaml.default >>= fun js_of_ocaml -> + field "js_of_ocaml" (Js_of_ocaml.t) ~default:Js_of_ocaml.default + >>= fun js_of_ocaml -> + field_b "allow_overlapping_dependencies" + >>= fun allow_overlapping_dependencies -> return { loc ; preprocess @@ -513,6 +515,7 @@ module Buildable = struct ; ocamlc_flags ; ocamlopt_flags ; js_of_ocaml + ; allow_overlapping_dependencies } let single_preprocess t = @@ -867,7 +870,8 @@ module Rule = struct return (fallback, mode)) ~f:(function | true, Some _ -> - Error "Cannot use both (fallback) and (mode ...) at the same time.\n\ + Error "Cannot use both (fallback) and (mode ...) at the \ + same time.\n\ (fallback) is the same as (mode fallback), \ please use the latter in new code." | false, Some mode -> Ok mode diff --git a/src/jbuild.mli b/src/jbuild.mli index c005e894..928df193 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -143,6 +143,7 @@ module Buildable : sig ; ocamlc_flags : Ordered_set_lang.Unexpanded.t ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t ; js_of_ocaml : Js_of_ocaml.t + ; allow_overlapping_dependencies : bool } (** Preprocessing specification used by all modules or [No_preprocessing] *)