Skip to content

Commit e866d70

Browse files
fix: exclude unsupported architectures from cocoapods (#5405)
* feat(ios): arch exlusion handling for cocoapods * fix: apply arch exclusions podfile from a temp file * fix: tests Co-authored-by: Nathan Walker <[email protected]>
1 parent 21f48ab commit e866d70

File tree

5 files changed

+136
-53
lines changed

5 files changed

+136
-53
lines changed

.vscode/launch.json

+62-51
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
11
{
2-
// Use IntelliSense to learn about possible Node.js debug attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "launch",
10-
"cwd": "${workspaceRoot}",
11-
"sourceMaps": true,
12-
// In case you want to debug child processes started from CLI:
13-
// "autoAttachChildProcesses": true,
14-
"name": "Launch CLI (Node 6+)",
15-
"program": "${workspaceRoot}/lib/nativescript-cli.js",
16-
17-
// example commands
18-
"args": [ "create", "cliapp", "--path", "${workspaceRoot}/scratch"]
19-
// "args": [ "test", "android", "--justlaunch"]
20-
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
21-
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
22-
// "args": [ "plugin", "add", "nativescript-barcodescanner", "--path", "cliapp"]
23-
// "args": [ "plugin", "remove", "nativescript-barcodescanner", "--path", "cliapp"]
24-
// "args": [ "build", "android", "--path", "cliapp"]
25-
// "args": [ "run", "android", "--path", "cliapp"]
26-
// "args": [ "debug", "android", "--path", "cliapp"]
27-
// "args": [ "livesync", "android", "--path", "cliapp"]
28-
// "args": [ "livesync", "android", "--watch", "--path", "cliapp"],
29-
// "args": [ "resources", "generate", "icons", "./test/image-generation-test.png", "--path", "cliapp" ],
30-
// "args": [ "resources", "generate", "splashes", "./test/image-generation-test.png", "--path", "cliapp", "--background", "#8000ff" ],
31-
},
32-
{
33-
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
34-
"type": "node",
35-
"request": "launch",
36-
"name": "Launch Tests (Node 6+)",
37-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
38-
"cwd": "${workspaceRoot}",
39-
"sourceMaps": true
40-
},
41-
42-
{
43-
"type": "node",
44-
"request": "attach",
45-
"name": "Attach to Broker Process",
46-
// In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process.
47-
"port": 9897,
48-
"sourceMaps": true
49-
}
50-
51-
]
52-
}
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"cwd": "${workspaceRoot}",
11+
"sourceMaps": true,
12+
// In case you want to debug child processes started from CLI:
13+
// "autoAttachChildProcesses": true,
14+
"name": "Launch CLI (Node 6+)",
15+
"program": "${workspaceRoot}/lib/nativescript-cli.js",
16+
// example commands
17+
"args": [
18+
"create",
19+
"cliapp",
20+
"--path",
21+
"${workspaceRoot}/scratch"
22+
]
23+
// "args": [ "test", "android", "--justlaunch"]
24+
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
25+
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
26+
// "args": [ "plugin", "add", "nativescript-barcodescanner", "--path", "cliapp"]
27+
// "args": [ "plugin", "remove", "nativescript-barcodescanner", "--path", "cliapp"]
28+
// "args": [ "build", "android", "--path", "cliapp"]
29+
// "args": [ "run", "android", "--path", "cliapp"]
30+
// "args": [ "debug", "android", "--path", "cliapp"]
31+
// "args": [ "livesync", "android", "--path", "cliapp"]
32+
// "args": [ "livesync", "android", "--watch", "--path", "cliapp"],
33+
// "args": [ "resources", "generate", "icons", "./test/image-generation-test.png", "--path", "cliapp" ],
34+
// "args": [ "resources", "generate", "splashes", "./test/image-generation-test.png", "--path", "cliapp", "--background", "#8000ff" ],
35+
},
36+
{
37+
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
38+
"type": "node",
39+
"request": "launch",
40+
"name": "Launch Tests (Node 6+)",
41+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
42+
"cwd": "${workspaceRoot}",
43+
"sourceMaps": true
44+
},
45+
{
46+
"type": "node",
47+
"request": "attach",
48+
"name": "Attach to Broker Process",
49+
// In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process.
50+
"port": 9897,
51+
"sourceMaps": true
52+
},
53+
{
54+
"name": "Attach to Node Debugger",
55+
"port": 9229,
56+
"request": "attach",
57+
"skipFiles": [
58+
"<node_internals>/**"
59+
],
60+
"type": "pwa-node"
61+
}
62+
]
63+
}

lib/definitions/project.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ interface ICocoaPodsService {
594594
platformData: IPlatformData
595595
): Promise<void>;
596596

