Skip to content

Commit

Permalink
Merge pull request #1693 from OCamlPro/small-api-extension
Browse files Browse the repository at this point in the history
Small API extension to help opam-publish
  • Loading branch information
AltGr committed Sep 3, 2014
2 parents fbc530d + d00159f commit dd8444a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
13 changes: 13 additions & 0 deletions admin-scripts/lint.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env opam-admin.top

#directory "+../opam-lib";;
open Opam_admin_top;;

iter_packages ~opam:(fun nv opam ->
match OpamFile.OPAM.validate opam with
| [] -> opam
| w ->
OpamGlobals.warning "In %s:\n - %s\n"
(OpamPackage.to_string nv) (String.concat "\n - " w);
opam
) ()
22 changes: 18 additions & 4 deletions src/core/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,18 @@ module X = struct
OpamGlobals.error_and_exit "Invalid OPAM file (missing field %S)" name
| Some n -> n

let is_explicit filename =
try
let ic = OpamFilename.open_in filename in
try
let file = Syntax.of_channel filename ic in
let fields = OpamFormat.variables file.file_contents in
List.exists (fun (f,_) -> f = s_name || f = s_version) fields
with e ->
close_in ic;
raise e
with e -> OpamMisc.fatal e; false

let name t = check "name" t.name
let name_opt t = t.name
let version t = check "version" t.version
Expand Down Expand Up @@ -2114,10 +2126,12 @@ module Make (F : F) = struct
if OpamFilename.exists f then
try
let ic = OpamFilename.open_in f in
let r = F.of_channel f ic in
close_in ic;
log ~level:2 "Read %s in %.3fs" filename (chrono ());
r
try
let r = F.of_channel f ic in
close_in ic;
log ~level:2 "Read %s in %.3fs" filename (chrono ());
r
with e -> close_in ic; raise e
with
| Lexer_error _ | Parsing.Parse_error as e ->
if !OpamGlobals.strict then
Expand Down
3 changes: 3 additions & 0 deletions src/core/opamFile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ module OPAM: sig
warnings *)
val validate: t -> string list

(** Returns true if the given OPAM file contains 'name' or 'version' fields *)
val is_explicit: filename -> bool

(** Get OPAM version. *)
val opam_version: t -> opam_version

Expand Down
2 changes: 2 additions & 0 deletions src/core/opamSystem.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(** Exception raised when subprocess fails *)
exception Process_error of OpamProcess.result

exception Command_not_found of string

(** raise [Process_error] *)
val process_error: OpamProcess.result -> 'a

Expand Down

0 comments on commit dd8444a

Please sign in to comment.