8000 Fix dependency on an installed package by bobot · Pull Request #4170 · ocaml/dune · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix dependency on an installed package #4170

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

Merged
merged 3 commits into from
Jan 28, 2021
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Allow `(package pkg)` in dependencies even if `pkg` is an installed package
(#4170, @bobot)

- Fixed a bug that could result in needless recompilation under Windows due to
case differences in the result of `Sys.getcwd` (observed under `emacs`).
(#3966, @nojb).
Expand Down
18 changes: 18 additions & 0 deletions otherlibs/site/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ Test compiling an external plugin
> (generate_sites_module (module sites) (sites e))
> (plugin (name c-plugins-e) (libraries e) (site (c plugins)))
> (install (section (site (e data))) (files info.txt))
> (rule (alias runtest) (deps (package a) (package b) (package c) (package d) (package e))
> (action (run %{bin:c})))
> EOF

$ cat >e/e.ml <<EOF
Expand Down Expand Up @@ -303,6 +305,22 @@ Test compiling an external plugin
info.txt is found: true
run c: registered:e,b.

$ OCAMLPATH=_install/lib:$OCAMLPATH dune build @runtest
c alias e/runtest
run a
a: $TESTCASE_ROOT/_build/install/default/share/a/data
run c: a linked registered:.
sourceroot is "$TESTCASE_ROOT"
c: $TESTCASE_ROOT/_build/install/default/share/c/data
b is available: true
run b
b: $TESTCASE_ROOT/_build/install/default/share/b/data
info.txt is found: true
run e
e: $TESTCASE_ROOT/_build/install/default/share/e/data
info.txt is found: true
run c: registered:e,b.

Test %{version:installed-pkg}
-----------------------------

Expand Down
17 changes: 17 additions & 0 deletions src/dune_engine/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module Dst : sig
val compare : t -> t -> Ordering.t

val infer : src_basename:string -> Section.t -> t

include Dune_lang.Conv.S with type t := t

val to_dyn : t -> Dyn.t
end = struct
type t = string

Expand Down Expand Up @@ -68,6 +72,12 @@ end = struct
None
else
Some s

let decode = Dune_lang.Decoder.string

let encode = Dune_lang.Encoder.string

let to_dyn = Dyn.Encoder.string
end

module Section_with_site = struct
Expand Down Expand Up @@ -104,6 +114,13 @@ module Section_with_site = struct
>>> pair Package.Name.decode Section.Site.decode
>>| fun (pkg, site) -> Site { pkg; site } )
] )

let encode =
let open Dune_lang.Encoder in
function
| Section s -> Section.encode s
| Site { pkg; site } ->
constr "site" (pair Package.Name.encode Section.Site.encode) (pkg, site)
end

module Section = struct
Expand Down
6 changes: 5 additions & 1 deletion src/dune_engine/install.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module Dst : sig
type t

val to_string : t -> string

include Dune_lang.Conv.S with type t := t

val to_dyn : t -> Dyn.t
end

