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

Remove dependency on state value for opam2nix use cases #4147

Merged
merged 6 commits into from Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/client/opamAction.ml
Expand Up @@ -240,15 +240,13 @@ let download_package st nv =
(* Prepare the package build:
* apply the patches
* substitute the files *)
let prepare_package_build st nv dir =
let opam = OpamSwitchState.opam st nv in

let prepare_package_build package_var opam nv dir =
rjbou marked this conversation as resolved.
Show resolved Hide resolved
let patches = OpamFile.OPAM.patches opam in

let rec iter_patches f = function
| [] -> Done []
| (patchname,filter)::rest ->
if OpamFilter.opt_eval_to_bool (OpamPackageVar.resolve ~opam st) filter
if OpamFilter.opt_eval_to_bool package_var filter
then
OpamFilename.patch (dir // OpamFilename.Base.to_string patchname) dir
@@+ function
Expand Down Expand Up @@ -278,8 +276,7 @@ let prepare_package_build st nv dir =
OpamFilename.in_dir dir @@ fun () ->
List.fold_left (fun errs f ->
try
OpamFilter.expand_interpolations_in_file
(OpamPackageVar.resolve ~opam st) f;
OpamFilter.expand_interpolations_in_file package_var f;
errs
with e -> (f, e)::errs)
[] subst_patches
Expand All @@ -306,8 +303,7 @@ let prepare_package_build st nv dir =
OpamFilename.in_dir dir @@ fun () ->
List.fold_left (fun errs f ->
try
OpamFilter.expand_interpolations_in_file
(OpamPackageVar.resolve ~opam st) f;
OpamFilter.expand_interpolations_in_file package_var f;
errs
with e -> (f, e)::errs)
subst_errs subst_others
Expand Down Expand Up @@ -381,7 +377,8 @@ let prepare_package_source st nv dir =
OpamFilename.mkdir dir;
get_extra_sources_job @@+ function Some _ as err -> Done err | None ->
check_extra_files |> function Some _ as err -> Done err | None ->
prepare_package_build st nv dir
let opam = OpamSwitchState.opam st nv in
prepare_package_build (OpamPackageVar.resolve ~opam st) opam nv dir

let compilation_env t opam =
OpamEnv.get_full ~force_path:true t ~updates:([
Expand Down
6 changes: 6 additions & 0 deletions src/client/opamAction.mli
Expand Up @@ -29,6 +29,12 @@ val download_package:
val prepare_package_source:
rw switch_state -> package -> dirname -> exn option OpamProcess.job

(** [prepare_package_build env opam t dir] is a lower level version
rjbou marked this conversation as resolved.
Show resolved Hide resolved
of `prepare_package_source`, without requiring a switch and
without handling extra downloads. *)
val prepare_package_build:
OpamFilter.env -> OpamFile.OPAM.t -> package -> dirname -> exn option OpamProcess.job

(** [build_package t build_dir pkg] builds the package [pkg] within [build_dir].
Returns [None] on success, [Some exn] on error.
See {!download_package} and {!prepare_package_source} for the previous
Expand Down
44 changes: 28 additions & 16 deletions src/format/opamPath.ml
Expand Up @@ -74,6 +74,12 @@ let plugin t name =
assert (sname <> "bin");
plugins t / sname

module type LAYOUT = sig
type ctx
val root : dirname -> ctx -> dirname
val lib_dir : dirname -> ctx -> dirname
end

module Switch = struct

let root t a = OpamSwitch.get_root t a
Expand Down Expand Up @@ -138,39 +144,45 @@ module Switch = struct
let installed_opam_files_dir t a nv =
installed_package_dir t a nv / "files"

module Default = struct

(** Visible files that can be redirected using
[config/global-config.config] *)
module DefaultF(L:LAYOUT) = struct
let lib_dir = L.lib_dir

let lib_dir t a = root t a / "lib"
let lib t a n = L.lib_dir t a / OpamPackage.Name.to_string n

let lib t a n = lib_dir t a / OpamPackage.Name.to_string n
let stublibs t a = L.lib_dir t a / "stublibs"

let stublibs t a = lib_dir t a / "stublibs"
let toplevel t a = L.lib_dir t a / "toplevel"

let toplevel t a = lib_dir t a / "toplevel"

let doc_dir t a = root t a / "doc"
let doc_dir t a = L.root t a / "doc"

let man_dir ?num t a =
match num with
| None -> root t a / "man"
| Some n -> root t a / "man" / ("man" ^ n)
| None -> L.root t a / "man"
| Some n -> L.root t a / "man" / ("man" ^ n)

let share_dir t a = root t a / "share"
let share_dir t a = L.root t a / "share"

let share t a n = share_dir t a / OpamPackage.Name.to_string n

let etc_dir t a = root t a / "etc"
let etc_dir t a = L.root t a / "etc"

let etc t a n = etc_dir t a / OpamPackage.Name.to_string n

let doc t a n = doc_dir t a / OpamPackage.Name.to_string n

let bin t a = root t a / "bin"
let bin t a = L.root t a / "bin"

let sbin t a = L.root t a / "sbin"
end

let sbin t a = root t a / "sbin"
(** Visible files that can be redirected using
[config/global-config.config] *)
module Default = struct
include DefaultF(struct
type ctx = switch
let root = root
let lib_dir t a = root t a / "lib"
end)

end

Expand Down
37 changes: 37 additions & 0 deletions src/format/opamPath.mli
Expand Up @@ -78,6 +78,12 @@ val plugin_bin: t -> name -> filename
forbidden. *)
val plugin: t -> name -> dirname

module type LAYOUT = sig
type ctx
val root : dirname -> ctx -> dirname
val lib_dir : dirname -> ctx -> dirname
end

(** Switch related paths *)
module Switch: sig

Expand Down Expand Up @@ -229,6 +235,37 @@ module Switch: sig
val sbin: t -> switch -> dirname
end

(** Fuctorised version of Default, for replicating
a switch's layout in non-switch contexts *)
module DefaultF : functor (L:LAYOUT) -> sig
val lib: t -> L.ctx -> name -> dirname

val lib_dir: t -> L.ctx -> dirname

val stublibs: t -> L.ctx -> dirname

val toplevel: t -> L.ctx -> dirname

val doc: t -> L.ctx -> name -> dirname

val doc_dir: t -> L.ctx -> dirname

val share_dir: t -> L.ctx -> dirname

val share: t -> L.ctx -> name -> dirname

val etc_dir: t -> L.ctx -> dirname

val etc: t -> L.ctx -> name -> dirname

val man_dir: ?num:string -> t -> L.ctx -> dirname

val bin: t -> L.ctx -> dirname

val sbin: t -> L.ctx -> dirname
end


(** Actual config handling the global-config.config indirections *)

(** Package-independent dirs *)
Expand Down
13 changes: 9 additions & 4 deletions src/state/opamSwitchState.ml
Expand Up @@ -476,7 +476,7 @@ let conflicts_with st subset =
let remove_conflicts st subset pkgs =
pkgs -- conflicts_with st subset pkgs

let get_conflicts st packages opams_map =
let get_conflicts package_var packages opams_map =
rjbou marked this conversation as resolved.
Show resolved Hide resolved
let conflict_classes =
OpamPackage.Map.fold (fun nv opam acc ->
List.fold_left (fun acc cc ->
Expand All @@ -503,7 +503,7 @@ let get_conflicts st packages opams_map =
OpamPackage.Map.fold (fun nv opam acc ->
let conflicts =
OpamFilter.filter_formula ~default:false
(OpamPackageVar.resolve_switch ~package:nv st)
(package_var nv)
(OpamFile.OPAM.conflicts opam)
in
let conflicts =
Expand All @@ -523,6 +523,11 @@ let get_conflicts st packages opams_map =
opams_map
OpamPackage.Map.empty

let get_conflicts_state st packages opams_map =
get_conflicts
(fun package -> OpamPackageVar.resolve_switch ~package st)
packages opams_map

let universe st
?(test=OpamStateConfig.(!r.build_test))
?(doc=OpamStateConfig.(!r.build_doc))
Expand Down Expand Up @@ -579,7 +584,7 @@ let universe st
get_deps depend st.opams
in
let u_depopts = get_deps OpamFile.OPAM.depopts st.opams in
let u_conflicts = get_conflicts st st.packages st.opams in
let u_conflicts = get_conflicts_state st st.packages st.opams in
let base =
if OpamStateConfig.(!r.unlock_base) then OpamPackage.Set.empty
else st.compiler_packages
Expand Down Expand Up @@ -624,7 +629,7 @@ let universe st
u

let dump_pef_state st oc =
let conflicts = get_conflicts st st.packages st.opams in
let conflicts = get_conflicts_state st st.packages st.opams in
let print_def nv opam =
Printf.fprintf oc "package: %s\n" (OpamPackage.name_to_string nv);
Printf.fprintf oc "version: %s\n" (OpamPackage.version_to_string nv);
Expand Down
7 changes: 7 additions & 0 deletions src/state/opamSwitchState.mli
Expand Up @@ -54,6 +54,13 @@ val compute_available_packages:
pinned:package_set -> opams:OpamFile.OPAM.t package_map ->
package_set

(** Raw function to compute the conflicts for all packages, given
the set of available packages and the corresponding opam files.
the `u_conflicts` field when building a universe manually. *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a missing line in this ocamldoc comment? the u_conflicts field <...> seems to be incomplete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where that went, fixed thanks.

val get_conflicts:
(package -> OpamFilter.env) -> package_set ->
OpamFile.OPAM.t package_map -> formula package_map

(** Releases any locks on the given switch_state *)
val unlock: 'a switch_state -> unlocked switch_state

Expand Down