Skip to content

fix: exclude unsupported architectures from cocoapods #5405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 62 additions & 51 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
// In case you want to debug child processes started from CLI:
// "autoAttachChildProcesses": true,
"name": "Launch CLI (Node 6+)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",

// example commands
"args": [ "create", "cliapp", "--path", "${workspaceRoot}/scratch"]
// "args": [ "test", "android", "--justlaunch"]
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
// "args": [ "plugin", "add", "nativescript-barcodescanner", "--path", "cliapp"]
// "args": [ "plugin", "remove", "nativescript-barcodescanner", "--path", "cliapp"]
// "args": [ "build", "android", "--path", "cliapp"]
// "args": [ "run", "android", "--path", "cliapp"]
// "args": [ "debug", "android", "--path", "cliapp"]
// "args": [ "livesync", "android", "--path", "cliapp"]
// "args": [ "livesync", "android", "--watch", "--path", "cliapp"],
// "args": [ "resources", "generate", "icons", "./test/image-generation-test.png", "--path", "cliapp" ],
// "args": [ "resources", "generate", "splashes", "./test/image-generation-test.png", "--path", "cliapp", "--background", "#8000ff" ],
},
{
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
"type": "node",
"request": "launch",
"name": "Launch Tests (Node 6+)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},

{
"type": "node",
"request": "attach",
"name": "Attach to Broker Process",
// In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process.
"port": 9897,
"sourceMaps": true
}

]
}
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
// In case you want to debug child processes started from CLI:
// "autoAttachChildProcesses": true,
"name": "Launch CLI (Node 6+)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",
// example commands
"args": [
"create",
"cliapp",
"--path",
"${workspaceRoot}/scratch"
]
// "args": [ "test", "android", "--justlaunch"]
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
// "args": [ "plugin", "add", "nativescript-barcodescanner", "--path", "cliapp"]
// "args": [ "plugin", "remove", "nativescript-barcodescanner", "--path", "cliapp"]
// "args": [ "build", "android", "--path", "cliapp"]
// "args": [ "run", "android", "--path", "cliapp"]
// "args": [ "debug", "android", "--path", "cliapp"]
// "args": [ "livesync", "android", "--path", "cliapp"]
// "args": [ "livesync", "android", "--watch", "--path", "cliapp"],
// "args": [ "resources", "generate", "icons", "./test/image-generation-test.png", "--path", "cliapp" ],
// "args": [ "resources", "generate", "splashes", "./test/image-generation-test.png", "--path", "cliapp", "--background", "#8000ff" ],
},
{
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
"type": "node",
"request": "launch",
"name": "Launch Tests (Node 6+)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},
{
"type": "node",
"request": "attach",
"name": "Attach to Broker Process",
// In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process.
"port": 9897,
"sourceMaps": true
},
{
"name": "Attach to Node Debugger",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
]
}
5 changes: 5 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ interface ICocoaPodsService {
platformData: IPlatformData
): Promise<void>;

applyPodfileArchExclusions(
projectData: IProjectData,
platformData: IPlatformData
): Promise<void>;

