Skip to content

Commit 8dfaa4f

Browse files
committed
fix(ios): use the folders of a NativeSource glob's headers as search paths
The glob itself ended up in HEADER_SEARCH_PATHS, where it matches nothing, relative to the Xcode project rather than the app. Folder paths now use the path resolved against the project for the search path and for the module map check as well.
1 parent f23e658 commit 8dfaa4f

2 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎lib/services/ios-project-service.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,16 +1547,26 @@ export class IOSProjectService
15471547
filesRelativeToProject: true,
15481548
target: project.getFirstTarget()?.uuid,
15491549
});
1550-
project.addToHeaderSearchPaths(group.path);
1551-
const headerFiles = this.$fs.exists(sourceFolderPath)
1550+
// A glob is no use as a search path, the folders of its headers are.
1551+
const headerSearchPaths = fastGlob.isDynamicPattern(sourceFolderPath)
1552+
? _.uniq(
1553+
group.files
1554+
.filter((file) => path.extname(file) === ".h")
1555+
.map((file) => path.dirname(file)),
1556+
)
1557+
: [group.path];
1558+
headerSearchPaths.forEach((searchPath) =>
1559+
project.addToHeaderSearchPaths(searchPath),
1560+
);
1561+
const headerFiles = this.$fs.exists(group.path)
15521562
? this.$fs.enumerateFilesInDirectorySync(
1553-
sourceFolderPath,
1563+
group.path,
15541564
(file, stat) => stat.isDirectory() || path.extname(file) === ".h",
15551565
)
15561566
: [];
15571567
if (
15581568
headerFiles.length > 0 &&
1559-
!this.$fs.exists(path.join(sourceFolderPath, "module.modulemap"))
1569+
!this.$fs.exists(path.join(group.path, "module.modulemap"))
15601570
) {
15611571
this.$logger.warn(
15621572
`warning: Directory ${sourceFolderPath} with native iOS source code doesn't contain a modulemap file. Metadata for it will not be generated and it will not be accessible from JavaScript. To learn more see https://docs.nativescript.org/guides/ios-source-code`,

‎test/ios-project-service-native-source.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,50 @@ describe("iOSProjectService getRootGroup", () => {
4747
it("resolves a folder against the project, not the working directory", async () => {
4848
assert.deepEqual(await getFiles("../../libs/native"), [expectedSource()]);
4949
});
50+
51+
describe("header search paths", () => {
52+
const prepare = async (rootPath: string): Promise<string[]> => {
53+
const searchPaths: string[] = [];
54+
const proto = <any>IOSProjectService.prototype;
55+
await proto.prepareNativeSourceCode.call(
56+
{
57+
$fs: new FileSystem(<any>{}),
58+
$logger: { warn: () => {} },
59+
getRootGroup: proto.getRootGroup,
60+
savePbxProj: () => {},
61+
createPbxProj: () => ({
62+
addPbxGroup: () => {},
63+
getFirstTarget: () => ({ uuid: "target" }),
64+
addToHeaderSearchPaths: (searchPath: string) =>
65+
searchPaths.push(searchPath),
66+
}),
67+
},
68+
"Native",
69+
rootPath,
70+
{ projectDir },
71+
);
72+
return searchPaths.map((searchPath) => fs.realpathSync(searchPath));
73+
};
74+
75+
it("uses the folders of the headers a glob matches", async () => {
76+
const nested = path.join(sourcesDir, "nested");
77+
fs.mkdirSync(nested);
78+
fs.writeFileSync(path.join(nested, "One.h"), "");
79+
fs.writeFileSync(path.join(nested, "Two.h"), "");
80+
81+
assert.deepEqual(await prepare("../../libs/native/**/*.{h,swift}"), [
82+
fs.realpathSync(nested),
83+
]);
84+
});
85+
86+
it("adds nothing for a glob without headers", async () => {
87+
assert.deepEqual(await prepare("../../libs/native/*.swift"), []);
88+
});
89+
90+
it("uses the folder itself, against the project", async () => {
91+
assert.deepEqual(await prepare("../../libs/native"), [
92+
fs.realpathSync(sourcesDir),
93+
]);
94+
});
95+
});
5096
});

0 commit comments

Comments
 (0)