Skip to content

Commit

Permalink
ocamlbuild: normalize pathname and authorize absolute pathnames as de…
Browse files Browse the repository at this point in the history
…pendencies.

git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.10@8717 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
ertai committed Dec 18, 2007
1 parent 62dbacc commit c7e709f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions ocamlbuild/main.ml
Expand Up @@ -156,6 +156,7 @@ let proceed () =

let targets =
List.map begin fun starget ->
let starget = Resource.import starget in
let target = path_and_context_of_string starget in
let ext = Pathname.get_extension starget in
(target, starget, ext)
Expand Down
15 changes: 14 additions & 1 deletion ocamlbuild/resource.ml
Expand Up @@ -138,6 +138,18 @@ module Cache = struct
dprintf 10 "resource_changed:@ %a" print r;
(get r).changed <- Yes

let external_is_up_to_date absolute_path =
let key = "Resource: " ^ absolute_path in
let digest = Digest.file absolute_path in
let is_up_to_date =
try
let digest' = Digest_cache.get key in
digest = digest'
with Not_found ->
false
in
is_up_to_date || (Digest_cache.put key digest; false)

let source_is_up_to_date r_in_source_dir r_in_build_dir =
Pathname.exists r_in_build_dir && Digest.file r_in_build_dir = Digest.file r_in_source_dir

Expand Down Expand Up @@ -264,7 +276,8 @@ let rec subst percent r =
let print_env = pp_print_string
*)

let import x = x
(* Should normalize *)
let import x = Pathname.normalize x

module MetaPath : sig

Expand Down
1 change: 1 addition & 0 deletions ocamlbuild/resource.mli
Expand Up @@ -44,6 +44,7 @@ module Cache :
val clear_resource_failed : t -> unit
val add_dependency : t -> t -> unit
val fold_dependencies : (string -> string -> 'a -> 'a) -> 'a -> 'a
val external_is_up_to_date : t -> bool

(* These are not currently used by others modules. *)
val dependencies : t -> Resources.t
Expand Down
6 changes: 3 additions & 3 deletions ocamlbuild/rule.ml
Expand Up @@ -28,7 +28,7 @@ type digest_command = { digest : string; command : Command.t }
type 'a gen_rule =
{ name : string;
tags : Tags.t;
deps : Pathname.t list;
deps : Pathname.t list; (* These pathnames must be normalized *)
prods : 'a list; (* Note that prods also contains stamp *)
stamp : 'a option;
code : env -> builder -> digest_command }
Expand Down Expand Up @@ -67,7 +67,7 @@ let subst env rule =
let prods = subst_resource_patterns rule.prods in
{ (rule) with name = sbprintf "%s (%a)" rule.name Resource.print_env env;
prods = prods;
deps = subst_resources rule.deps;
deps = subst_resources rule.deps; (* The substition should preserve normalization of pathnames *)
stamp = stamp;
code = (fun env -> rule.code (finder env)) }

Expand Down Expand Up @@ -298,7 +298,7 @@ let rule name ?(tags=[]) ?(prods=[]) ?(deps=[]) ?prod ?dep ?stamp ?(insert = `bo
add_rule insert
{ name = name;
tags = List.fold_right Tags.add tags Tags.empty;
deps = res_add Resource.import deps dep;
deps = res_add Resource.import (* should normalize *) deps dep;
stamp = stamp;
prods = prods;
code = code }
Expand Down
8 changes: 8 additions & 0 deletions ocamlbuild/solver.ml
Expand Up @@ -31,6 +31,10 @@ let failed target backtrace =
let rec pp_repeat f (n, s) =
if n > 0 then (pp_print_string f s; pp_repeat f (n - 1, s))

(* Targets must be normalized pathnames.
* Recursive calls are either on input targets
* or dependencies of these targets (returned by Rule.deps_of_rule).
*)
let rec self depth on_the_go_orig target =
let rules = Rule.get_rules () in
let on_the_go = target :: on_the_go_orig in
Expand All @@ -46,6 +50,10 @@ let rec self depth on_the_go_orig target =
(dprintf 5 "%a was suspended -> resuming" Resource.print target;
Resource.Cache.resume_suspension s)
| Resource.Cache.Bnot_built_yet ->
if not (Pathname.is_relative target) && Pathname.exists target then
if Resource.Cache.external_is_up_to_date target then ()
else (* perhaps the error can be refined *) failed target (Leaf target)
else
if Resource.exists_in_source_dir target then
Resource.Cache.import_in_build_dir target
else
Expand Down

0 comments on commit c7e709f

Please sign in to comment.