Skip to content

Commit d8d62ad

Browse files
millenomicompnerd
authored andcommitted
Add test for header include path lookup
Add a test case for the handling of cross-target header lookups which would fail on Windows.
1 parent 0c07485 commit d8d62ad

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "CLibraryParentSearchPath",
7+
products: [
8+
.library(
9+
name: "HeaderInclude",
10+
targets: ["HeaderInclude"]),
11+
],
12+
targets: [
13+
.target(
14+
name: "CHeaderInclude",
15+
cSettings: [
16+
/*
17+
This package tests path normalization; incorrect path normalization on certain OSes (especially Windows) can lead to relative paths like these not being correctly passed to the C compiler.
18+
*/
19+
.headerSearchPath("../Constants")
20+
]
21+
),
22+
.target(
23+
name: "HeaderInclude",
24+
dependencies: [
25+
"CHeaderInclude"
26+
]
27+
)
28+
]
29+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#include "answers.h"
3+
#include "Constants.h"
4+
5+
int getAnswer(void) {
6+
return kTheAnswer;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#ifndef answers_h
3+
#define answers_h
4+
5+
extern int getAnswer(void);
6+
7+
#endif /* answers_h */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#ifndef Constants_h
3+
#define Constants_h
4+
5+
static const int kTheAnswer = 42;
6+
7+
#endif /* Constants_h */
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import CHeaderInclude
3+
4+
enum Answer {
5+
var value: Int { Int(getAnswer()) }
6+
}

Tests/FunctionalTests/CFamilyTargetTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,11 @@ class CFamilyTargetTestCase: XCTestCase {
100100
XCTAssertSwiftTest(fixturePath)
101101
}
102102
}
103+
104+
func testCanBuildRelativeHeaderSearchPaths() throws {
105+
try fixture(name: "CFamilyTargets/CLibraryParentSearchPath") { fixturePath in
106+
XCTAssertBuilds(fixturePath)
107+
XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HeaderInclude.swiftmodule")
108+
}
109+
}
103110
}

0 commit comments

Comments
 (0)