Skip file from include dir if parcel was already processed

The parcel from the first source or include dir takes precedence.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/bec8dc32
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/bec8dc32
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/bec8dc32

Branch: refs/heads/include_dir_fixes
Commit: bec8dc327b54e9d5111ff35b7662f2a114c21c11
Parents: 76f81ce
Author: Nick Wellnhofer <[email protected]>
Authored: Fri Aug 1 13:47:46 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Fri Aug 1 15:48:17 2014 +0200

----------------------------------------------------------------------
 compiler/perl/t/502-clash.t |  2 +-
 compiler/src/CFCHierarchy.c | 34 ++++++++++++++++------------------
 2 files changed, 17 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bec8dc32/compiler/perl/t/502-clash.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/502-clash.t b/compiler/perl/t/502-clash.t
index cd875f0..4bb5a63 100644
--- a/compiler/perl/t/502-clash.t
+++ b/compiler/perl/t/502-clash.t
@@ -40,7 +40,7 @@ SKIP: {
     eval { $hierarchy->build; };
 
     my $filename = catfile(qw( Animal Dog.cfh ));
-    like( $@, qr/File \Q$filename\E already registered/,
+    like( $@, qr|\Q$filename\E .* \Q$base_dir\E .* \Q$file_clash_dir\E|,
           "source/source filename clash" );
 
     Clownfish::CFC::Model::Class->_clear_registry();

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bec8dc32/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index e336b29..9698e61 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -352,22 +352,6 @@ S_parse_cf_files(CFCHierarchy *self, const char 
*source_dir, int is_included) {
         memcpy(path_part, src, path_part_len);
         path_part[path_part_len] = '\0';
 
-        // Make sure path_part is unique
-        CFCFile *existing = S_fetch_file(self, path_part);
-        if (existing) {
-            if (is_included && !CFCFile_included(existing)) {
-                // Allow filename clash between source and include dirs
-                CFCUtil_warn("Warning: File %s.cfh from source dir takes "
-                             "precedence over file from include dir",
-                             path_part);
-                // Ignore file
-                continue;
-            }
-            else {
-                CFCUtil_die("File %s.cfh already registered", path_part);
-            }
-        }
-
         CFCFileSpec *file_spec = CFCFileSpec_new(source_dir, path_part,
                                                  is_included);
 
@@ -381,9 +365,23 @@ S_parse_cf_files(CFCHierarchy *self, const char 
*source_dir, int is_included) {
             CFCUtil_die("%s:%d: parser error", source_path, lineno);
         }
 
-        // Add parsed file to pool if it's from a required parcel.
+        // Add parsed file to pool if it's from a required parcel. Skip
+        // file if it's from an include dir and the parcel was already
+        // processed in another source or include dir.
         CFCParcel *parcel = CFCFile_get_parcel(file);
-        if (CFCParcel_required(parcel)) {
+        const char *parcel_source_dir = CFCParcel_get_source_dir(parcel);
+        CFCUTIL_NULL_CHECK(parcel_source_dir);
+        if (CFCParcel_required(parcel)
+            && (!is_included || strcmp(source_dir, parcel_source_dir) == 0)) {
+            // Make sure path_part is unique because the name of the generated
+            // C header is derived from it.
+            CFCFile *existing = S_fetch_file(self, path_part);
+            if (existing) {
+                CFCUtil_die("File %s.cfh found twice in %s and %s",
+                            path_part, CFCFile_get_source_dir(existing),
+                            source_dir);
+            }
+
             S_add_file(self, file);
         }
 

Reply via email to