Skip to content

Commit

Permalink
Clean-ups: OPAM now compiles with -warning-error A -w +A-4-9
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht committed Jan 9, 2013
1 parent 1ca631f commit 19de888
Show file tree
Hide file tree
Showing 33 changed files with 252 additions and 429 deletions.
10 changes: 4 additions & 6 deletions src/client/opamClient.ml
Expand Up @@ -15,8 +15,6 @@

open OpamTypes
open OpamState.Types
open OpamFilename.OP
open OpamMisc.OP

let log fmt = OpamGlobals.log "CLIENT" fmt

Expand Down Expand Up @@ -695,7 +693,7 @@ let init repo compiler cores =
let t = OpamState.load_state () in
let switch = OpamSwitch.of_string (OpamCompiler.to_string compiler) in
let quiet = (compiler = OpamCompiler.default) in
OpamState.install_compiler t quiet switch compiler;
OpamState.install_compiler t ~quiet switch compiler;
update_packages t ~show_packages:false t.repositories;

(* Finally, load the complete state and install the compiler packages *)
Expand Down Expand Up @@ -888,7 +886,7 @@ let upload upload repo =
(OpamRepositoryName.to_string repo)
(OpamState.string_of_repositories t.repositories) in
let repo_p = OpamPath.Repository.create t.root repo.repo_name in
let upload_repo = OpamPath.Repository.raw (OpamPath.Repository.upload_dir repo_p) in
let upload_repo = OpamPath.Repository.upload_dir repo_p in
let upload_opam = OpamPath.Repository.opam upload_repo nv in
let upload_descr = OpamPath.Repository.descr upload_repo nv in
let upload_archives = OpamPath.Repository.archive upload_repo nv in
Expand Down Expand Up @@ -1083,7 +1081,7 @@ let remote action =
OpamState.check (Global_lock (fun () -> remote action))

let switch_install quiet switch ocaml_version =
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.install quiet switch ocaml_version))
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.install ~quiet switch ocaml_version))

let switch_import filename =
OpamState.check (Switch_lock (fun () -> OpamSwitchCommand.import filename))
Expand All @@ -1095,7 +1093,7 @@ let switch_remove switch =
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.remove switch))

let switch quiet name =
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.switch quiet name))
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.switch ~quiet name))

let switch_reinstall switch =
OpamState.check (Global_lock (fun () -> OpamSwitchCommand.reinstall switch))
Expand Down
225 changes: 112 additions & 113 deletions src/client/opamMain.ml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/client/opamSolution.ml
Expand Up @@ -417,7 +417,7 @@ let proceed_to_change t nv_old nv =
| Some nv_old ->
OpamGlobals.error
"The recompilation of %s failed in %s."
(OpamPackage.to_string nv)
(OpamPackage.to_string nv_old)
(OpamFilename.Dir.to_string p_build)
end;
raise e
Expand Down Expand Up @@ -650,7 +650,6 @@ let apply_solution ?(force = false) t action sol =
)

let new_variables e =
let open OpamMisc in
let e = List.filter (fun (_,s,_) -> s="=") e in
let e = List.map (fun (v,_,_) -> v) e in
OpamMisc.StringSet.of_list e
Expand Down
60 changes: 3 additions & 57 deletions src/client/opamState.ml
Expand Up @@ -14,7 +14,6 @@
(***********************************************************************)

open OpamTypes
open OpamFilename.OP
open OpamMisc.OP

let log fmt =
Expand Down Expand Up @@ -150,25 +149,12 @@ let print_state t =
log "USERS : %s" (OpamPackage.Set.to_string t.user_installed);
log "REINSTALL : %s" (OpamPackage.Set.to_string t.reinstall)

let compiler_of_switch t switch =
try Some (OpamSwitch.Map.find switch t.aliases)
with Not_found -> None

let config t =
OpamFile.Config.read (OpamPath.config t.root)

let compilers t =
OpamCompiler.list (OpamPath.compilers_dir t.root)