(** Location for installation, containing the sections relative to the current
Expand All @@ -23,7 +27,7 @@ module Section_with_site : sig

(* val parse_string : string -> (t, string) Result.t *)

val decode : t Dune_lang.Decoder.t
include Dune_lang.Conv.S with type t := t

val to_dyn : t -> Dyn.t
end
Expand Down
28 changes: 27 additions & 1 deletion src/dune_rules/dep_conf_eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,37 @@ let dep expander = function
let pkg = Package.Name.of_string pkg in
let context = Expander.context expander in
match Expander.find_package expander pkg with
| Some pkg ->
| Some (Local pkg) ->
Action_builder.alias
(Build_system.Alias.package_install
~context:(Context.build_context context)
~pkg)
| Some (Installed pkg) ->
let version =
Dune_project.dune_version @@ Scope.project
@@ Expander.scope expander
in
if version < (2, 9) then
Action_builder.fail
{ fail =
(fun () ->
let loc = String_with_vars.loc p in
User_error.raise ~loc
[ Pp.textf
"Dependency on an installed package requires at \
least (lang dune 2.9)"
])
}
else
let files =
List.concat_map
~f:(fun (s, l) ->
let dir = Section.Map.find_exn pkg.sections s in
List.map l ~f:(fun d ->
Path.relative dir (Install.Dst.to_string d)))
pkg.files
in
Action_builder.paths files
| None ->
Action_builder.fail
{ fail =
Expand Down
13 changes: 10 additions & 3 deletions src/dune_rules/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ type t =
; sections : Path.t Section.Map.t
; sites : Section.t Section.Site.Map.t
; dir : Path.t
; files : (Section.t * Install.Dst.t list) list
}

let decode ~lang ~dir =
Expand All @@ -314,6 +315,9 @@ let decode ~lang ~dir =
and+ sites =
field ~default:[] "sites"
(repeat (pair (located Section.Site.decode) Section.decode))
and+ files =
field ~default:[] "files"
(repeat (pair Install.Section.decode (enter (repeat Install.Dst.decode))))
and+ entries = leftover_fields_as_sums (Entry.cstrs ~lang ~dir) in
let entries =
List.map entries ~f:(fun e ->
Expand Down Expand Up @@ -348,7 +352,7 @@ let decode ~lang ~dir =
let sites =
section_map Section.Site.Map.of_list_map Section.Site.to_string sites
in
{ name; version; entries; dir; sections; sites }
{ name; version; entries; dir; sections; sites; files }

let () = Vfile.Lang.register Stanza.syntax ()

Expand All @@ -363,7 +367,8 @@ let prepend_version ~dune_version sexps =
]
@ sexps

let encode ~dune_version { entries; name; version; dir; sections; sites } =
let encode ~dune_version { entries; name; version; dir; sections; sites; files }
=
let open Dune_lang.Encoder in
let sections =
Section.Map.to_list (Section.Map.map ~f:Path.to_absolute_filename sections)
Expand All @@ -375,6 +380,7 @@ let encode ~dune_version { entries; name; version; dir; sections; sites } =
; field_o "version" string version
; field_l "sections" (pair Section.encode string) sections
; field_l "sites" (pair Section.Site.encode Section.encode) sites
; field_l "files" (pair Section.encode (list Install.Dst.encode)) files
]
in
let list s = Dune_lang.List s in
Expand All @@ -394,7 +400,7 @@ let encode ~dune_version { entries; name; version; dir; sections; sites } =
in
prepend_version ~dune_version (List.concat [ sexp; entries ])

let to_dyn { entries; name; version; dir; sections; sites } =
let to_dyn { entries; name; version; dir; sections; sites; files } =
let open Dyn.Encoder in
record
[ ( "entries"
Expand All @@ -404,6 +410,7 @@ let to_dyn { entries; name; version; dir; sections; sites } =
; ("dir", Path.to_dyn dir)
; ("sections", Section.Map.to_dyn Path.to_dyn sections)
; ("sites", Section.Site.Map.to_dyn Section.to_dyn sites)
; ("files", (list (pair Section.to_dyn (list Install.Dst.to_dyn))) files)
]

module Or_meta = struct
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/dune_package.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type t =
; sections : Path.t Section.Map.t
; sites : Section.t Section.Site.Map.t
; dir : Path.t
; files : (Section.t * Install.Dst.t list) list
}

val to_dyn : t Dyn.Encoder.t
Expand Down
6 changes: 5 additions & 1 deletion src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module Expanded = struct
| Some v -> Value v
end

type any_package =
| Local of Package.t
| Installed of Dune_package.t

type t =
{ dir : Path.Build.t
; hidden_env : Env.Var.Set.t
Expand All @@ -39,7 +43,7 @@ type t =
; map_exe : Path.t -> Path.t
; foreign_flags :
dir:Path.Build.t -> string list Action_builder.t Foreign_language.Dict.t
; find_package : Package.Name.t -> Package.t option
; find_package : Package.Name.t -> any_package option
}

