Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a %{share}% variable (corresponding to ~/.opam/$switch/share).

This should fix #298
  • Loading branch information...
commit 24b7a23420ee5ad478a7e7aa2c56ade26e0ffeaf 1 parent 55db825
@samoht samoht authored
View
25 src/client/opamSolution.ml
@@ -140,6 +140,16 @@ let proceed_to_install t nv =
end
) (OpamFile.Dot_install.misc install);
+ (* Shared files *)
+ List.iter (fun (src, dst) ->
+ let share = OpamPath.Switch.share t.root t.switch name in
+ let dst = share // OpamFilename.Base.to_string dst in
+ (* WARNING [dst] could be a symbolic link (in this case, it will be removed). *)
+ if not (OpamFilename.exists_dir share) then
+ OpamFilename.mkdir share;
+ OpamFilename.copy src.c dst;
+ ) (OpamFile.Dot_install.share install);
+
if !warnings <> [] then (
let print (f, dst) = Printf.sprintf " - %s in %s" (OpamFilename.to_string f) (OpamFilename.Dir.to_string dst) in
OpamGlobals.error
@@ -262,6 +272,21 @@ let proceed_to_delete ~rm_build t nv =
end
) (OpamFile.Dot_install.misc install);
+ (* Remove the shared files *)
+ log "Removing the shared files";
+ let share = OpamPath.Switch.share t.root t.switch name in
+ List.iter (fun (_,dst) ->
+ let dst = share // (OpamFilename.Base.to_string dst) in
+ if OpamFilename.exists dst then
+ OpamGlobals.msg "Removing %s." (OpamFilename.to_string dst);
+ ) (OpamFile.Dot_install.share install);
+ (match OpamFilename.list_files share, OpamFilename.list_dirs share with
+ | [], [] -> OpamFilename.rmdir share
+ | _ ->
+ OpamGlobals.msg
+ "%s is not empty, I'm keeping its content for futur installations"
+ (OpamFilename.Dir.to_string share));
+
(* Remove .config and .install *)
log "Removing config and install files";
OpamFilename.remove (OpamPath.Switch.install t.root t.switch name);
View
1  src/client/opamState.ml
@@ -642,6 +642,7 @@ let install_conf_ocaml_config root switch =
("stublibs", OpamPath.Switch.stublibs root switch);
("toplevel", OpamPath.Switch.toplevel root switch);
("man", OpamPath.Switch.man_dir root switch);
+ ("share", OpamPath.Switch.share_dir root switch);
]
@ map id [
("user" , try (Unix.getpwuid (Unix.getuid ())).Unix.pw_name with _ -> "user");
View
16 src/core/opamFile.ml
@@ -759,12 +759,14 @@ module Dot_install_raw = struct
bin : (string optional * string option) list;
toplevel: string optional list;
misc: (string optional * string option) list;
+ share: (string optional * string option) list;
}
let lib t = t.lib
let bin t = t.bin
let toplevel t = t.toplevel
let misc t = t.misc
+ let share t = t.share
let with_bin t bin = { t with bin }
let with_lib t lib = { t with lib }
@@ -775,12 +777,14 @@ module Dot_install_raw = struct
bin = [] ;
toplevel = [] ;
misc = [] ;
+ share = [];
}
let s_lib = "lib"
let s_bin = "bin"
let s_misc = "misc"
let s_toplevel = "toplevel"
+ let s_share = "share"
let valid_fields = [
s_opam_version;
@@ -788,6 +792,7 @@ module Dot_install_raw = struct
s_bin;
s_toplevel;
s_misc;
+ s_share;
]
(* Filenames starting by ? are not always present. *)
@@ -814,6 +819,7 @@ module Dot_install_raw = struct
Variable (s_bin , OpamFormat.make_list make_option t.bin);
Variable (s_toplevel, OpamFormat.make_list (string_of_optional |> OpamFormat.make_string) t.toplevel);
Variable (s_misc , OpamFormat.make_list make_option t.misc);
+ Variable (s_share , OpamFormat.make_list make_option t.share);
]
} in
Syntax.to_string ~indent_variable:(fun _ -> true) filename s
@@ -835,7 +841,8 @@ module Dot_install_raw = struct
OpamFormat.assoc_list s.file_contents s_toplevel
(OpamFormat.parse_list (OpamFormat.parse_string |> optional_of_string)) in
let misc = OpamFormat.assoc_list s.file_contents s_misc (OpamFormat.parse_list parse_option) in
- { lib; bin; misc; toplevel }
+ let share = OpamFormat.assoc_list s.file_contents s_share (OpamFormat.parse_list parse_option) in
+ { lib; bin; misc; toplevel; share }
end
@@ -848,6 +855,7 @@ module Dot_install = struct
bin : (filename optional * basename) list ;
toplevel : filename optional list;
misc: (filename optional * filename) list ;
+ share: (filename optional * basename) list;
}
let string_of_move (src, dst) =
@@ -859,6 +867,7 @@ module Dot_install = struct
let bin t = t.bin
let misc t = t.misc
let toplevel t = t.toplevel
+ let share t = t.share
module R = Dot_install_raw
@@ -866,7 +875,8 @@ module Dot_install = struct
lib = [] ;
bin = [] ;
toplevel = [];
- misc = [] ;
+ misc = [];
+ share = [];
}
let map_o fn x =
@@ -883,6 +893,7 @@ module Dot_install = struct
{ lib = List.map (map_o OpamFilename.to_string) t.lib
; bin = List.map to_bin t.bin
; toplevel = List.map (map_o OpamFilename.to_string) t.toplevel
+ ; share = List.map to_bin t.share
; R.misc = List.map to_misc t.misc }
let of_string filename str =
@@ -896,6 +907,7 @@ module Dot_install = struct
{ lib = List.map (map_o OpamFilename.of_string) t.R.lib
; bin = List.map of_bin t.R.bin
; toplevel = List.map (map_o OpamFilename.of_string) t.R.toplevel
+ ; share = List.map of_bin t.R.share
; misc = List.map of_misc t.R.misc }
end
View
30 src/core/opamFile.mli
@@ -257,32 +257,7 @@ end
(** .install files *)
module Dot_install: sig
- module Raw : sig
-
- include IO_FILE
-
- (** List of files to install in $lib/ *)
- val lib: t -> string optional list
-
- (** List of files to install in $bin/ *)
- val bin: t -> (string optional * string option) list
-
- (** List of other files to install *)
- val misc: t -> (string optional * string option) list
-
- (** List of toplevel files *)
- val toplevel: t -> string optional list
-
- (** Construct as [bin] *)
- val with_bin: t -> (string optional * string option) list -> t
-
- (** Construct as [lib] *)
- val with_lib: t -> string optional list -> t
-
- (** Construct as [toplevel] *)
- val with_toplevel: t -> string optional list -> t
-
- end
+ module Raw : IO_FILE
include IO_FILE
@@ -298,6 +273,9 @@ module Dot_install: sig
(** List of other files to install *)
val misc: t -> (filename optional * filename) list
+ (** List of shared files *)
+ val share: t -> (filename optional * basename) list
+
end
(** .config files *)
View
4 src/core/opamPath.ml
@@ -71,6 +71,10 @@ module Switch = struct
| None -> root t a / "man"
| Some n -> root t a / "man" / ("man" ^ n)
+ let share_dir t a = root t a / "share"
+
+ let share t a n = share_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"
View
6 src/core/opamPath.mli
@@ -93,6 +93,12 @@ module Switch: sig
(** Documentation path: {i $opam/$OVERSION/doc/} *)
val doc_dir: t -> switch -> dirname
+ (** Shared directory: {i $opam/$OVERSION/share} *)
+ val share_dir: t -> switch -> dirname
+
+ (** Share directory for a given package: {i $opam/$OVERSION/share/$package} *)
+ val share: t -> switch -> name -> dirname
+
(** Man pages path: {i $opam/$OVERSION/man/}. The optional
[num] argument will add a {i manN } suffix if specified *)
val man_dir: ?num:string -> t -> switch -> dirname
View
1  tests/packages/P1-1.opam
@@ -13,6 +13,7 @@ build: [
[ "./build.sh" ]
[ "this" "should" "never" "run" ] { "%{ocaml-version}%" > "100" }
[ make "this" ocaml-version "also" ] { os = "NO" }
+ [ "echo" make share ocaml-version ]
[ "this as well" { "%{os}%" = "myOS" } ]
]
View
1  tests/packages/P1-1/P1.install
@@ -5,3 +5,4 @@ lib: [
"_build/p1.a"
"?_build/this_file_will_not_exits_but_that's_ok"
]
+share: [ "build.sh" { "foo/bar" } ]
Please sign in to comment.
Something went wrong with that request. Please try again.