Skip to content

Commit

Permalink
Start fixing the converter from 0.3 to 0.4
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
samoht committed Aug 14, 2012
1 parent ae31909 commit f09920f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 118 deletions.
13 changes: 4 additions & 9 deletions Makefile
Expand Up @@ -2,13 +2,7 @@ BIN = /usr/local/bin
OCPBUILD ?= ./_obuild/unixrun ./boot/ocp-build.boot
OCAMLC=ocamlc
SRC_EXT=src_ext
TARGETS = opam opam-server \
opam-rsync-init opam-rsync-update opam-rsync-download opam-rsync-upload \
opam-curl-init opam-curl-update opam-curl-download opam-curl-upload \
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-repo-convert-0.3
TARGETS = opam opam-mk-repo opam-repo-convert-0.3

.PHONY: all

Expand Down Expand Up @@ -68,8 +62,9 @@ tests-git:
cp _obuild/$*/$*.asm $(BIN)/$*

.PHONY: install
install: $(TARGETS:%=%-install)
@
install:
rm $(BIN)/opam*
$(MAKE) $(TARGETS:%=%-install)

doc: compile
mkdir -p doc/html/
Expand Down
77 changes: 1 addition & 76 deletions opam.ocp
Expand Up @@ -53,61 +53,6 @@ end

(*


(* RSYNC *)
begin library "opam-rsync-lib"
files = [ "src/repo/rsync/rsync.ml" ]
requires = [ "opam-lib" ]
end

begin program "opam-rsync-init"
files = [ "src/repo/rsync/init.ml" ]
requires = [ "opam-rsync-lib" ]
end

begin program "opam-rsync-update"
files = [ "src/repo/rsync/update.ml" ]
requires = [ "opam-rsync-lib" ]
end

begin program "opam-rsync-download"
files = [ "src/repo/rsync/download.ml" ]
requires = [ "opam-rsync-lib" ]
end

begin program "opam-rsync-upload"
files = [ "src/repo/rsync/upload.ml" ]
requires = [ "opam-rsync-lib" ]
end


(* GIT *)
begin library "opam-git-lib"
files = [ "src/repo/git/git.ml" ]
requires = [ "opam-lib" ]
end

begin program "opam-git-init"
files = [ "src/repo/git/init.ml" ]
requires = [ "opam-git-lib" ]
end

begin program "opam-git-update"
files = [ "src/repo/git/update.ml" ]
requires = [ "opam-git-lib" ]
end

begin program "opam-git-download"
files = [ "src/repo/git/download.ml" ]
requires = [ "opam-git-lib" ]
end

begin program "opam-git-upload"
files = [ "src/repo/git/upload.ml" ]
requires = [ "opam-git-lib" ]
end


(* SERVER *)
begin library "opam-server-lib"
files = [
Expand All @@ -131,26 +76,6 @@ begin program "opam-server"
]
end

begin program "opam-server-init"
files = [ "src/repo/server/init.ml" ]
requires = [ "opam-server-lib" ]
end

begin program "opam-server-update"
files = [ "src/repo/server/update.ml" ]
requires = [ "opam-server-lib" ]
end

begin program "opam-server-download"
files = [ "src/repo/server/download.ml" ]
requires = [ "opam-server-lib" ]
end

begin program "opam-server-upload"
files = [ "src/repo/server/upload.ml" ]
requires = [ "opam-server-lib" ]
end

*)

(* Helpers *)
Expand All @@ -167,7 +92,7 @@ end

begin program "opam-mk-repo"
files = [ "src/scripts/opam_mk_repo.ml" ]
requires = [ "opam-curl-lib" ]
requires = [ "opam-lib" ]
end

begin program "opam-check"
Expand Down
4 changes: 2 additions & 2 deletions src/path.ml
Expand Up @@ -208,9 +208,9 @@ module R = struct

let files t nv = package t nv / "files"

let tmp_root t = t / "tmp"
let tmp t = t / "tmp"

let tmp_dir t nv = tmp_root t / NV.to_string nv
let tmp_dir t nv = tmp t / NV.to_string nv

let available_files t nv =
if Dirname.exists (files t nv) then
Expand Down
41 changes: 25 additions & 16 deletions src/repositories.mli
Expand Up @@ -20,41 +20,50 @@

open Types

(** Initialize {i $opam/repo/$repo} *)
val init: repository -> unit

(** Updated {i $opam/repo/$repo} *)
val update: repository -> unit

(** Run {i opam-$kind-download} in {i $opam/repo/$repo} *)
val download: repository -> nv -> unit

(** Upload the content of {i $opam/repo/$repo/upload} *)
val upload: repository -> unit

type kind = string

