Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[conf] Add "enable"/"installed" virtual variables (ie. which do not a…

…ppear in the corresponding .config files)

It is always possible to query for them, even if the package is not installed.

%{foo:enable}% = "enable" if the package "foo" is installed, "disable" othewise
${foo:installed}% = true if the package "foo" is installed, false otherwise
  • Loading branch information...
commit f3c95736923998a0ab10d427298cd4fec0acec3c 1 parent 760a3a9
@samoht samoht authored
Showing with 37 additions and 11 deletions.
  1. +19 −9 src/client.ml
  2. +9 −1 src/types.ml
  3. +9 −1 src/types.mli
View
28 src/client.ml
@@ -102,6 +102,9 @@ let find_repository t name =
let r, _ = List.find (fun (r,_) -> Repository.name r = name) t.repositories in
r
+let mem_installed_package_by_name t name =
+ not (NV.Set.is_empty (NV.Set.filter (fun nv -> NV.name nv = name) t.installed))
+
let find_installed_package_by_name t name =
try NV.Set.choose (NV.Set.filter (fun nv -> NV.name nv = name) t.installed)
with Not_found ->
@@ -588,16 +591,23 @@ let get_archive t nv =
let contents_of_variable t v =
let name = Full_variable.package v in
let var = Full_variable.variable v in
- let _nv =
- try find_installed_package_by_name t name
+ let installed = mem_installed_package_by_name t name in
+ if var = Variable.enable && installed then
+ S "enable"
+ else if var = Variable.enable && not installed then
+ S "disable"
+ else if var = Variable.installed then
+ B installed
+ else if not installed then
+ Globals.error_and_exit "Package %s is not installed" (N.to_string name)
+ else begin
+ let c = File.Dot_config.safe_read (Path.C.config t.compiler name) in
+ try match Full_variable.section v with
+ | None -> File.Dot_config.variable c var
+ | Some s -> File.Dot_config.Section.variable c s var
with Not_found ->
- Globals.error_and_exit "Package %s is not installed" (N.to_string name) in
- let c = File.Dot_config.safe_read (Path.C.config t.compiler name) in
- try match Full_variable.section v with
- | None -> File.Dot_config.variable c var
- | Some s -> File.Dot_config.Section.variable c s var
- with Not_found ->
- Globals.error_and_exit "%s is not defined" (Full_variable.to_string v)
+ Globals.error_and_exit "%s is not defined" (Full_variable.to_string v)
+ end
(* Substitue the string contents *)
let substitute_string t s =
View
10 src/types.ml
@@ -399,7 +399,15 @@ type repository = Repository.t
(* Variable names *)
(* Variable names are used in .config files *)
-module Variable: Abstract = Base
+module Variable: sig
+ include Abstract
+ val installed: t
+ val enable: t
+end = struct
+ include Base
+ let installed = of_string "installed"
+ let enable = of_string "enable"
+end
type variable = Variable.t
View
10 src/types.mli
@@ -257,7 +257,15 @@ type repository = Repository.t
(** {2 Variable names} *)
(** Variable names are used in .config files *)
-module Variable: Abstract
+module Variable: sig
+ include Abstract
+
+ (** the variable [enable] *)
+ val enable: t
+
+ (** the variable [installed] *)
+ val installed: t
+end
(** Shortcut to variable type *)
type variable = Variable.t
Please sign in to comment.
Something went wrong with that request. Please try again.