Permalink
Browse files

It is now possible to specify --jobs in the command line when install…

…ing/upgrading packages.

This overwrite the default configuration value which is in ~/.opam/config

You can also set OPAMJOBS

Priorities: command-line > env variables > default

Also, add a specific variable to store the actual value of jobs:

   opam config var jobs

This should fix #569
  • Loading branch information...
1 parent 57e39ef commit 7a4eb106109a2e8d22774c60c93463bb1e90b24b @samoht committed Apr 2, 2013
Showing with 43 additions and 12 deletions.
  1. +20 −6 src/client/opamMain.ml
  2. +2 −2 src/client/opamSolution.ml
  3. +13 −4 src/client/opamState.ml
  4. +3 −0 src/client/opamState.mli
  5. +5 −0 src/core/opamGlobals.ml
View
@@ -60,14 +60,16 @@ type build_options = {
cudf_file : string option;
fake : bool;
external_tags : string list;
+ jobs : int option;
}
let create_build_options
keep_build_dir make no_checksums build_test
- build_doc dryrun external_tags cudf_file fake = {
+ build_doc dryrun external_tags cudf_file fake
+ jobs = {
keep_build_dir; make; no_checksums;
build_test; build_doc; dryrun; external_tags;
- cudf_file; fake
+ cudf_file; fake; jobs
}
let set_build_options b =
@@ -79,6 +81,11 @@ let set_build_options b =
OpamGlobals.external_tags := b.external_tags;
OpamGlobals.cudf_file := b.cudf_file;
OpamGlobals.fake := b.fake;
+ OpamGlobals.jobs :=
+ begin match b.jobs with
+ | None -> !OpamGlobals.jobs
+ | Some j -> Some j
+ end;
match b.make with
| None -> ()
| Some s -> OpamGlobals.makecmd := (fun () -> s)
@@ -321,13 +328,20 @@ let build_options =
Arg.(some string) None in
let fake =
mk_flag ["fake"]
- "WARNING: This option is fo testing purposes only! Using this option without care is \
- the best way to corrupt your current compiler environement. When using this option \
- OPAM will run a dry-run of the solver and then fake the build and install commands" in
+ "WARNING: This option is fo testing purposes only! Using this option without \
+ care is the best way to corrupt your current compiler environement. When using \
+ this option OPAM will run a dry-run of the solver and then fake the build and \
+ install commands." in
+ let jobs =
+ mk_opt ["j";"jobs"] "JOBS"
+ "Set the maximal number of concurrent jobs to use. You can also set it using \
+ the OPAMJOBS environment variable."
+ Arg.(some int) None in
Term.(pure create_build_options
$keep_build_dir $make $no_checksums $build_test
- $build_doc $dryrun $external_tags $cudf_file $fake)
+ $build_doc $dryrun $external_tags $cudf_file $fake
+ $jobs)
let guess_repository_kind kind address =
match kind with
@@ -274,13 +274,13 @@ let parallel_apply t action solution =
| To_change (_, nv) -> add_to_install nv in
try
- let jobs = OpamFile.Config.jobs t.config in
(* 1/ We remove all installed packages appearing in the solution. *)
let deleted = OpamAction.remove_all_packages t ~metadata:true solution in
remove_from_install deleted;
(* 2/ We install the new packages *)
- PackageActionGraph.Parallel.parallel_iter jobs solution.to_process ~pre ~child ~post;
+ PackageActionGraph.Parallel.parallel_iter
+ (OpamState.jobs t) solution.to_process ~pre ~child ~post;
if !OpamGlobals.fake then
OpamGlobals.msg "Simulation complete.\n";
View
@@ -259,6 +259,11 @@ let pinned_path t name =
else
None
+let jobs t =
+ match !OpamGlobals.jobs with
+ | None -> OpamFile.Config.jobs t.config
+ | Some j -> j
+
(* List the packages which does fullfil the compiler constraints *)
let available_packages
root system opams installed prefixes repositories
@@ -354,7 +359,6 @@ let make_repository_name_map fn root config =
OpamRepositoryName.Map.empty
(OpamFile.Config.repositories config)
-
(* Only used during init: load only repository-related information *)
let load_repository_state call_site =
log "LOAD-REPO-STATE(%s)" call_site;
@@ -604,7 +608,8 @@ let load_state ?(save_cache=true) call_site =
let config =
let config = OpamFile.Config.read config_p in
if OpamFile.Config.opam_version config <> OpamVersion.current then (
- (* opam has been updated, so refresh the configuration file and clean-up the cache. *)
+ (* opam has been updated, so refresh the configuration file and
+ clean-up the cache. *)
let config = OpamFile.Config.with_current_opam_version config in
OpamFile.Config.write config_p config;
remove_state_cache ();
@@ -753,6 +758,8 @@ let contents_of_variable t v =
B (OpamFile.Comp.preinstalled (compiler t t.compiler))
else if var_str = "switch" then
S (OpamSwitch.to_string t.switch)
+ else if var_str = "jobs" then
+ S (string_of_int (jobs t))
else
read_var name
) else (
@@ -1323,6 +1330,7 @@ let add_switch root switch compiler =
(* install ~/.opam/<switch>/config/conf-ocaml.config *)
let install_conf_ocaml_config root switch =
log "install_conf_ocaml_config switch=%s" (OpamSwitch.to_string switch);
+
(* .config *)
let vars =
let map f l = List.rev_map (fun (s,p) -> OpamVariable.of_string s, S (f p)) l in
@@ -1348,7 +1356,9 @@ let install_conf_ocaml_config root switch =
] in
let config = OpamFile.Dot_config.create vars in
- OpamFile.Dot_config.write (OpamPath.Switch.config root switch OpamPackage.Name.default) config
+ OpamFile.Dot_config.write
+ (OpamPath.Switch.config root switch OpamPackage.Name.default)
+ config
(* - compiles and install $opam/compiler/[ocaml_version].comp in $opam/[switch]
- update $opam/switch
@@ -1546,4 +1556,3 @@ module Types = struct
repo_index: OpamFile.Repo_index.t;
}
end
-
View
@@ -264,6 +264,9 @@ val add_to_reinstall: state -> all:bool -> package_set -> unit
the new system compiler version as arguments. *)
val create_system_compiler_description: dirname -> compiler_version option -> unit
+(** {2 Jobs} *)
+val jobs: state -> int
+
(** {2 Misc} *)
(** Ask the user to press Y/y/N/n to continue *)
View
@@ -43,6 +43,11 @@ let print_stats = check "STATS"
let utf8_msgs = check "UTF8MSGS"
let autoremove = check "AUTOREMOVE"
+let jobs = ref (
+ try Some (int_of_string (OpamMisc.getenv "OPAMJOBS"))
+ with _ -> None
+ )
+
let download_retry =
try max 1 (int_of_string (OpamMisc.getenv "OPAMRETRY"))
with _ -> 10

0 comments on commit 7a4eb10

Please sign in to comment.