Skip to content
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

Fix libexec variable behavior #4058

Merged
merged 4 commits into from
Jan 5, 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
Expand Up @@ -108,6 +108,9 @@ Unreleased
- Configurator: fix a bug introduced in 2.6.0 where the configurator V1 API doesn't work at
all when used outside of dune. (#4046, @aalekseyev)

- Fix `libexec` and `libexec-private` variables. In cross-compilation settings,
they now point to the file in the host context. (#4058, fixes #4057, @TheLortex)

2.7.1 (2/09/2020)
-----------------

Expand Down
40 changes: 31 additions & 9 deletions src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ type t =
; hidden_env : Env.Var.Set.t
; env : Env.t
; lib_artifacts : Artifacts.Public_libs.t
; lib_artifacts_host : Artifacts.Public_libs.t
; bin_artifacts_host : Artifacts.Bin.t
; ocaml_config : Value.t list String.Map.t Lazy.t
; bindings : Pform.Map.t
; scope : Scope.t
; scope_host : Scope.t
; c_compiler : string
; context : Context.t
; expand_var : t -> Expanded.t String_with_vars.expander
Expand Down Expand Up @@ -193,8 +195,8 @@ let static_expand
let cc_cxx_bindings =
Pform.Map.of_list_exn [ ("cc", Pform.Var.Cc); ("cxx", Pform.Var.Cxx) ]

let make ~scope ~(context : Context.t) ~lib_artifacts ~bin_artifacts_host
~find_package =
let make ~scope ~scope_host ~(context : Context.t) ~lib_artifacts
~lib_artifacts_host ~bin_artifacts_host ~find_package =
let ocaml_config = lazy (make_ocaml_config context.ocaml_config) in
let dir = context.build_dir in
let bindings =
Expand All @@ -209,7 +211,9 @@ let make ~scope ~(context : Context.t) ~lib_artifacts ~bin_artifacts_host
; ocaml_config
; bindings
; scope
; scope_host
; lib_artifacts
; lib_artifacts_host
; bin_artifacts_host
; expand_var = static_expand
; c_compiler
Expand Down Expand Up @@ -376,10 +380,16 @@ let expand_and_record_generic acc ~dep_kind ~(dir : Path.Build.t) ~pform t
| Macro (Lib { lib_exec; lib_private }, s) -> (
let lib, file = parse_lib_file ~loc s in
Resolved_forms.add_lib_dep acc lib dep_kind;
let scope =
if lib_exec then
t.scope_host
else
t.scope
in
match
if lib_private then
let open Result.O in
let* lib = Lib.DB.resolve (Scope.libs t.scope) (loc, lib) in
let* lib = Lib.DB.resolve (Scope.libs scope) (loc, lib) in
let current_project = Scope.project t.scope
and referenced_project =
Lib.info lib |> Lib_info.status |> Lib_info.Status.project
Expand All @@ -394,9 +404,13 @@ let expand_and_record_generic acc ~dep_kind ~(dir : Path.Build.t) ~pform t
(User_error.E
(User_error.make ~loc
[ Pp.textf
"The variable \"lib-private\" can only refer to \
"The variable \"lib%s-private\" can only refer to \
libraries within the same project. The current \
project's name is %S, but the reference is to %s."
( if lib_exec then
"exec"
else
"" )
(Dune_project.Name.to_string_hum
(Dune_project.name current_project))
( match referenced_project with
Expand All @@ -406,11 +420,15 @@ let expand_and_record_generic acc ~dep_kind ~(dir : Path.Build.t) ~pform t
|> Dune_project.Name.to_string_hum |> String.quoted )
]))
else
Artifacts.Public_libs.file_of_lib t.lib_artifacts ~loc ~lib ~file
let artifacts =
if lib_exec then
t.lib_artifacts_host
else
t.lib_artifacts
in
Artifacts.Public_libs.file_of_lib artifacts ~loc ~lib ~file
with
| Ok path ->
(* TODO: The [exec = true] case is currently not handled correctly and
does not match the documentation. *)
if (not lib_exec) || (not Sys.win32) || Filename.extension s = ".exe" then
Static (path_exp path)
else
Expand All @@ -430,14 +448,18 @@ let expand_and_record_generic acc ~dep_kind ~(dir : Path.Build.t) ~pform t
( match lib_private with
| true -> e
| false ->
if Lib.DB.available (Scope.libs t.scope) lib then
if Lib.DB.available (Scope.libs scope) lib then
User_error.E
(User_error.make ~loc
[ Pp.textf
"The library %S is not public. The variable \"lib\" \
"The library %S is not public. The variable \"lib%s\" \
expands to the file's installation path which is not \
defined for private libraries."
(Lib_name.to_string lib)
( if lib_exec then
"exec"
else
"" )
])
else
e ) )
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/expander.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ val context : t -> Context.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)
-> t
Expand Down
10 changes: 6 additions & 4 deletions src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,18 @@ let create ~(context : Context.t) ?host ~projects ~packages ~stanzas () =
Artifacts.create context ~public_libs ~local_bins
in
let root_expander =
let artifacts_host =
let scopes_host, artifacts_host, context_host =
match host with
| None -> artifacts
| Some host -> host.artifacts
| None -> (scopes, artifacts, context)
| Some host -> (host.scopes, host.artifacts, host.context)
in
let find_package = Package.Name.Map.find packages in
Expander.make
~scope:(Scope.DB.find_by_dir scopes context.build_dir)
~scope_host:(Scope.DB.find_by_dir scopes_host context_host.build_dir)
~context ~lib_artifacts:artifacts.public_libs
~bin_artifacts_host:artifacts_host.bin ~find_package
~bin_artifacts_host:artifacts_host.bin
~lib_artifacts_host:artifacts_host.public_libs ~find_package
in
let dune_dir_locations_var : Stdune.Env.Var.t = "DUNE_DIR_LOCATIONS" in
(* Add the section of the site mentioned in stanzas (it could be a site of an
Expand Down
1 change: 0 additions & 1 deletion test/blackbox-tests/test-cases/lib.t/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
----------------------------------------------------------------------------------
Testsuite for the %{lib...} and %{lib-private...} variable.
TODO: Fix %{libexec} and %{libexec-private} variables and test them.

$ cat >sdune <<'EOF'
> #!/usr/bin/env bash
Expand Down
Loading