Skip to content

Commit

Permalink
Possibility to rename the including files in .spec .
Browse files Browse the repository at this point in the history
  • Loading branch information
tuong committed Apr 19, 2012
1 parent 8516afa commit 2e5b331
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 67 deletions.
5 changes: 3 additions & 2 deletions src/client.ml
Expand Up @@ -670,9 +670,10 @@ module Client : CLIENT = struct
let tmp_nv = Path.concat Path.cwd (B (Namespace.string_of_nv (fst nv) (snd nv))) in
let () =
begin
(* try to check that patches are well-parsed before the copy *)
(* try to check that patches are well-parsed before the copy.
Currently, only ".install" are processed. *)
List.iter
(function Internal p ->
(function Internal p, _ ->
if not (Sys.is_directory p) && Filename.check_suffix p "install" then
(try ignore (File.To_install.parse (Run.read p)) with e ->
Globals.error_and_exit "%s\nwhile parsing '%s'." (Printexc.to_string e) p)
Expand Down
60 changes: 42 additions & 18 deletions src/file.ml
Expand Up @@ -235,8 +235,8 @@ struct
val name : t -> name
val version : t -> version
val make : t -> Run.command list
val sources : t -> raw_filename list
val patches : t -> raw_filename list
val sources : t -> links
val patches : t -> links

(** Returns the list of sentences *)
val description : t -> string list
Expand Down Expand Up @@ -274,8 +274,8 @@ struct
name : string;
version : string;
description: string list;
sources : raw_filename list;
patches : raw_filename list;
sources : links;
patches : links;
make : Run.command list;
depends : Debian.Format822.vpkgformula;
conflicts : Debian.Format822.vpkglist;
Expand Down Expand Up @@ -314,11 +314,17 @@ struct
s_make;
]

let real_path =
List.map
(function
| Internal s, o -> Internal (Run.real_path s), o
| External (s1, s2), o -> External (s1, s2), o)

let description t = t.description
let name t = Namespace.name_of_string t.name
let version t = Namespace.version_of_string t.version
let sources t = t.sources
let patches t = t.patches
let sources t = real_path t.sources
let patches t = real_path t.patches
let make t = t.make

let default_package (t:t) =
Expand All @@ -338,27 +344,45 @@ struct
let to_string, string_of_command =
let open Printf in
let pf p_S (k, v) = sprintf " %s = %s\n" k (p_S v) in
let p_concat f l = String.concat "; " (List.map f l) in
let p_concat f l = String.concat " ; " (List.map f l) in
let p_s = sprintf "%s" in
let p_S = sprintf "%S" in
let pl_S = p_concat p_S in
let pl_s = p_concat (sprintf "%s") in
let pl f_S k l = sprintf " %s = [%s]\n" k (f_S l) in
let plist = sprintf "[ %s ]" in
let pl f_S k l = sprintf " %s = %s\n" k (plist (f_S l)) in
let plf k l =
pl pl_S k (List.map (function
| Internal s -> sprintf "local://%s" s
| External (uri, s) -> sprintf "%s%s" (string_of_uri uri) s
) l) in
pl
(p_concat (function
| s, None -> p_S s
| s, Some s_to -> plist (pl_S [ s ; s_to ])))
k
(List.map
(function s, o ->
(match s with
| Internal s -> sprintf "local://%s" s
| External (uri, s) -> sprintf "%s%s" (string_of_uri uri) s), o) l) in
let string_of_command l =
List.map (function
| Run.Sh l -> sprintf "[%s]" (pl_S l)
| Run.OCaml s -> p_S s) l in
| Run.Sh l -> plist (pl_S l)
| Run.OCaml s ->
Printf.sprintf "%c%s%c"
Lexer.escape_sharp
(String.replace_chars
(fun c ->
sprintf "%s%c"
(if c = Lexer.escape_sharp then
"\\"
else
"")
c) s)
Lexer.escape_sharp) l in
let plc k l = pl pl_s k (string_of_command l) in
let pvpkgl = function
| [] -> "[]"
| l ->
sprintf "[%s]"
(p_concat (fun s -> sprintf "[%s]" (p_concat p_S s))
plist
(p_concat (fun s -> plist (p_concat p_S s))
(List.map (function
| s, None -> [ s ]
| s, Some (rel, v) -> [s ; rel ; v]) l)) in
Expand Down Expand Up @@ -397,8 +421,8 @@ struct
| String s -> String.nsplit s "\\"
| _ -> Globals.error_and_exit "Field 'description': bad format"
with Not_found -> [] in
let sources = parse_l_url (string_list s_sources statement) in
let patches = parse_l_url (string_list s_patches statement) in
let sources = parse_l_url s_sources statement in
let patches = parse_l_url s_patches statement in
let make =
let make = command s_make statement in
if make = [] then [ Run.Sh [ "./build.sh" ] ] else make in
Expand Down
26 changes: 16 additions & 10 deletions src/file_format.ml
Expand Up @@ -45,8 +45,9 @@ let parse_string_list = function
| _ -> bad_format "expecting a list, got a string"

let parse_pair_opt = function
| List[String k; String v] -> k, v
| List[String k] -> k, Filename.basename k
| List[String k; String v] -> k, Some v
| List[String k]
| String k -> k, None
| _ -> bad_format "expecting a pair"

let parse_pair = function
Expand All @@ -58,7 +59,12 @@ let parse_pair_list_ parse_pair = function
| _ -> bad_format "expecting a list, got a string"

let parse_pair_list = parse_pair_list_ parse_pair
let parse_pair_opt_list = parse_pair_list_ parse_pair_opt
let parse_pair_opt_list =
parse_pair_list_
(fun x ->
match parse_pair_opt x with
| k, Some v -> k, v
| k, None -> k, Filename.basename k)

let string_list n s =
try parse_string_list (List.assoc n s.contents)
Expand All @@ -85,13 +91,13 @@ let rec string_of_content = function
Printf.sprintf "[%s]"
(String.concat "; " (List.map string_of_content l))

let parse_l_url =
List.map (fun s ->
match uri_of_url s with
| None , s2
| Some Local, s2 -> Path.Internal (Run.real_path s2)
| Some uri , s2 -> Path.External (uri, s2)
)
let parse_l_url n s =
List.map (fun (s, o) ->
(match uri_of_url s with
| None , s2
| Some Local, s2 -> Path.Internal s2
| Some uri , s2 -> Path.External (uri, s2)), o
) (pair_list_ (parse_pair_list_ parse_pair_opt) n s)

let raw_list n s =
match try List.assoc n s.contents with Not_found -> List [] with
Expand Down
1 change: 1 addition & 0 deletions src/lexer.mll
Expand Up @@ -17,6 +17,7 @@
open Parser

let newline lexbuf = Lexing.new_line lexbuf
let escape_sharp = '#' (* FIXME replace every '#' below by [escape_sharp] *)
}