(** {2 Repository backends *)

(** Backend signature *)
module type BACKEND = sig

(** Initialize the repository *)
val init: repository -> unit

(** Update the repository. Return the list of updated files *)
(** Update the repository. Return the list of updated local files. *)
val update: repository -> Filename.Set.t

(** Download the package archive on the server *)
(** Download the package archive on the server. Return the local file. *)
val download_archive: repository -> nv -> filename download

(** Download a file *)
(** Download a file. Return the local file. Use {i $repo/tmp/$nv/}
as tempory location. *)
val download_file: repository -> nv -> filename -> filename download

(** Download a directory *)
(** Download a directory. Return the local directory. Use {i
$repo/tmp/$nv} as location to store transient state between
downloads. *)
val download_dir: repository -> nv -> dirname -> dirname download

(** Upload a local directory *)
(** Upload a local directory. Return the updated local files. *)
val upload_dir: repository -> dirname -> Filename.Set.t

end

(** Register a repository backend *)
val register_backend: kind -> (module BACKEND) -> unit

(** Initialize {i $opam/repo/$repo} *)
val init: repository -> unit

(** Updated {i $opam/repo/$repo} *)
val update: repository -> unit

(** Run {i opam-$kind-download} in {i $opam/repo/$repo} *)
val download: repository -> nv -> unit

(** Upload the content of {i $opam/repo/$repo/upload} *)
val upload: repository -> unit
(** Find a repository *)
val find_backend: repository -> (module BACKEND)
18 changes: 7 additions & 11 deletions src/scripts/opam_mk_repo.ml
Expand Up @@ -26,9 +26,7 @@
After the script is run, archives/ contains all the package archives
for the available descr and OPAM files *)

open Repo_helpers
open Types
open Curl

let all, index, packages =
let usage = Printf.sprintf "%s [-all] [<package>]*" (Stdlib_filename.basename Sys.argv.(0)) in
Expand All @@ -46,13 +44,8 @@ let all, index, packages =
let () =

let local_path = Dirname.cwd () in
let local_repo = Path.R.of_dirname local_path in
let state = {
local_path; local_repo;
remote_path = local_path;
remote_repo = local_repo;
} in
let repo = Repository.create ~name:"local" ~kind:"curl" ~address:(Dirname.to_string local_path) in
let local_repo = Path.R.create repo in

(* Create urls.txt *)
let local_index_file = Filename.of_string "urls.txt" in
Expand All @@ -71,22 +64,25 @@ let () =
) in
File.Urls_txt.write local_index_file urls;

let updates = Curl.get_updates state in
let module B = (val Repositories.find_backend repo: Repositories.BACKEND) in
let updates = B.update repo in
let packages =
NV.Set.of_list (Utils.filter_map NV.of_filename (Filename.Set.elements updates)) in

(* Update the archive files *)
NV.Set.iter (fun nv ->
Globals.msg "Updating %s as some file have changed\n" (NV.to_string nv);
if Filename.exists (Path.R.archive local_repo nv) then
Repositories.download repo nv
) updates;
) packages;

(* Create the archives asked by the user *)
NV.Set.iter (fun nv ->
if not index && (all || NV.Set.mem nv packages) then begin
Globals.msg "Creating archive for %s\n" (NV.to_string nv);
Repositories.download repo nv
end
) updates;
) packages;

(* Create index.tar.gz *)
let err = Run.command [
Expand Down
29 changes: 25 additions & 4 deletions src/scripts/opam_repo_convert.ml
Expand Up @@ -34,7 +34,7 @@ module Syntax = struct
(String.concat ", " fields)
end

module X = struct
module OPAM_X = struct

let internal = "opam"

Expand Down Expand Up @@ -243,6 +243,16 @@ module X = struct
ocaml_version; build_env }
end

module URL_X = struct
let internal = "url"
type t = string
let empty = "<none>"
let to_string f t =
Raw.of_string (Utils.string_strip t)
let of_string f t =
Utils.string_strip (Raw.to_string t)
end

module type F = sig
val internal : string
type t
Expand Down Expand Up @@ -292,10 +302,14 @@ module Make (F : F) = struct
end

module OPAM = struct
include X
include Make (X)
include OPAM_X
include Make (OPAM_X)
end

module URL = struct
include URL_X
include Make (URL_X)
end
end

module Path_0_3 = struct
Expand Down Expand Up @@ -395,7 +409,14 @@ end
end

let () =
let open File_0_3.X in
let usage = Printf.sprintf "Usage: %s" Sys.argv.(0) in
let specs = [] in
let ano x =
Printf.eprintf "%s: invalid argument" x in
Arg.parse specs ano usage

let () =
let open File_0_3.OPAM_X in
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 ->
Expand Down

0 comments on commit f09920f

Please sign in to comment.