Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

It is now possible to disable some packages on some OS

os: [ !"darwin"]

or

os: ["linux" "bsd"]

This is quite had-hoc at the moment (ie. a typo will not be detected) but it is sufficient to close #260
  • Loading branch information...
commit 865233b6626f28d5e3340176f92da2dca0698cba 1 parent c466fc4
@samoht samoht authored
View
11 src/client/opamSolution.ml
@@ -399,8 +399,15 @@ let unknown_package name version =
let unavailable_package name version =
match version with
- | None -> OpamGlobals.error_and_exit "%S is not available for your compiler.\n" (OpamPackage.Name.to_string name)
- | Some v -> OpamGlobals.error_and_exit "Version %s of %S is incompatible with your compiler." (OpamPackage.Version.to_string v) (OpamPackage.Name.to_string name)
+ | None ->
+ OpamGlobals.error_and_exit
+ "%S is not available for your compiler or your OS.\n"
+ (OpamPackage.Name.to_string name)
+ | Some v ->
+ OpamGlobals.error_and_exit
+ "Version %s of %S is incompatible with your compiler or your OS."
+ (OpamPackage.Version.to_string v)
+ (OpamPackage.Name.to_string name)
let eq_atom name version =
name, Some (`Eq, version)
View
11 src/client/opamState.ml
@@ -229,6 +229,14 @@ let available_packages root opams repositories repo_index compiler_version confi
match OpamFile.OPAM.ocaml_version opam with
| None -> true
| Some c -> OpamFormula.eval atom c in
+ let consistent_os () =
+ match OpamFile.OPAM.os opam with
+ | [] -> true
+ | l ->
+ List.fold_left (fun accu (b,os) ->
+ let ($) = if b then (=) else (<>) in
+ accu || (os $ Lazy.force OpamGlobals.os_string)
+ ) false l in
let consistent_pinned_version () =
not (OpamPackage.Name.Map.mem (OpamPackage.name nv) pinned) ||
match OpamPackage.Name.Map.find (OpamPackage.name nv) pinned with
@@ -236,7 +244,8 @@ let available_packages root opams repositories repo_index compiler_version confi
| _ -> true (* any version is fine, as this will be overloaded on install *) in
available ()
&& consistent_ocaml_version ()
- && consistent_pinned_version () in
+ && consistent_pinned_version ()
+ && consistent_os () in
OpamPackage.Set.filter filter packages
let base_packages =
View
14 src/core/opamFile.ml
@@ -560,6 +560,7 @@ module OPAM = struct
files : (basename * filter option) list;
others : (string * value) list;
ocaml_version: compiler_constraint option;
+ os : (bool * string) list;
}
let empty = {
@@ -579,6 +580,7 @@ module OPAM = struct
patches = [];
others = [];
ocaml_version = None;
+ os = [];
}
let create nv =
@@ -605,6 +607,7 @@ module OPAM = struct
let s_patches = "patches"
let s_files = "files"
let s_configure_style = "configure-style"
+ let s_os = "os"
let useful_fields = [
s_opam_version;
@@ -621,6 +624,7 @@ module OPAM = struct
s_build_env;
s_patches;
s_files;
+ s_os;
]
let valid_fields =
@@ -648,6 +652,7 @@ module OPAM = struct
let build_env t = t.build_env
let patches t = t.patches
let files t = t.files
+ let os t = t.os
let with_depends t depends = { t with depends }
let with_depopts t depopts = { t with depopts }
@@ -682,6 +687,10 @@ module OPAM = struct
match t.ocaml_version with
| None -> []
| Some v -> [ Variable (s_ocaml_version, OpamFormat.make_compiler_constraint v) ]
+ ) @ (
+ match t.os with
+ | [] -> []
+ | l -> [ Variable (s_os, OpamFormat.make_os_constraint l) ]
) @
List.map (fun (s, v) -> Variable (s, v)) t.others;
} in
@@ -738,6 +747,7 @@ module OPAM = struct
let libraries = OpamFormat.assoc_list s s_libraries (OpamFormat.parse_list (OpamFormat.parse_string |> OpamVariable.Section.of_string)) in
let syntax = OpamFormat.assoc_list s s_syntax (OpamFormat.parse_list (OpamFormat.parse_string |> OpamVariable.Section.of_string)) in
let ocaml_version = OpamFormat.assoc_option s s_ocaml_version OpamFormat.parse_compiler_constraint in
+ let os = OpamFormat.assoc_list s s_os OpamFormat.parse_os_constraint in
let parse_file = OpamFormat.parse_option (OpamFormat.parse_string |> OpamFilename.Base.of_string) OpamFormat.parse_filter in
let patches = OpamFormat.assoc_list s s_patches (OpamFormat.parse_list parse_file) in
let files = OpamFormat.assoc_list s s_files (OpamFormat.parse_list parse_file) in
@@ -748,12 +758,12 @@ module OPAM = struct
) s in
{ name; version; maintainer; substs; build; remove;
depends; depopts; conflicts; libraries; syntax; others;
- files; patches; ocaml_version; build_env }
+ files; patches; ocaml_version; os; build_env }
end
module Dot_install_raw = struct
- let internal = ".install(*raw*)"
+ let internal = ".install(raw)"
type t = {
lib : string optional list;
View
3  src/core/opamFile.mli
@@ -90,6 +90,9 @@ module OPAM: sig
(** Compiler constraint *)
val ocaml_version: t -> compiler_constraint option
+ (** OS constraint *)
+ val os: t -> (bool * string) list
+
(** Package maintainer *)
val maintainer: t -> string
View
21 src/core/opamFormat.ml
@@ -387,6 +387,27 @@ let rec make_compiler_constraint t =
let make_compiler_constraint t =
List (make_compiler_constraint t)
+let parse_os_constraint l =
+ let rec aux = function
+ | [] -> []
+ | String os :: l -> (true, os) :: aux l
+ | Symbol n :: String os :: l ->
+ if n = "!" then
+ (false, os) :: aux l
+ else
+ bad_format "Expecting '!', got %s" n
+ | e :: _ -> bad_format "Expecting an OS constraint, got %s" (kind e) in
+ match l with
+ | List l -> aux l
+ | e -> bad_format "Expecting an OS constraint, got %s" (kind e)
+
+let make_os_constraint l =
+ let rec aux = function
+ | [] -> []
+ | (true , os) :: l -> String os :: aux l
+ | (false, os) :: l -> Symbol "!" :: String os :: aux l in
+ List (aux l)
+
let parse_env_variable v =
let l = parse_sequence [
("ident" , parse_ident);
View
6 src/core/opamFormat.mli
@@ -198,6 +198,12 @@ val parse_compiler_constraint: value -> compiler_constraint
(** Build a compiler constraint *)
val make_compiler_constraint: compiler_constraint -> value
+(** Parse an OS constraint *)
+val parse_os_constraint: value -> (bool * string) list
+
+(** Build an OS constraint *)
+val make_os_constraint: (bool * string) list -> value
+
(** {2 Environment variables} *)
(** Parsing *)
Please sign in to comment.
Something went wrong with that request. Please try again.