let space = [' ' '\t' '\r' '\n']
Expand Down
57 changes: 35 additions & 22 deletions src/path.ml
Expand Up @@ -66,15 +66,17 @@ type binary_data =
| Binary of raw_binary
| Filename of raw_filename

type links = {
sources: raw_filename list; (* list OR of archive to download *)
patches: raw_filename list; (* list AND of patch to apply *)
} (* at execution, (sources, OR) will be first considered,
then it is (patches, AND). *)
type links = (raw_filename * string option (* target_name *)) list

type links_order = {
sources: links; (* list OR of archive to download *)
patches: links; (* list AND of patch to apply *)
} (* at execution, "list OR" will be first considered,
then it is "list AND". *)

type 'a archive =
| Archive of 'a
| Links of links
| Links of links_order

type basename = B of string

Expand Down Expand Up @@ -517,38 +519,49 @@ module Path : PATH = struct
if Sys.file_exists file then
error_and_exit "%s already exits" file
else
add_rec (Raw (Namespace.to_string nv)) (R_filename [Raw p]) in
let dir = Namespace.to_string nv in
let () = add_rec (Raw dir) (R_filename [Raw p]) in
function
| Some p_name -> Run.in_dir dir (Unix.rename (Filename.basename p)) p_name
| None -> () in
let apply p =
if Run.patch p nv <> 0 then
error_and_exit "Unable to apply path %S" p in

let patch p =
let l = match p with
| Internal p -> Some p
| External (uri, url) ->
match Run.download (uri, url) nv with
| Run.Url_error -> error_and_exit "Patch %S is unavailable" url
| Run.From_git -> None
| Run.From_http p -> Some p in
let process_link (p, p_name) =
let l =
match p with
| Internal p -> Some p
| External (uri, url) ->
match Run.download (uri, url) nv with
| Run.Url_error -> error_and_exit "Patch %S is unavailable" url
| Run.From_git -> None
| Run.From_http p -> Some p
in

match l, is_patch p with
| Some l, true -> apply l
| Some l, false when Run.is_archive l <> None ->
if Run.untar l nv <> 0 then
error_and_exit "Unable to extract %S" l
| Some l, _ -> add l
| Some l, _ -> add l p_name
| _ -> () in

