Skip to content

Commit

Permalink
From now on, the only reason to recompile a package becomes "it has c…
Browse files Browse the repository at this point in the history
…hanged upstream"

This means we do nothing if the 'opam' file has changed, which means: we can now modify 'opam' files without fear (eg. we can add more metadata when we need it).

This should fix ocaml#497
  • Loading branch information
samoht committed Feb 26, 2013
1 parent 434ae1a commit 5e76bc9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/core/opamFile.ml
Expand Up @@ -751,7 +751,7 @@ module OPAM = struct
s
let of_string filename str =
let nv = OpamPackage.of_filename filename in
let nv = OpamPackage.of_filename ~all:true filename in
let s = Syntax.of_string filename str in
Syntax.check s valid_fields;
let s = s.file_contents in
Expand Down
22 changes: 6 additions & 16 deletions src/core/opamPackage.ml
Expand Up @@ -92,13 +92,15 @@ let of_string s = match of_string_opt s with

(* XXX: this function is quite hackish, as it mainly depends on the shape the paths
built in path.ml *)
let of_filename f =
let of_filename ~all f =
let f = OpamMisc.strip (OpamFilename.to_string f) in
let base = Filename.basename f in
let parent = Filename.basename (Filename.dirname f) in
match base with
| "opam" | "url" -> of_string_opt parent
| _ ->
| "descr"
| "opam" -> if all then of_string_opt parent else None
| "url" -> of_string_opt parent
| _ ->
if Filename.check_suffix base ".opam" then
of_string_opt (Filename.chop_suffix base ".opam")
else if Filename.check_suffix base "+opam.tar.gz" then
Expand Down Expand Up @@ -149,26 +151,14 @@ let to_map nv =
Name.Map.add name (Version.Set.add version versions) (Name.Map.remove name map)
) nv Name.Map.empty

let opam_files dir =
if OpamFilename.exists_dir dir then (
let files = OpamFilename.list_files dir in
let files = List.filter (fun f -> OpamFilename.check_suffix f ".opam") files in
List.fold_left (fun set file ->
match of_filename file with
| None -> set
| Some nv -> Set.add nv set
) Set.empty files
) else
Set.empty

let list dir =
log "list %s" (OpamFilename.Dir.to_string dir);
if OpamFilename.exists_dir dir then (
let dot_opams =
let files = OpamFilename.list_files dir in
let files = List.filter (fun f -> OpamFilename.check_suffix f ".opam") files in
List.fold_left (fun set file ->
match of_filename file with
match of_filename ~all:true file with
| None ->
log "%s is not a valid package filename!" (OpamFilename.to_string file);
set
Expand Down
10 changes: 4 additions & 6 deletions src/core/opamPackage.mli
Expand Up @@ -48,9 +48,10 @@ val version: t -> Version.t
val create: Name.t -> Version.t -> t

(** Create a new pair from a filename. This function extracts {i
$name} and {i $version} from {i /path/to/$name.$version.XXX}
with various heuristics.*)
val of_filename: OpamFilename.t -> t option
$name} and {i $version} from {i /path/to/$name.$version.XXX} with
various heuristics. If [all] is unset, discard "opam" and "url"
files. *)
val of_filename: all:bool -> OpamFilename.t -> t option

(** Create a new pair from a directory name. This function extracts {i
$name} and {i $version} from {i /path/to/$name.$version/} *)
Expand All @@ -71,9 +72,6 @@ val names_of_packages: Set.t -> Name.Set.t
(** Return all the packages with the given names *)
val packages_of_name: Set.t -> Name.t -> Set.t

(** Look for all .opam files in directory *)
val opam_files: OpamFilename.Dir.t -> Set.t

(** Compare two packages *)
val compare: t -> t -> int

Expand Down
11 changes: 6 additions & 5 deletions src/core/opamRepository.ml
Expand Up @@ -105,11 +105,12 @@ let init r =
OpamFilename.mkdir (upload_dir repo);
OpamFilename.in_dir (root repo) (fun () -> B.init ~address:r.repo_address)

let nv_set_of_files files =
let nv_set_of_files ~all files =
OpamPackage.Set.of_list
(OpamMisc.filter_map
OpamPackage.of_filename
(OpamFilename.Set.elements files))
(OpamPackage.of_filename ~all)
(OpamFilename.Set.elements files)
)

let read_tmp dir =
let dirs =
Expand All @@ -129,7 +130,7 @@ let upload r =
let address = r.repo_address in
let module B = (val find_backend r: BACKEND) in
let files = OpamFilename.in_dir local_dir (fun () -> B.upload_dir ~address upload_dir) in
let packages = nv_set_of_files files in
let packages = nv_set_of_files ~all:true files in
OpamGlobals.msg "The following packages have been uploaded:\n";
OpamPackage.Set.iter (fun nv ->
OpamGlobals.msg " - %s\n" (OpamPackage.to_string nv)
Expand Down Expand Up @@ -342,7 +343,7 @@ let update r =

check_version repo;

let updated_packages = nv_set_of_files updated_files in
let updated_packages = nv_set_of_files ~all:false updated_files in

(* Clean-up archives and tmp files on URL changes *)
OpamPackage.Set.iter (fun nv ->
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/opam_mk_repo.ml
Expand Up @@ -135,7 +135,7 @@ let process () =
let nv_set_of_remotes remotes =
let aux r = OpamFilename.create (OpamFilename.cwd ()) (OpamFilename.Attribute.base r) in
let list = List.map aux (OpamFilename.Attribute.Set.elements remotes) in
OpamPackage.Set.of_list (OpamMisc.filter_map OpamPackage.of_filename list) in
OpamPackage.Set.of_list (OpamMisc.filter_map (OpamPackage.of_filename ~all:true) list) in
let new_index = nv_set_of_remotes new_index in
let missing_archive =
OpamPackage.Set.filter (fun nv ->
Expand Down

0 comments on commit 5e76bc9

Please sign in to comment.