-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warning for framework include violation from Headers to PrivateHeaders
Framework vendors usually layout their framework headers in the following way: Foo.framework/Headers -> "public" headers Foo.framework/PrivateHeader -> "private" headers Since both headers in both directories can be found with #import <Foo/some-header.h>, it's easy to make mistakes and include headers in Foo.framework/PrivateHeader from headers in Foo.framework/Headers, which usually configures a layering violation on Darwin ecosystems. One of the problem this causes is dep cycles when modules are used, since it's very common for "private" modules to include from the "public" ones; adding an edge the other way around will trigger cycles. Add a warning to catch those cases such that: ./A.framework/Headers/A.h:1:10: warning: public framework header includes private framework header 'A/APriv.h' #include <A/APriv.h> ^ rdar://problem/38712182 llvm-svn: 335542
- Loading branch information
1 parent
9bca748
commit 1b3b69f
Showing
16 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Headers/A.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <A/APriv.h> | ||
#include "APriv2.h" | ||
#include <Z/Z.h> | ||
int foo(); |
4 changes: 4 additions & 0 deletions
4
...est/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// framework-public-includes-private/A.framework/Modules/module.modulemap | ||
framework module A { | ||
header "A.h" | ||
} |
4 changes: 4 additions & 0 deletions
4
...les/Inputs/framework-public-includes-private/A.framework/Modules/module.private.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// framework-public-includes-private/A.framework/Modules/module.private.modulemap | ||
framework module A_Private { | ||
header "APriv.h" | ||
} |
1 change: 1 addition & 0 deletions
1
.../test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// framework-public-includes-private/A.framework/PrivateHeaders/APriv.h |
1 change: 1 addition & 0 deletions
1
...test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h |
8 changes: 8 additions & 0 deletions
8
clang/test/Modules/Inputs/framework-public-includes-private/a.hmap.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
{ | ||
"mappings" : | ||
{ | ||
"A.h" : "A/A.h", | ||
"APriv2.h" : "A/APriv2.h" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// framework-public-includes-private/flat-header-path/Z.h | ||
#import "ZPriv.h" |
4 changes: 4 additions & 0 deletions
4
clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// framework-public-includes-private/flat-header-path/Z.modulemap | ||
framework module Z { | ||
header "Z.h" | ||
} |
4 changes: 4 additions & 0 deletions
4
...est/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.private.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// framework-public-includes-private/flat-header-path/Z.private.modulemap | ||
framework module Z_Private { | ||
header "ZPriv.h" | ||
} |
1 change: 1 addition & 0 deletions
1
clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/ZPriv.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// framework-public-includes-private/flat-header-path/ZPriv.h |
7 changes: 7 additions & 0 deletions
7
clang/test/Modules/Inputs/framework-public-includes-private/z.hmap.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
{ | ||
"mappings" : | ||
{ | ||
"ZPriv.h" : "Z/ZPriv.h" | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
clang/test/Modules/Inputs/framework-public-includes-private/z.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
'version': 0, | ||
'case-sensitive': 'false', | ||
'use-external-names' : 'false', | ||
'roots': [ | ||
{ | ||
'type': 'directory', | ||
'name': "TEST_DIR/Z.framework/Headers", | ||
'contents': [ | ||
{ | ||
'type': 'file', | ||
'name': "Z.h", | ||
'external-contents': "TEST_DIR/flat-header-path/Z.h" | ||
} | ||
] | ||
}, | ||
{ | ||
'type': 'directory', | ||
'name': "TEST_DIR/Z.framework/PrivateHeaders", | ||
'contents': [ | ||
{ | ||
'type': 'file', | ||
'name': "ZPriv.h", | ||
'external-contents': "TEST_DIR/flat-header-path/ZPriv.h" | ||
} | ||
] | ||
}, | ||
{ | ||
'type': 'directory', | ||
'name': "TEST_DIR/Z.framework/Modules", | ||
'contents': [ | ||
{ | ||
'type': 'file', | ||
'name': "module.modulemap", | ||
'external-contents': "TEST_DIR/flat-header-path/Z.modulemap" | ||
}, | ||
{ | ||
'type': 'file', | ||
'name': "module.private.modulemap", | ||
'external-contents': "TEST_DIR/flat-header-path/Z.private.modulemap" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// REQUIRES: shell | ||
|
||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
|
||
// RUN: hmaptool write %S/Inputs/framework-public-includes-private/a.hmap.json %t/a.hmap | ||
// RUN: hmaptool write %S/Inputs/framework-public-includes-private/z.hmap.json %t/z.hmap | ||
|
||
// RUN: sed -e "s:TEST_DIR:%S/Inputs/framework-public-includes-private:g" \ | ||
// RUN: %S/Inputs/framework-public-includes-private/z.yaml > %t/z.yaml | ||
|
||
// The output with and without modules should be the same, without modules first. | ||
// RUN: %clang_cc1 \ | ||
// RUN: -iquote %t/z.hmap -iquote %t/a.hmap -ivfsoverlay %t/z.yaml \ | ||
// RUN: -F%S/Inputs/framework-public-includes-private \ | ||
// RUN: -fsyntax-only %s -verify | ||
|
||
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \ | ||
// RUN: -iquote %t/z.hmap -iquote %t/a.hmap -ivfsoverlay %t/z.yaml \ | ||
// RUN: -F%S/Inputs/framework-public-includes-private \ | ||
// RUN: -fsyntax-only %s \ | ||
// RUN: 2>%t/stderr | ||
|
||
// The same warnings show up when modules is on but -verify doesn't get it | ||
// because they only show up under the module A building context. | ||
// RUN: FileCheck --input-file=%t/stderr %s | ||
// CHECK: public framework header includes private framework header 'A/APriv.h' | ||
// CHECK: public framework header includes private framework header 'A/APriv2.h' | ||
// CHECK: public framework header includes private framework header 'Z/ZPriv.h' | ||
|
||
#import "A.h" | ||
|
||
int bar() { return foo(); } | ||
|
||
// expected-warning@Inputs/framework-public-includes-private/A.framework/Headers/A.h:1{{public framework header includes private framework header 'A/APriv.h'}} | ||
// expected-warning@Inputs/framework-public-includes-private/A.framework/Headers/A.h:2{{public framework header includes private framework header 'A/APriv2.h'}} | ||
// expected-warning@Inputs/framework-public-includes-private/flat-header-path/Z.h:2{{public framework header includes private framework header 'Z/ZPriv.h'}} |