let scope t = t.scope
Expand Down
9 changes: 7 additions & 2 deletions src/dune_rules/expander.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ val dir : t -> Path.Build.t

val context : t -> Context.t

(** local or installed package *)
type any_package =
| Local of Package.t
| Installed of Dune_package.t

val make :
scope:Scope.t
-> scope_host:Scope.t
-> context:Context.t
-> lib_artifacts:Artifacts.Public_libs.t
-> lib_artifacts_host:Artifacts.Public_libs.t
-> bin_artifacts_host:Artifacts.Bin.t
-> find_package:(Package.Name.t -> Package.t option)
-> find_package:(Package.Name.t -> any_package option)
-> t

val set_foreign_flags :
Expand Down Expand Up @@ -124,4 +129,4 @@ val map_exe : t -> Path.t -> Path.t

val artifacts : t -> Artifacts.Bin.t

val find_package : t -> Package.Name.t -> Package.t option
val find_package : t -> Package.Name.t -> any_package option
2 changes: 2 additions & 0 deletions src/dune_rules/findlib/findlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ let builtin_for_dune : Dune_package.t =
; dir = Path.root
; sections = Section.Map.empty
; sites = Section.Site.Map.empty
; files = []
}

type db =
Expand Down Expand Up @@ -481,6 +482,7 @@ end = struct
; dir
; sections = Section.Map.empty
; sites = Section.Site.Map.empty
; files = []
}

let load_and_convert db ~dir ~meta_file ~name =
Expand Down
31 changes: 24 additions & 7 deletions src/dune_rules/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,19 @@ end
module Meta_and_dune_package : sig
val meta_and_dune_package_rules : Super_context.t -> dir:Path.Build.t -> unit
end = struct
let sections ctx_name pkg =
let sections ctx_name files pkg =
let pkg_name = Package.name pkg in
Section.Site.Map.values pkg.sites
|> Section.Set.of_list
|> Section.Set.to_map ~f:(fun section ->
Install.Section.Paths.get_local_location ctx_name section pkg_name)
let sections =
(* the one from sites *)
Section.Site.Map.values pkg.sites |> Section.Set.of_list
in
let sections =
(* the one from install stanza *)
List.fold_left ~init:sections files ~f:(fun acc (s, _) ->
Section.Set.add acc s)
in
Section.Set.to_map sections ~f:(fun section ->
Install.Section.Paths.get_local_location ctx_name section pkg_name)

let make_dune_package sctx lib_entries (pkg : Package.t) =
let pkg_name = Package.name pkg in
Expand Down Expand Up @@ -455,14 +462,23 @@ end = struct
~dir:(Path.build (lib_root lib))
~modules ~foreign_objects))))
in
let sections = sections ctx.name pkg in
let files =
Package.Name.Map.Multi.find
(Stanzas_to_entries.stanzas_to_entries sctx)
pkg_name
|> List.map ~f:(fun (_, entry) ->
(entry.Install.Entry.section, entry.dst))
|> Section.Map.of_list_multi |> Section.Map.to_list
in
let sections = sections ctx.name files pkg in
Dune_package.Or_meta.Dune_package
{ Dune_package.version = pkg.version
; name = pkg_name
; entries
; dir = Path.build pkg_root
; sections
; sites = pkg.sites
; files
}

let gen_dune_package sctx (pkg : Package.t) =
Expand Down Expand Up @@ -518,7 +534,7 @@ end = struct
(Dune_package.Entry.Deprecated_library_name
{ loc; old_public_name; new_public_name }))
in
let sections = sections ctx.name pkg in
let sections = sections ctx.name [] pkg in
{ Dune_package.version = pkg.version
; name
; entries
Expand All @@ -527,6 +543,7 @@ end = struct
(Config.local_install_lib_dir ~context:ctx.name ~package:name)
; sections
; sites = pkg.sites
; files = []
}
in
Action_builder.write_file
Expand Down
Loading
0