Skip to content

Commit

Permalink
Fix opam-mk-repo script
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht committed Aug 22, 2012
1 parent 3c80380 commit 68b1fc8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
7 changes: 6 additions & 1 deletion opam.ocp
Expand Up @@ -52,7 +52,12 @@ end
(* Helpers *)

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

Expand Down
1 change: 1 addition & 0 deletions src/repositories.ml
Expand Up @@ -157,6 +157,7 @@ let make_archive nv =
(* And finally create the final archive *)
(* XXX: we should add a suffix to the version to show that
the archive has been repacked by opam *)
Dirname.mkdir (Path.R.archives_dir local_repo);
let local_archive = Path.R.archive local_repo nv in
log "Creating the archive files in %s" (Filename.to_string local_archive);
let err = Dirname.exec extract_root [
Expand Down
14 changes: 8 additions & 6 deletions src/run.ml
Expand Up @@ -117,12 +117,14 @@ let in_dir dir fn =
raise e

let list kind dir =
in_dir dir (fun () ->
let d = Sys.readdir (Unix.getcwd ()) in
let d = Array.to_list d in
let l = List.filter kind d in
List.sort compare (List.map (Filename.concat dir) l)
)
if Sys.file_exists dir then
in_dir dir (fun () ->
let d = Sys.readdir (Unix.getcwd ()) in
let d = Array.to_list d in
let l = List.filter kind d in
List.sort compare (List.map (Filename.concat dir) l))
else
[]

let files_with_links =
list (fun f -> try not (Sys.is_directory f) with _ -> true)
Expand Down
46 changes: 33 additions & 13 deletions src/scripts/opam_mk_repo.ml
Expand Up @@ -15,19 +15,17 @@

(* A script helper to initialize an OPAM repo.
It takes as input a directory where:
* opam/ contains some OPAM files
* descr/ contains some description files
* packages/ contains packages meta-files
* archives/ might contain some archive
* url/$name.$version contains archive address
* files/$name.$version contains some files to include in
the archives (typically .config.in
and .install)
* compilers/ contains compiler descriptions
After the script is run, archives/ contains all the package archives
for the available descr and OPAM files *)
After the script is run with -all, archives/ contains all the
package archives for the available package meta-files *)

open Types

let log fmt = Globals.log "OPAM-MK-REPO" fmt

let all, index, packages =
let usage = Printf.sprintf "%s [-all] [<package>]*" (Stdlib_filename.basename Sys.argv.(0)) in
let all = ref true in
Expand Down Expand Up @@ -65,12 +63,31 @@ let () =
)) in
File.Urls_txt.write local_index_file new_index;

let to_remove = Remote_file.Set.diff old_index new_index in
let to_add = Remote_file.Set.diff new_index old_index in

let nv_set_of_remotes remotes =
let aux r = Filename.create (Dirname.cwd ()) (Remote_file.base r) in
let list = List.map aux (Remote_file.Set.elements remotes) in
NV.Set.of_list (Utils.filter_map NV.of_filename list) in
let to_remove = nv_set_of_remotes (Remote_file.Set.diff old_index new_index) in
let to_add = nv_set_of_remotes (Remote_file.Set.diff new_index old_index) in
let new_index = nv_set_of_remotes new_index in
let missing_archive =
NV.Set.filter (fun nv ->
let archive = Path.R.archive local_repo nv in
not (Filename.exists archive)
) new_index in
let to_remove = nv_set_of_remotes to_remove in
let to_add = NV.Set.union (nv_set_of_remotes to_add) missing_archive in
let to_add =
if NV.Set.is_empty packages then
to_add
else
NV.Set.inter packages to_add in

if not (NV.Set.is_empty to_remove) then
Globals.msg "Packages to remove: %s\n" (NV.Set.to_string to_remove);
if not (NV.Set.is_empty to_add) then
Globals.msg "Packages to build: %s\n" (NV.Set.to_string to_add);

(* Remove the old archive files *)
NV.Set.iter (fun nv ->
Expand All @@ -79,12 +96,15 @@ let () =
Filename.remove archive
) to_remove;

let to_add = NV.Set.inter packages to_add in
NV.Set.iter Repositories.make_archive to_add;

(* Create index.tar.gz *)
let dirs = [ "compilers"; "packages"; "archives" ] in
let dirs = List.filter Sys.file_exists dirs in
let err = Run.command [
"sh"; "-c"; "tar cz compilers opam descr > index.tar.gz"
"sh"; "-c"; "tar cz " ^ (String.concat " " dirs) ^ "> index.tar.gz"
] in
if err <> 0 then
Globals.error_and_exit "Cannot create index.tar.gz"
Globals.error_and_exit "Cannot create index.tar.gz";

Unix.rmdir "log"
19 changes: 11 additions & 8 deletions src/types.ml
Expand Up @@ -488,19 +488,22 @@ end = struct
else begin
let base = F.basename f in
let parent = F.basename (F.dirname f) in
match parent with
| "." -> None
| "package" -> check base
| "file" ->
(* XXX: make it work for sub-folders of packages/files/ *)
of_filename (Filename.of_string parent)
match base with
| "opam" | "descr" | "url" ->
check parent
| _ ->
if F.check_suffix base ".opam" then
check (F.chop_suffix base ".opam")
else if F.check_suffix base ".tar.gz" then
check (F.chop_suffix base ".tar.gz")
else
None
match parent with
| "files" ->
let parent2 = F.basename (F.dirname (F.dirname f)) in
check parent2
| _ ->
(* XXX: handle the case with a deeper files hierarchy *)
None
end

let of_dirname d =
Expand Down Expand Up @@ -924,7 +927,7 @@ end = struct
let to_string t =
let perm = match t.perm with
| None -> ""
| Some p -> Printf.sprintf " o%o" p in
| Some p -> Printf.sprintf " 0o%o" p in
Printf.sprintf "%s %s%s" (Basename.to_string t.base) t.md5 perm

let of_string s =
Expand Down

0 comments on commit 68b1fc8

Please sign in to comment.