Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

opam-repo-convert + opam init works

  • Loading branch information...
commit cf68a8017a6f94d9540472689468527802221434 1 parent 16ef5d7
Thomas Gazagnaire samoht authored
2  Makefile
@@ -8,7 +8,7 @@ TARGETS = opam opam-server \
8 8 opam-git-init opam-git-update opam-git-download opam-git-upload \
9 9 opam-server-init opam-server-update opam-server-download opam-server-upload \
10 10 opam-mk-config opam-mk-install opam-mk-repo \
11   - opam-convert-0.3
  11 + opam-repo-convert-0.3
12 12
13 13 .PHONY: all
14 14
12 src/file.ml
@@ -543,8 +543,8 @@ module OPAM = struct
543 543 filename = Filename.to_string filename;
544 544 contents = [
545 545 Variable (s_opam_version, String Globals.opam_version);
546   - Variable (s_name, String (N.to_string t.name));
547   - Variable (s_version, String (V.to_string t.version));
  546 +(* Variable (s_name, String (N.to_string t.name));
  547 + Variable (s_version, String (V.to_string t.version)); *)
548 548 Variable (s_maintainer, String t.maintainer);
549 549 Variable (s_substs, make_list (Basename.to_string |> make_string) t.substs);
550 550 Variable (s_build_env, make_list make_env_variable t.build_env);
@@ -578,9 +578,7 @@ module OPAM = struct
578 578 let opam_version = assoc s s_opam_version parse_string in
579 579 if opam_version <> Globals.opam_version then
580 580 Globals.error_and_exit "%s is not a supported OPAM version" opam_version;
581   - let name_f =
582   - try Some (assoc s s_name (parse_string |> N.of_string))
583   - with Not_found -> None in
  581 + let name_f = assoc_option s s_name (parse_string |> N.of_string) in
584 582 let name = match name_f, nv with
585 583 | None , None ->
586 584 Globals.error_and_exit "%s is an invalid OPAM filename" (Filename.to_string filename);
@@ -593,9 +591,7 @@ module OPAM = struct
593 591 (Filename.to_string filename)
594 592 else
595 593 n in
596   - let version_f =
597   - try Some (assoc s s_version (parse_string |> V.of_string))
598   - with Not_found -> None in
  594 + let version_f = assoc_option s s_version (parse_string |> V.of_string) in
599 595 let version = match version_f, nv with
600 596 | None , None ->
601 597 Globals.error_and_exit "%s is an invalid OPAM filename" (Filename.to_string filename);
38 src/file_format.ml
@@ -191,6 +191,30 @@ let make_string_pair = make_pair make_string
191 191
192 192 (* Printing *)
193 193
  194 +let is_list = function
  195 + | List _ -> true
  196 + | _ -> false
  197 +
  198 +let rec pretty_string_of_value = function
  199 + | Symbol s
  200 + | Ident s -> Printf.sprintf "%s" s
  201 + | Int i -> Printf.sprintf "%d" i
  202 + | Bool b -> Printf.sprintf "%b" b
  203 + | String s -> Printf.sprintf "%S" s
  204 + | List l ->
  205 + if List.for_all is_list l then
  206 + Printf.sprintf "[\n %s\n]" (pretty_string_of_values "\n " l)
  207 + else
  208 + Printf.sprintf "[%s]" (pretty_string_of_values " " l)
  209 + | Group g -> Printf.sprintf "(%s)" (pretty_string_of_values " " g)
  210 + | Option(v,l) ->
  211 + Printf.sprintf "%s {%s}"
  212 + (pretty_string_of_value v)
  213 + (pretty_string_of_values " " l)
  214 +
  215 +and pretty_string_of_values sep l =
  216 + String.concat sep (List.map pretty_string_of_value l)
  217 +
194 218 let rec string_of_value = function
195 219 | Symbol s
196 220 | Ident s -> Printf.sprintf "%s" s
@@ -202,25 +226,25 @@ let rec string_of_value = function
202 226 | Option(v,l) -> Printf.sprintf "%s {%s}" (string_of_value v) (string_of_values l)
203 227
204 228 and string_of_values l =
205   - String.concat " " (List.map string_of_value l)
  229 + String.concat " " (List.map string_of_value l)
206 230
207 231 let incr tab = " " ^ tab
208 232
209 233 let rec string_of_item_aux tab = function
210   - | Variable (i, List []) -> ""
211   - | Variable (i, v) -> Printf.sprintf "%s%s: %s" tab i (string_of_value v)
  234 + | Variable (i, List []) -> None
  235 + | Variable (i, v) -> Some (Printf.sprintf "%s%s: %s" tab i (pretty_string_of_value v))
212 236 | Section s ->
213   - Printf.sprintf "%s%s %S {\n%s\n}"
  237 + Some (Printf.sprintf "%s%s %S {\n%s\n}"
214 238 tab s.kind s.name
215   - (string_of_items_aux (incr tab) s.items)
  239 + (string_of_items_aux (incr tab) s.items))
216 240
217 241 and string_of_items_aux tab is =
218   - String.concat "\n" (List.map (string_of_item_aux tab) is)
  242 + String.concat "\n" (Utils.filter_map (string_of_item_aux tab) is)
219 243
220 244 let string_of_item = string_of_item_aux ""
221 245 let string_of_items = string_of_items_aux ""
222 246
223   -let string_of_file f = string_of_items f.contents
  247 +let string_of_file f = string_of_items f.contents ^ "\n"
224 248
225 249 (* Reading section contents *)
226 250
2  src/file_format.mli
@@ -156,7 +156,7 @@ val string_of_value : value -> string
156 156 val string_of_values : value list -> string
157 157
158 158 (** Print an item *)
159   -val string_of_item : item -> string
  159 +val string_of_item : item -> string option
160 160
161 161 (** Print a list of items *)
162 162 val string_of_items : item list -> string
6 src/scripts/opam_repo_convert.ml
@@ -399,9 +399,12 @@ let () =
399 399 let t3 = Path_0_3.R.of_path (Dirname.cwd ()) in
400 400 let t4 = Path.R.of_dirname (Dirname.cwd ()) in
401 401 NV.Set.iter (fun nv ->
  402 + Globals.msg "Processing %s\n" (NV.to_string nv);
402 403 let opam3 = File_0_3.OPAM.read (Path_0_3.R.opam t3 nv) in
  404 + let maintainer =
  405 + if opam3.maintainer = "<none>" then "contact@ocamlpro.com" else opam3.maintainer in
403 406 let opam4 = File.OPAM.make
404   - ~name:opam3.name ~version:opam3.version ~maintainer:opam3.maintainer
  407 + ~name:opam3.name ~version:opam3.version ~maintainer
405 408 ~substs:opam3.substs ~build_env:opam3.build_env ~build:opam3.build
406 409 ~remove:opam3.remove ~depends:opam3.depends ~depopts:opam3.depopts
407 410 ~conflicts:opam3.conflicts ~libraries:opam3.libraries ~syntax:opam3.syntax
@@ -413,7 +416,6 @@ let () =
413 416 let mv_dir src dst =
414 417 if Dirname.exists (src t3 nv) then
415 418 Dirname.move (src t3 nv) (dst t4 nv) in
416   - mv_file Path_0_3.R.opam Path.R.opam;
417 419 mv_file Path_0_3.R.descr Path.R.descr;
418 420 mv_file Path_0_3.R.url Path.R.url;
419 421 mv_dir Path_0_3.R.files Path.R.files;
2  src/solver.ml
@@ -161,7 +161,7 @@ let string_of_package p =
161 161 && List.assoc "status" p.Debian.Packages.extras = " installed"
162 162 then "installed"
163 163 else "not-installed" in
164   - Printf.sprintf "%s.%s(%s)"
  164 + Printf.sprintf "%s::%s(%s)"
165 165 p.Debian.Packages.name p.Debian.Packages.version installed
166 166
167 167 let string_of_packages l =
8 src/types.ml
@@ -441,9 +441,11 @@ end = struct
441 441 let sep = '.'
442 442
443 443 let check s =
444   - match Utils.cut_at s sep with
445   - | None -> None
446   - | Some (n, v) -> Some { name = N.of_string n; version = V.of_string v }
  444 + if Utils.contains s ' ' || Utils.contains s '\n' then
  445 + None
  446 + else match Utils.cut_at s sep with
  447 + | None -> None
  448 + | Some (n, v) -> Some { name = N.of_string n; version = V.of_string v }
447 449
448 450 let of_string s = match check s with
449 451 | Some x -> x
4 src/utils.ml
@@ -78,6 +78,10 @@ let cut_at = cut_at_aux String.index
78 78
79 79 let rcut_at = cut_at_aux String.rindex
80 80
  81 +let contains s c =
  82 + try let _ = String.index s c in true
  83 + with Not_found -> false
  84 +
81 85 let split s c =
82 86 Pcre.split (Pcre.regexp (String.make 1 c)) s
83 87
8 src_ext/depends.ocp.boot
... ... @@ -1,3 +1,7 @@
  1 +begin
  2 +
  3 +comp += [ "-g" ]
  4 +link += [ "-g" ]
1 5
2 6 begin library "extlib"
3 7 sort = true
@@ -192,4 +196,6 @@ begin program "cnftocudf"
192 196 requires = [ "dose" ]
193 197 end
194 198
195   -*)
  199 +*)
  200 +
  201 +end

0 comments on commit cf68a80

Please sign in to comment.
Something went wrong with that request. Please try again.