/**
* Prepares the Podfile content of a plugin and merges it in the project's Podfile.
* @param {string} moduleName The module which the Podfile is from.
Expand Down
30 changes: 30 additions & 0 deletions lib/services/cocoapods-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,36 @@ ${versionResolutionHint}`);
}
}

public async applyPodfileArchExclusions(
projectData: IProjectData,
platformData: IPlatformData
): Promise<void> {
const { projectRoot } = platformData;
const exclusionsPodfile = path.join(projectRoot, "Podfile-exclusions");

if (!this.$fs.exists(exclusionsPodfile)) {
const exclusions = `
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS_x86_64"] = "arm64 arm64e"
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386 armv6 armv7 armv7s armv8 $(EXCLUDED_ARCHS_$(NATIVE_ARCH_64_BIT))"
config.build_settings["EXCLUDED_ARCHS[sdk=iphoneos*]"] = "i386 armv6 armv7 armv7s armv8 x86_64"
end
end`.trim();
this.$fs.writeFile(exclusionsPodfile, exclusions);
}

await this.applyPodfileToProject(
"NativeScript-CLI-Architecture-Exclusions",
exclusionsPodfile,
projectData,
platformData
);

// clean up
this.$fs.deleteFile(exclusionsPodfile);
}

public async applyPodfileToProject(
moduleName: string,
podfilePath: string,
Expand Down
4 changes: 4 additions & 0 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
projectData,
platformData
);
await this.$cocoapodsService.applyPodfileArchExclusions(
projectData,
platformData
);

const projectPodfilePath = this.$cocoapodsService.getProjectPodfilePath(
platformData.projectRoot
Expand Down
37 changes: 35 additions & 2 deletions test/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ describe("Cocoapods support", () => {
if (require("os").platform() !== "darwin") {
console.log("Skipping Cocoapods tests. They cannot work on windows");
} else {
const expectedArchExclusions = (projectPath: string) =>
[
``,
`post_install do |installer|`,
` post_installNativeScript_CLI_Architecture_Exclusions_0 installer`,
`end`,
``,
`# Begin Podfile - ${projectPath}/platforms/ios/Podfile-exclusions`,
`def post_installNativeScript_CLI_Architecture_Exclusions_0 (installer)`,
` installer.pods_project.build_configurations.each do |config|`,
` config.build_settings["EXCLUDED_ARCHS_x86_64"] = "arm64 arm64e"`,
` config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386 armv6 armv7 armv7s armv8 $(EXCLUDED_ARCHS_$(NATIVE_ARCH_64_BIT))"`,
` config.build_settings["EXCLUDED_ARCHS[sdk=iphoneos*]"] = "i386 armv6 armv7 armv7s armv8 x86_64"`,
` end`,
`end`,
`# End Podfile`,
].join("\n");

it("adds а base Podfile", async () => {
const projectName = "projectDirectory";
const projectPath = temp.mkdirSync(projectName);
Expand Down Expand Up @@ -458,13 +476,15 @@ describe("Cocoapods support", () => {
"platform :ios, '8.1'",
"# End NativeScriptPlatformSection\n",
].join("\n");

const expectedProjectPodfileContent = [
"use_frameworks!\n",
`target "${projectName}" do`,
expectedPlatformSection,
`# Begin Podfile - ${pluginPodfilePath}`,
expectedPluginPodfileContent,
"# End Podfile",
expectedArchExclusions(projectPath),
"end",
].join("\n");
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
Expand Down Expand Up @@ -573,7 +593,7 @@ describe("Cocoapods support", () => {
const projectPodfilePath = join(platformsFolderPath, "Podfile");
assert.isTrue(fs.exists(projectPodfilePath));

const actualProjectPodfileContent = fs.readText(projectPodfilePath);
let actualProjectPodfileContent = fs.readText(projectPodfilePath);
const expectedPluginPodfileContent = [
"source 'https://github.com/CocoaPods/Specs.git'",
"# platform :ios, '8.1'",
Expand All @@ -591,6 +611,7 @@ describe("Cocoapods support", () => {
`# Begin Podfile - ${pluginPodfilePath}`,
expectedPluginPodfileContent,
"# End Podfile",
expectedArchExclusions(projectPath),
"end",
].join("\n");
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
Expand All @@ -600,7 +621,18 @@ describe("Cocoapods support", () => {
projectData
);

assert.isFalse(fs.exists(projectPodfilePath));
const expectedProjectPodfileContentAfter = [
"use_frameworks!\n",
`target "${projectName}" do`,
"",
expectedArchExclusions(projectPath),
"end",
].join("\n");
actualProjectPodfileContent = fs.readText(projectPodfilePath);
assert.equal(
actualProjectPodfileContent,
expectedProjectPodfileContentAfter
);
});
}
});
Expand Down Expand Up @@ -1234,6 +1266,7 @@ describe("handleNativeDependenciesChange", () => {
cocoapodsService.getProjectPodfilePath = () => projectPodfilePath;

const fs = testInjector.resolve("fs");
fs.readText = (filePath: string) => "";
fs.exists = (filePath: string) => filePath === projectPodfilePath;

await iOSProjectService.handleNativeDependenciesChange(projectData);
Expand Down