Permalink
Browse files

opam-repo-convert + opam init works

  • Loading branch information...
1 parent 16ef5d7 commit cf68a8017a6f94d9540472689468527802221434 @samoht samoht committed Jul 29, 2012
Showing with 58 additions and 24 deletions.
  1. +1 −1 Makefile
  2. +4 −8 src/file.ml
  3. +31 −7 src/file_format.ml
  4. +1 −1 src/file_format.mli
  5. +4 −2 src/scripts/opam_repo_convert.ml
  6. +1 −1 src/solver.ml
  7. +5 −3 src/types.ml
  8. +4 −0 src/utils.ml
  9. +7 −1 src_ext/depends.ocp.boot
View
@@ -8,7 +8,7 @@ TARGETS = opam opam-server \
opam-git-init opam-git-update opam-git-download opam-git-upload \
opam-server-init opam-server-update opam-server-download opam-server-upload \
opam-mk-config opam-mk-install opam-mk-repo \
- opam-convert-0.3
+ opam-repo-convert-0.3
.PHONY: all
View
@@ -543,8 +543,8 @@ module OPAM = struct
filename = Filename.to_string filename;
contents = [
Variable (s_opam_version, String Globals.opam_version);
- Variable (s_name, String (N.to_string t.name));
- Variable (s_version, String (V.to_string t.version));
+(* Variable (s_name, String (N.to_string t.name));
+ Variable (s_version, String (V.to_string t.version)); *)
Variable (s_maintainer, String t.maintainer);
Variable (s_substs, make_list (Basename.to_string |> make_string) t.substs);
Variable (s_build_env, make_list make_env_variable t.build_env);
@@ -578,9 +578,7 @@ module OPAM = struct
let opam_version = assoc s s_opam_version parse_string in
if opam_version <> Globals.opam_version then
Globals.error_and_exit "%s is not a supported OPAM version" opam_version;
- let name_f =
- try Some (assoc s s_name (parse_string |> N.of_string))
- with Not_found -> None in
+ let name_f = assoc_option s s_name (parse_string |> N.of_string) in
let name = match name_f, nv with
| None , None ->
Globals.error_and_exit "%s is an invalid OPAM filename" (Filename.to_string filename);
@@ -593,9 +591,7 @@ module OPAM = struct
(Filename.to_string filename)
else
n in
- let version_f =
- try Some (assoc s s_version (parse_string |> V.of_string))
- with Not_found -> None in
+ let version_f = assoc_option s s_version (parse_string |> V.of_string) in
let version = match version_f, nv with
| None , None ->
Globals.error_and_exit "%s is an invalid OPAM filename" (Filename.to_string filename);
View
@@ -191,6 +191,30 @@ let make_string_pair = make_pair make_string
(* Printing *)
+let is_list = function
+ | List _ -> true
+ | _ -> false
+
+let rec pretty_string_of_value = function
+ | Symbol s
+ | Ident s -> Printf.sprintf "%s" s
+ | Int i -> Printf.sprintf "%d" i
+ | Bool b -> Printf.sprintf "%b" b
+ | String s -> Printf.sprintf "%S" s
+ | List l ->
+ if List.for_all is_list l then
+ Printf.sprintf "[\n %s\n]" (pretty_string_of_values "\n " l)
+ else
+ Printf.sprintf "[%s]" (pretty_string_of_values " " l)
+ | Group g -> Printf.sprintf "(%s)" (pretty_string_of_values " " g)
+ | Option(v,l) ->
+ Printf.sprintf "%s {%s}"
+ (pretty_string_of_value v)
+ (pretty_string_of_values " " l)
+
+and pretty_string_of_values sep l =
+ String.concat sep (List.map pretty_string_of_value l)
+
let rec string_of_value = function
| Symbol s
| Ident s -> Printf.sprintf "%s" s
@@ -202,25 +226,25 @@ let rec string_of_value = function
| Option(v,l) -> Printf.sprintf "%s {%s}" (string_of_value v) (string_of_values l)
and string_of_values l =
- String.concat " " (List.map string_of_value l)
+ String.concat " " (List.map string_of_value l)
let incr tab = " " ^ tab
let rec string_of_item_aux tab = function
- | Variable (i, List []) -> ""
- | Variable (i, v) -> Printf.sprintf "%s%s: %s" tab i (string_of_value v)
+ | Variable (i, List []) -> None
+ | Variable (i, v) -> Some (Printf.sprintf "%s%s: %s" tab i (pretty_string_of_value v))
| Section s ->
- Printf.sprintf "%s%s %S {\n%s\n}"
+ Some (Printf.sprintf "%s%s %S {\n%s\n}"
tab s.kind s.name
- (string_of_items_aux (incr tab) s.items)
+ (string_of_items_aux (incr tab) s.items))
and string_of_items_aux tab is =
- String.concat "\n" (List.map (string_of_item_aux tab) is)
+ String.concat "\n" (Utils.filter_map (string_of_item_aux tab) is)
let string_of_item = string_of_item_aux ""
let string_of_items = string_of_items_aux ""
-let string_of_file f = string_of_items f.contents
+let string_of_file f = string_of_items f.contents ^ "\n"
(* Reading section contents *)
View
@@ -156,7 +156,7 @@ val string_of_value : value -> string
val string_of_values : value list -> string
(** Print an item *)
-val string_of_item : item -> string
+val string_of_item : item -> string option
(** Print a list of items *)
val string_of_items : item list -> string
@@ -399,9 +399,12 @@ let () =
let t3 = Path_0_3.R.of_path (Dirname.cwd ()) in
let t4 = Path.R.of_dirname (Dirname.cwd ()) in
NV.Set.iter (fun nv ->
+ Globals.msg "Processing %s\n" (NV.to_string nv);
let opam3 = File_0_3.OPAM.read (Path_0_3.R.opam t3 nv) in
+ let maintainer =
+ if opam3.maintainer = "<none>" then "contact@ocamlpro.com" else opam3.maintainer in
let opam4 = File.OPAM.make
- ~name:opam3.name ~version:opam3.version ~maintainer:opam3.maintainer
+ ~name:opam3.name ~version:opam3.version ~maintainer
~substs:opam3.substs ~build_env:opam3.build_env ~build:opam3.build
~remove:opam3.remove ~depends:opam3.depends ~depopts:opam3.depopts
~conflicts:opam3.conflicts ~libraries:opam3.libraries ~syntax:opam3.syntax
@@ -413,7 +416,6 @@ let () =
let mv_dir src dst =
if Dirname.exists (src t3 nv) then
Dirname.move (src t3 nv) (dst t4 nv) in
- mv_file Path_0_3.R.opam Path.R.opam;
mv_file Path_0_3.R.descr Path.R.descr;
mv_file Path_0_3.R.url Path.R.url;
mv_dir Path_0_3.R.files Path.R.files;
View
@@ -161,7 +161,7 @@ let string_of_package p =
&& List.assoc "status" p.Debian.Packages.extras = " installed"
then "installed"
else "not-installed" in
- Printf.sprintf "%s.%s(%s)"
+ Printf.sprintf "%s::%s(%s)"
p.Debian.Packages.name p.Debian.Packages.version installed
let string_of_packages l =
View
@@ -441,9 +441,11 @@ end = struct
let sep = '.'
let check s =
- match Utils.cut_at s sep with
- | None -> None
- | Some (n, v) -> Some { name = N.of_string n; version = V.of_string v }
+ if Utils.contains s ' ' || Utils.contains s '\n' then
+ None
+ else match Utils.cut_at s sep with
+ | None -> None
+ | Some (n, v) -> Some { name = N.of_string n; version = V.of_string v }
let of_string s = match check s with
| Some x -> x
View
@@ -78,6 +78,10 @@ let cut_at = cut_at_aux String.index
let rcut_at = cut_at_aux String.rindex
+let contains s c =
+ try let _ = String.index s c in true
+ with Not_found -> false
+
let split s c =
Pcre.split (Pcre.regexp (String.make 1 c)) s
View
@@ -1,3 +1,7 @@
+begin
+
+comp += [ "-g" ]
+link += [ "-g" ]
begin library "extlib"
sort = true
@@ -192,4 +196,6 @@ begin program "cnftocudf"
requires = [ "dose" ]
end
-*)
+*)
+
+end

0 comments on commit cf68a80

Please sign in to comment.