597+
applyPodfileArchExclusions(
598+
projectData: IProjectData,
599+
platformData: IPlatformData
600+
): Promise<void>;
601+
597602
/**
598603
* Prepares the Podfile content of a plugin and merges it in the project's Podfile.
599604
* @param {string} moduleName The module which the Podfile is from.

lib/services/cocoapods-service.ts

+30
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,36 @@ ${versionResolutionHint}`);
135135
}
136136
}
137137

138+
public async applyPodfileArchExclusions(
139+
projectData: IProjectData,
140+
platformData: IPlatformData
141+
): Promise<void> {
142+
const { projectRoot } = platformData;
143+
const exclusionsPodfile = path.join(projectRoot, "Podfile-exclusions");
144+
145+
if (!this.$fs.exists(exclusionsPodfile)) {
146+
const exclusions = `
147+
post_install do |installer|
148+
installer.pods_project.build_configurations.each do |config|
149+
config.build_settings["EXCLUDED_ARCHS_x86_64"] = "arm64 arm64e"
150+
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386 armv6 armv7 armv7s armv8 $(EXCLUDED_ARCHS_$(NATIVE_ARCH_64_BIT))"
151+
config.build_settings["EXCLUDED_ARCHS[sdk=iphoneos*]"] = "i386 armv6 armv7 armv7s armv8 x86_64"
152+
end
153+
end`.trim();
154+
this.$fs.writeFile(exclusionsPodfile, exclusions);
155+
}
156+
157+
await this.applyPodfileToProject(
158+
"NativeScript-CLI-Architecture-Exclusions",
159+
exclusionsPodfile,
160+
projectData,
161+
platformData
162+
);
163+
164+
// clean up
165+
this.$fs.deleteFile(exclusionsPodfile);
166+
}
167+
138168
public async applyPodfileToProject(
139169
moduleName: string,
140170
podfilePath: string,

lib/services/ios-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
937937
projectData,
938938
platformData
939939
);
940+
await this.$cocoapodsService.applyPodfileArchExclusions(
941+
projectData,
942+
platformData
943+
);
940944

941945
const projectPodfilePath = this.$cocoapodsService.getProjectPodfilePath(
942946
platformData.projectRoot

test/ios-project-service.ts

+35-2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@ describe("Cocoapods support", () => {
258258
if (require("os").platform() !== "darwin") {
259259
console.log("Skipping Cocoapods tests. They cannot work on windows");
260260
} else {
261+
const expectedArchExclusions = (projectPath: string) =>
262+
[
263+
``,
264+
`post_install do |installer|`,
265+
` post_installNativeScript_CLI_Architecture_Exclusions_0 installer`,
266+
`end`,
267+
``,
268+
`# Begin Podfile - ${projectPath}/platforms/ios/Podfile-exclusions`,
269+
`def post_installNativeScript_CLI_Architecture_Exclusions_0 (installer)`,
270+
` installer.pods_project.build_configurations.each do |config|`,
271+
` config.build_settings["EXCLUDED_ARCHS_x86_64"] = "arm64 arm64e"`,
272+
` config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386 armv6 armv7 armv7s armv8 $(EXCLUDED_ARCHS_$(NATIVE_ARCH_64_BIT))"`,
273+
` config.build_settings["EXCLUDED_ARCHS[sdk=iphoneos*]"] = "i386 armv6 armv7 armv7s armv8 x86_64"`,
274+
` end`,
275+
`end`,
276+
`# End Podfile`,
277+
].join("\n");
278+
261279
it("adds а base Podfile", async () => {
262280
const projectName = "projectDirectory";
263281
const projectPath = temp.mkdirSync(projectName);
@@ -458,13 +476,15 @@ describe("Cocoapods support", () => {
458476
"platform :ios, '8.1'",
459477
"# End NativeScriptPlatformSection\n",
460478
].join("\n");
479+
461480
const expectedProjectPodfileContent = [
462481
"use_frameworks!\n",
463482
`target "${projectName}" do`,
464483
expectedPlatformSection,
465484
`# Begin Podfile - ${pluginPodfilePath}`,
466485
expectedPluginPodfileContent,
467486
"# End Podfile",
487+
expectedArchExclusions(projectPath),
468488
"end",
469489
].join("\n");
470490
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
@@ -573,7 +593,7 @@ describe("Cocoapods support", () => {
573593
const projectPodfilePath = join(platformsFolderPath, "Podfile");
574594
assert.isTrue(fs.exists(projectPodfilePath));
575595

576-
const actualProjectPodfileContent = fs.readText(projectPodfilePath);
596+
let actualProjectPodfileContent = fs.readText(projectPodfilePath);
577597
const expectedPluginPodfileContent = [
578598
"source 'https://github.com/CocoaPods/Specs.git'",
579599
"# platform :ios, '8.1'",
@@ -591,6 +611,7 @@ describe("Cocoapods support", () => {
591611
`# Begin Podfile - ${pluginPodfilePath}`,
592612
expectedPluginPodfileContent,
593613
"# End Podfile",
614+
expectedArchExclusions(projectPath),
594615
"end",
595616
].join("\n");
596617
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
@@ -600,7 +621,18 @@ describe("Cocoapods support", () => {
600621
projectData
601622
);
602623

603-
assert.isFalse(fs.exists(projectPodfilePath));
624+
const expectedProjectPodfileContentAfter = [
625+
"use_frameworks!\n",
626+
`target "${projectName}" do`,
627+
"",
628+
expectedArchExclusions(projectPath),
629+
"end",
630+
].join("\n");
631+
actualProjectPodfileContent = fs.readText(projectPodfilePath);
632+
assert.equal(
633+
actualProjectPodfileContent,
634+
expectedProjectPodfileContentAfter
635+
);
604636
});
605637
}
606638
});
@@ -1234,6 +1266,7 @@ describe("handleNativeDependenciesChange", () => {
12341266
cocoapodsService.getProjectPodfilePath = () => projectPodfilePath;
12351267

12361268
const fs = testInjector.resolve("fs");
1269+
fs.readText = (filePath: string) => "";
12371270
fs.exists = (filePath: string) => filePath === projectPodfilePath;
12381271

12391272
await iOSProjectService.handleNativeDependenciesChange(projectData);

0 commit comments

Comments
 (0)