let rec download = function
let rec links_or = function
| [] -> ()
| x :: xs ->
try patch x with
(* WARNING nothing is done in case [x] represents a "git://" *)
try process_link x with
| Extraction s ->
let () = Globals.warning "%s" s in
download xs in

download links.sources;
try List.iter patch links.patches with Extraction s -> Globals.error_and_exit "%s" s
links_or xs in

let links_and ln =
try List.iter process_link ln with
| Extraction s -> Globals.error_and_exit "%s" s in

links_or links.sources;
links_and links.patches;
)

let to_archive archive_filename tmp_nv =
Expand Down
2 changes: 1 addition & 1 deletion src/server.ml
Expand Up @@ -110,7 +110,7 @@ module Server : SERVER with type t = server_state = struct
| urls ->
(* if some urls are provided, check for external urls *)
let external_urls =
List.fold_left (fun accu -> function External (_,s) -> s::accu | _ -> accu) [] urls in
List.fold_left (fun accu -> function External (_,s), o -> (s, o) :: accu | _ -> accu) [] urls in
if external_urls <> [] then
(* clients can fetch archives *)
None
Expand Down
4 changes: 2 additions & 2 deletions tests/packages/P4-2.spec
Expand Up @@ -4,8 +4,8 @@ package "P4" {
version = "2"
description = "Testing constraints"
patches = [ "http://www.ocamlpro.com/pub/p4.tar.gz"
; "file://P4-3_build.sh" ]
make = [ # Sys.command "./P4-3_build.sh" # ]
; [ "file://P4-3_build.sh" ; "./P4-2_build.sh" ] ]
make = [ # Sys.command "./P4-2_build.sh" # ]
depends = [ [ ["P1";"=";"1"] ]
; [ ["P2"] ]
; [ ["P3"] ] ]
Expand Down
5 changes: 2 additions & 3 deletions tests/packages/bootstrap/extlib.spec
Expand Up @@ -5,7 +5,6 @@ package "extlib" {
description = "http://ocaml-extlib.googlecode.com/svn/doc/apiref/index.html"
patches = [ "http://ocaml-extlib.googlecode.com/files/extlib-1.5.2.tar.gz"
; "local://extlib.install"
; "local://extlib.ocp.boot" ]
make = [ # Unix.rename "extlib.ocp.boot" "extlib.ocp" #
; # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
; [ "local://extlib.ocp.boot" ; "extlib.ocp" ] ]
make = [ # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
}
5 changes: 2 additions & 3 deletions tests/packages/bootstrap/ocamlarg.spec
Expand Up @@ -5,7 +5,6 @@ package "ocamlarg" {
description = "https://github.com/samoht/ocaml-arg.git"
patches = [ "http://www.ocamlpro.com/pub/ocaml-arg.tar.bz2"
; "local://ocamlarg.install"
; "local://ocamlarg.ocp.boot" ]
make = [ # Unix.rename "ocamlarg.ocp.boot" "ocamlarg.ocp" #
; # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
; [ "local://ocamlarg.ocp.boot" ; "ocamlarg.ocp" ] ]
make = [ # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
}
5 changes: 2 additions & 3 deletions tests/packages/bootstrap/ocamlgraph.spec
Expand Up @@ -5,7 +5,6 @@ package "ocamlgraph" {
description = "http://ocamlgraph.lri.fr/doc"
patches = [ "http://ocamlgraph.lri.fr/download/ocamlgraph-1.8.1.tar.gz"
; "local://ocamlgraph.install"
; "local://ocamlgraph.ocp.boot" ]
make = [ # Unix.rename "ocamlgraph.ocp.boot" "ocamlgraph.ocp" #
; # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
; [ "local://ocamlgraph.ocp.boot" ; "ocamlgraph.ocp" ] ]
make = [ # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
}
5 changes: 2 additions & 3 deletions tests/packages/bootstrap/ocamlre.spec
Expand Up @@ -5,7 +5,6 @@ package "ocamlre" {
description = "https://github.com/avsm/ocaml-re.git"
patches = [ "http://www.ocamlpro.com/pub/ocaml-re.tar.bz2"
; "local://ocamlre.install"
; "local://ocamlre.ocp.boot" ]
make = [ # Unix.rename "ocamlre.ocp.boot" "ocamlre.ocp" #
; # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
; [ "local://ocamlre.ocp.boot" ; "ocamlre.ocp" ] ]
make = [ # let exec s a = Unix.execvp s (Array.append [|s|] a) in exec "ocp-build" [| "-init" ; "-scan" |] # ]
}

0 comments on commit 2e5b331

Please sign in to comment.