Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opam-admin depexts #886

Merged
merged 4 commits into from Sep 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
_obuild/
.*.swp
src_ext/cudf/
src_ext/dose/
src_ext/cmdliner/
Expand Down
4 changes: 4 additions & 0 deletions CHANGES
@@ -1,3 +1,7 @@
1.1.0-trunk
* Document use of `OPAMCOLOR` for optional ANSI coloring
* Add `opam-admin depexts` utility to rewrite OPAM files with external dependencies

1.1.0-beta [Sept 2013]
* Automatic backup before any operation which might alter the list of installed packages
* Support for arbitrary sub-directories for metadata repositories
Expand Down
1 change: 1 addition & 0 deletions src/core/opamFile.ml
Expand Up @@ -860,6 +860,7 @@ module X = struct
let with_maintainer t maintainer = { t with maintainer }
let with_patches t patches = { t with patches }
let with_bug_reports t bug_reports = { t with bug_reports }
let with_depexts t depexts = { t with depexts }

let to_string filename t =
let make_file =
Expand Down
3 changes: 3 additions & 0 deletions src/core/opamFile.mli
Expand Up @@ -207,6 +207,9 @@ module OPAM: sig
(** Construct using [bug_reports] *)
val with_bug_reports: t -> string list -> t

(** Construct using [depexts] *)
val with_depexts: t -> tags option -> t

end

(** Package descriptions: [$opam/descr/] *)
Expand Down
7 changes: 6 additions & 1 deletion src/scripts/opam_admin.ml
Expand Up @@ -36,11 +36,16 @@ let stats_cmd =
Term.(Opam_stats.(pure process $ pure ())),
Term.info "stats" ~doc

let depexts_cmd =
let doc = "Add external dependencies." in
Term.(Opam_depexts_change.(pure process $ args)),
Term.info "depexts" ~doc

let () =
try
match
Term.eval_choice ~catch:false
default_cmd [make_repo_cmd; check_repo_cmd; stats_cmd]
default_cmd [make_repo_cmd; check_repo_cmd; stats_cmd; depexts_cmd]
with
| `Error _ -> exit 2
| _ -> exit 0
Expand Down
68 changes: 68 additions & 0 deletions src/scripts/opam_depexts_change.ml
@@ -0,0 +1,68 @@
(**************************************************************************)
(* *)
(* Copyright 2012-2013 OCamlPro *)
(* Copyright 2012 INRIA *)
(* *)
(* All rights reserved.This file is distributed under the terms of the *)
(* GNU Lesser General Public License version 3.0 with linking *)
(* exception. *)
(* *)
(* OPAM is distributed in the hope that it will be useful, but WITHOUT *)
(* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)
(* or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public *)
(* License for more details. *)
(* *)
(**************************************************************************)

(* Script to check that a given repository is well-typed (or well-parsed) *)
open OpamTypes
open OpamFilename.OP

type args = {
pkg: name;
os: string list;
deps: string list;
}

let args =
let open Cmdliner in
let os =
let doc = "Operating system tag" in
Arg.(value & opt_all string [] & info ["os"] ~doc)
in
let deps =
let doc = "Extdep tag" in
Arg.(value & opt_all string [] & info ["dep"] ~doc)
in
let pkg =
let doc = "OPAM package name" in
Arg.(required & pos 1 (some OpamArg.package_name) None & info [] ~doc)
in
Term.(pure (fun os deps pkg -> { os; deps; pkg }) $ os $ deps $ pkg)

let process args =

let repo = OpamRepository.local (OpamFilename.cwd ()) in

let packages = OpamRepository.packages_with_prefixes repo in

(** packages *)
OpamPackage.Map.iter (fun package prefix ->
OpamGlobals.msg "Processing (package) %s\n" (OpamPackage.to_string package);
(** OPAM *)
let opam_f = OpamPath.Repository.opam repo prefix package in
let opam = OpamFile.OPAM.read opam_f in
let pkgname = OpamFile.OPAM.name opam in
if pkgname = args.pkg then begin
let depexts =
let os = OpamMisc.StringSet.of_list args.os in
let deps = OpamMisc.StringSet.of_list args.deps in
match OpamFile.OPAM.depexts opam with
| None -> OpamMisc.StringSetMap.of_list [ os, deps ]
| Some depexts' -> (* TODO: Replace existing entry? *)
OpamMisc.StringSetMap.add os deps depexts'
in
let opam = OpamFile.OPAM.with_depexts opam (Some depexts) in
OpamFile.OPAM.write opam_f opam;
end;
) packages
2 changes: 1 addition & 1 deletion src/scripts/scripts.ocp
Expand Up @@ -6,6 +6,6 @@ begin program "opam-check"
end

begin program "opam-admin"
files = [ "opam_mk_repo.ml" "opam_repo_check.ml" "opam_stats.ml" "opam_admin.ml" ]
files = [ "opam_mk_repo.ml" "opam_repo_check.ml" "opam_stats.ml" "opam_depexts_change.ml" "opam_admin.ml" ]
requires = [ "opam-client" ]
end