]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matita/matitaEngine.ml
Some bugs fixed (and some still open) in recursive compilation of files:
[helm.git] / matita / matita / matitaEngine.ml
index 185b0ed1fb088bffb47ecc89cd4800f9909eedab..c6f4359759d4818baf48e51b0c86827c83aa9042 100644 (file)
@@ -162,19 +162,23 @@ let eval_ast ~include_paths ?do_heavy_checks status (text,prefix_len,ast) =
   (new_status,None)::intermediate_states
 ;;
 
+let baseuri_of_script ~include_paths fname =
+ try Librarian.baseuri_of_script ~include_paths fname
+ with
+   Librarian.NoRootFor _ -> 
+    HLog.error ("The included file '"^fname^"' has no root file,");
+    HLog.error "please create it.";
+    raise (Failure ("No root file for "^fname))
+  | Librarian.FileNotFound _ -> 
+    raise (Failure ("File not found: "^fname))
+;;
+
 let rec get_ast status ~compiling ~include_paths strm = 
   match GrafiteParser.parse_statement status strm with
      (GrafiteAst.Executable
        (_,GrafiteAst.NCommand (_,GrafiteAst.Include (_,_,mafilename)))) as cmd
      ->
-      let root, buri, _, tgt = 
-        try Librarian.baseuri_of_script ~include_paths mafilename
-        with Librarian.NoRootFor _ -> 
-          HLog.error ("The included file '"^mafilename^"' has no root file,");
-          HLog.error "please create it.";
-          raise (Failure ("No root file for "^mafilename))
-      in
-       ignore (assert_ng ~compiling ~include_paths ~root tgt);
+       ignore (assert_ng ~compiling ~include_paths mafilename);
        cmd
    | cmd -> cmd
 
@@ -288,14 +292,11 @@ and compile ~compiling ~include_paths fname =
       pp_times fname false big_bang big_bang_u big_bang_s;
       clean_exit baseuri exn
 
-(* BIG BUG: if a file recursively includes itself, anything can happen,
- * from divergence to inclusion of an old copy of itself *)
-and assert_ng ~compiling ~include_paths ~root mapath =
- let root',baseuri,fullmapath,_ = Librarian.baseuri_of_script ~include_paths mapath in
- assert (root=root');
+and assert_ng ~compiling ~include_paths mapath =
+ let _,baseuri,fullmapath,_ = Librarian.baseuri_of_script ~include_paths mapath in
  let baseuri = NUri.uri_of_string baseuri in
- let ngpath = NCicLibrary.ng_path_of_baseuri baseuri in
- let ngtime =
+ let ngtime_of baseuri =
+  let ngpath = NCicLibrary.ng_path_of_baseuri baseuri in
   try
    Some (Unix.stat ngpath).Unix.st_mtime
   with Unix.Unix_error (Unix.ENOENT, "stat", f) when f = ngpath -> None in
@@ -303,12 +304,22 @@ and assert_ng ~compiling ~include_paths ~root mapath =
   try (Unix.stat fullmapath).Unix.st_mtime
   with Unix.Unix_error (Unix.ENOENT, "stat", f) when f = fullmapath -> assert false
  in
+ let ngtime = ngtime_of baseuri in
  let to_be_compiled =
   match ngtime with
      Some ngtime ->
       let preamble = GrafiteTypes.Serializer.dependencies_of baseuri in
       let children_bad =
-       List.exists (assert_ng ~compiling ~include_paths ~root) preamble
+       List.exists
+        (fun mapath ->
+             assert_ng ~compiling ~include_paths mapath
+          || let _,baseuri,_,_ =
+               Librarian.baseuri_of_script ~include_paths mapath in
+             let baseuri = NUri.uri_of_string baseuri in
+              (match ngtime_of baseuri with
+                  Some child_ngtime -> child_ngtime > ngtime
+                | None -> assert false)
+        ) preamble
       in
        children_bad || matime > ngtime
    | None -> true