let repositories t =
OpamFile.Config.repositories t.config

let opam t nv =
OpamPackage.Map.find nv t.opams

let archives t =
OpamFilename.Set.of_list (OpamFilename.list_files (OpamPath.archives_dir t.root))

let compiler t c =
OpamFile.Comp.safe_read (OpamPath.compiler t.root c)

Expand Down Expand Up @@ -200,9 +186,6 @@ let installed_map t =
let dot_config t nv =
OpamFile.Dot_config.safe_read (OpamPath.Switch.config t.root t.switch nv)

let reinstall t =
OpamFile.Reinstall.safe_read (OpamPath.Switch.reinstall t.root t.switch)

let mem_repository_name t name =
OpamRepositoryName.Map.exists (fun n _ -> n = name) t.repositories

Expand Down Expand Up @@ -242,7 +225,7 @@ let with_repository t nv fn =
| Some (repo_p, repo) -> fn repo_p repo

(* List the packages which does fullfil the compiler constraints *)
let available_packages root opams repositories repo_index compiler_version config pinned packages =
let available_packages root opams repositories repo_index compiler_version pinned packages =
let filter nv =
let opam = OpamPackage.Map.find nv opams in
let available () =
Expand Down Expand Up @@ -404,7 +387,7 @@ let load_state () =
let reinstall = OpamFile.Reinstall.safe_read (OpamPath.Switch.reinstall root switch) in
let packages = OpamPackage.list (OpamPath.opam_dir root) in
let available_packages =
lazy (available_packages root opams repositories repo_index compiler_version config pinned packages) in
lazy (available_packages root opams repositories repo_index compiler_version pinned packages) in
let t = {
root; switch; compiler; compiler_version; repositories; opams;
packages; available_packages; installed; user_installed; reinstall;
Expand Down Expand Up @@ -526,42 +509,6 @@ let substitute_file t f =
let substitute_string t s =
OpamFile.Subst.replace_string s (contents_of_variable t)

let rec substitute_filter t = function
| FBool b -> FBool b
| FString s -> FString (substitute_string t s)
| FIdent s -> FString (substitute_ident t s)
| FOp(e,s,f) ->
let e = substitute_filter t e in
let f = substitute_filter t f in
FOp(e, s, f)
| FAnd (e,f) ->
let e = substitute_filter t e in
let f = substitute_filter t f in
FAnd(e,f)
| FOr(e,f) ->
let e = substitute_filter t e in
let f = substitute_filter t f in
FOr(e,f)

let substitute_arg t (a, f) =
let a = match a with
| CString s -> CString (substitute_string t s)
| CIdent i -> CString (substitute_ident t i) in
let f = match f with
| None -> None
| Some f -> Some (substitute_filter t f) in
(a, f)

let substitute_command t (l, f) =
let l = List.map (substitute_arg t) l in
let f = match f with
| None -> None
| Some f -> Some (substitute_filter t f) in
(l, f)

let substitute_commands t c =
List.map (substitute_command t) c

let rec eval_filter t = function
| FBool b -> string_of_bool b
| FString s -> substitute_string t s
Expand Down Expand Up @@ -680,8 +627,7 @@ let print_env_warning ?(add_profile = false) t =
else
Printf.sprintf " --root %s" !OpamGlobals.root_dir in
let variables = String.concat ", " (List.map (fun (s, _) -> "$" ^ s) l) in
OpamGlobals.msg "\nTo update %s; you can now run:
\n\ $ %seval `opam config env%s`\n%s\n"
OpamGlobals.msg "\nTo update %s; you can now run:\n\n $ %seval `opam config env%s`\n%s\n"
variables
which_opam
opam_root
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamState.mli
Expand Up @@ -129,7 +129,7 @@ val filter_commands: state -> command list -> string list list
val mem_repository: state -> package -> bool

(** Apply a function on the repository which contains a given package *)
val with_repository: state -> package -> (OpamPath.Repository.r -> repository -> 'a) -> 'a
val with_repository: state -> package -> (repository_root -> repository -> 'a) -> 'a

(** Check whether a repository name is valid *)
val mem_repository_name: state -> repository_name -> bool
Expand Down
4 changes: 2 additions & 2 deletions src/client/opamSwitchCommand.ml
Expand Up @@ -124,7 +124,7 @@ let install_with_packages ~quiet ~packages ~warning switch compiler =
let old_switch = t.switch in

(* install the new OCaml version *)
OpamState.install_compiler t quiet switch compiler;
OpamState.install_compiler t ~quiet switch compiler;

(* install the compiler packages *)
let t = OpamState.load_state () in
Expand Down Expand Up @@ -185,7 +185,7 @@ let switch ~quiet switch =
if not (OpamFilename.exists_dir comp_dir) && not (OpamFilename.exists comp_f) then
OpamState.unknown_compiler compiler;
if not (OpamSwitch.Map.mem switch t.aliases) then
install quiet switch compiler
install ~quiet switch compiler
else
update_config t switch

Expand Down
41 changes: 8 additions & 33 deletions src/core/opamFile.ml
Expand Up @@ -13,24 +13,18 @@
(* *)
(***********************************************************************)

exception Parsing of string

open OpamTypes
open OpamMisc.OP

module Lines = struct

let internal = "lines"

(* Lines of space separated words *)
type t = string list list

let empty = []

let of_string raw =
OpamLineLexer.main (Lexing.from_string raw)
let of_string str =
OpamLineLexer.main (Lexing.from_string str)

let to_string lines =
let to_string (lines: t) =
let buf = Buffer.create 1024 in
List.iter (fun l ->
Buffer.add_string buf (String.concat " " l);
Expand All @@ -42,12 +36,8 @@ end

module Syntax = struct

let internal = "syntax"

type t = file

let empty = OpamFormat.empty

let of_string filename str =
let filename = OpamFilename.to_string filename in
try
Expand All @@ -58,7 +48,7 @@ module Syntax = struct
OpamGlobals.error "Parsing error while reading %s" filename;
raise e

let to_string ?(indent_variable = fun _ -> false) t =
let to_string ?(indent_variable = fun _ -> false) (t: t) =
OpamFormat.string_of_file ~indent_variable t
let check f fields =
Expand Down Expand Up @@ -823,16 +813,6 @@ module Dot_install_raw = struct
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 }
let with_toplevel t toplevel = { t with toplevel }
let empty = {
lib = [] ;
bin = [] ;
Expand Down Expand Up @@ -919,11 +899,6 @@ module Dot_install = struct
share: (filename optional * basename) list;
}
let string_of_move (src, dst) =
let src = OpamFilename.to_string src in
let dst = OpamFilename.to_string dst in
Printf.sprintf "%s => %s" src dst
let lib t = t.lib
let bin t = t.bin
let misc t = t.misc
Expand Down Expand Up @@ -1044,7 +1019,7 @@ module Dot_config = struct
let variables = parse_variables file.file_contents in
{ sections; variables }
let rec to_string filename t =
let to_string filename t =
let of_value = function
| B b -> Bool b
| S s -> String s in
Expand Down Expand Up @@ -1180,7 +1155,7 @@ module Comp = struct
let create_preinstalled name version packages env =
let mk n = Atom (n, Empty) in
let rec aux accu t = match accu, t with
let aux accu t = match accu, t with
| Empty, x -> mk x
| _ , x -> And(accu, mk x) in
let packages = List.fold_left aux OpamFormula.Empty packages in
Expand Down Expand Up @@ -1368,9 +1343,9 @@ module Subst = struct
let empty = ""
let of_string filename str = str
let of_string _ str = str
let to_string filename t = t
let to_string _ t = t
let replace t f =
let subst str =
Expand Down
2 changes: 1 addition & 1 deletion src/core/opamFilename.ml
Expand Up @@ -209,7 +209,7 @@ let extract_in filename dirname =
OpamSystem.extract_in (to_string filename) (Dir.to_string dirname)

let starts_with dirname filename =
OpamMisc.starts_with (Dir.to_string dirname) (to_string filename)
OpamMisc.starts_with ~prefix:(Dir.to_string dirname) (to_string filename)

let remove_prefix ~prefix filename =
let prefix =
Expand Down
4 changes: 2 additions & 2 deletions src/core/opamFormat.ml
Expand Up @@ -231,8 +231,8 @@ and string_of_values l =
let incr tab = " " ^ tab

let rec string_of_item_aux tab ?(indent_variable = fun _ -> false) = function
| Variable (i, List []) -> None
| Variable (i, List[List[]]) -> None
| Variable (_, List []) -> None
| Variable (_, List[List[]]) -> None
| Variable (i, v) -> Some (Printf.sprintf "%s%s: %s" tab i (pretty_string_of_value ~indent_hint:[indent_variable i] v))
| Section s ->
Some (Printf.sprintf "%s%s %S {\n%s\n}"
Expand Down
8 changes: 4 additions & 4 deletions src/core/opamFormula.ml
Expand Up @@ -124,7 +124,7 @@ let to_string t =
string_of_formula string_of_pkg t

(* convert a formula to a CNF *)
let rec cnf_of_formula t =
let cnf_of_formula t =
let rec mk_left x y = match y with
| Block y -> mk_left x y
| And (a,b) -> And (mk_left x a, mk_left x b)
Expand All @@ -144,7 +144,7 @@ let rec cnf_of_formula t =
mk t

(* convert a formula to DNF *)
let rec dnf_of_formula t =
let dnf_of_formula t =
let rec mk_left x y = match y with
| Block y -> mk_left x y
| Or (a,b) -> Or (mk_left x a, mk_left x b)
Expand Down Expand Up @@ -189,7 +189,7 @@ let to_cnf (t : t) =
| And _ -> assert false in
let rec aux t = match t with
| Empty -> []
| Block x -> assert false
| Block _ -> assert false
| Atom _
| Or _ -> [or_formula t]
| And(x,y) -> aux x @ aux y in
Expand All @@ -206,7 +206,7 @@ let to_dnf t =
| Or _ -> assert false in
let rec aux t = match t with
| Empty -> []
| Block x -> assert false
| Block _ -> assert false
| Atom _
| And _ -> [and_formula t]
| Or(x,y) -> aux x @ aux y in
Expand Down
4 changes: 2 additions & 2 deletions src/core/opamMisc.ml
Expand Up @@ -192,7 +192,7 @@ let ends_with ~suffix s =
&& String.sub s (String.length s - String.length suffix) (String.length suffix) = suffix

let remove_prefix ~prefix s =
if starts_with prefix s then
if starts_with ~prefix s then
Some (String.sub s (String.length prefix) (String.length s - String.length prefix))
else
None
Expand All @@ -215,7 +215,7 @@ let contains s c =
with Not_found -> false

let split s c =
Pcre.split (Re_perl.compile (Re.char c)) s
Pcre.split ~rex:(Re_perl.compile (Re.char c)) s

(* Remove from a ':' separated list of string the one with the given prefix *)
let reset_env_value ~prefix v =
Expand Down
6 changes: 0 additions & 6 deletions src/core/opamPackage.ml
Expand Up @@ -149,12 +149,6 @@ let to_map nv =
Name.Map.add name (Version.Set.add version versions) (Name.Map.remove name map)
) nv Name.Map.empty

let versions_of_packages nvset =
Set.fold
(fun nv vset -> Version.Set.add (version nv) vset)
nvset
Version.Set.empty

let opam_files dir =
if OpamFilename.exists_dir dir then (
let files = OpamFilename.list_files dir in
Expand Down

0 comments on commit 19de888

Please sign in to comment.