From 25440f6e823980b1cedba38f75ac5ecb12bc159c Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Fri, 2 Oct 2020 14:12:37 -0700 Subject: [PATCH 1/3] feat(ios): arch exlusion handling for cocoapods --- .vscode/launch.json | 11 ++++++++++- lib/definitions/project.d.ts | 2 ++ lib/services/cocoapods-service.ts | 21 +++++++++++++++++++++ lib/services/ios-project-service.ts | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e1dd227cc5..df2be71789 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -46,7 +46,16 @@ // 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", + "port": 9229, + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "pwa-node" + } ] } \ No newline at end of file diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 5f092ae1f7..43ebb624d3 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -660,6 +660,8 @@ interface ICocoaPodsService { platformData: IPlatformData, opts: IRelease ): Promise; + + applyPodfileArchExclusions(platformData: IPlatformData): Promise; } interface ICocoaPodsPlatformManager { diff --git a/lib/services/cocoapods-service.ts b/lib/services/cocoapods-service.ts index 4163948628..4d1efe5619 100644 --- a/lib/services/cocoapods-service.ts +++ b/lib/services/cocoapods-service.ts @@ -48,6 +48,27 @@ export class CocoaPodsService implements ICocoaPodsService { return `${EOL}end`; } + public async applyPodfileArchExclusions( + platformData: IPlatformData + ): Promise { + const { projectRoot } = platformData; + const projectPodfilePath = this.getProjectPodfilePath(projectRoot); + if (this.$fs.exists(projectPodfilePath)) { + let projectPodfileContent = this.$fs.exists(projectPodfilePath) + ? this.$fs.readText(projectPodfilePath).trim() + : ""; + projectPodfileContent += `${EOL}post_install do |installer| + installer.pods_project.build_configurations.each do |config| + # config.build_settings.delete "VALID_ARCHS" + 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`; + this.$fs.writeFile(projectPodfilePath, projectPodfileContent); + } + } + public getProjectPodfilePath(projectRoot: string): string { return path.join(projectRoot, PODFILE_NAME); } diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index f4795f4b04..ee5041ad6a 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -933,6 +933,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.setProductBundleIdentifier(projectData); await this.applyPluginsCocoaPods(pluginsData, projectData, platformData); + await this.$cocoapodsService.applyPodfileArchExclusions(platformData); await this.$cocoapodsService.applyPodfileFromAppResources( projectData, platformData From 2ecbb7b187c6b1cace926cfa28ef0225d6cd45d1 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 2 Oct 2020 23:27:46 +0200 Subject: [PATCH 2/3] fix: apply arch exclusions podfile from a temp file --- lib/definitions/project.d.ts | 7 ++-- lib/services/cocoapods-service.ts | 51 +++++++++++++++++------------ lib/services/ios-project-service.ts | 5 ++- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 43ebb624d3..be5db54030 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -594,6 +594,11 @@ interface ICocoaPodsService { platformData: IPlatformData ): Promise; + applyPodfileArchExclusions( + projectData: IProjectData, + platformData: IPlatformData + ): Promise; + /** * 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. @@ -660,8 +665,6 @@ interface ICocoaPodsService { platformData: IPlatformData, opts: IRelease ): Promise; - - applyPodfileArchExclusions(platformData: IPlatformData): Promise; } interface ICocoaPodsPlatformManager { diff --git a/lib/services/cocoapods-service.ts b/lib/services/cocoapods-service.ts index 4d1efe5619..c94f394160 100644 --- a/lib/services/cocoapods-service.ts +++ b/lib/services/cocoapods-service.ts @@ -48,27 +48,6 @@ export class CocoaPodsService implements ICocoaPodsService { return `${EOL}end`; } - public async applyPodfileArchExclusions( - platformData: IPlatformData - ): Promise { - const { projectRoot } = platformData; - const projectPodfilePath = this.getProjectPodfilePath(projectRoot); - if (this.$fs.exists(projectPodfilePath)) { - let projectPodfileContent = this.$fs.exists(projectPodfilePath) - ? this.$fs.readText(projectPodfilePath).trim() - : ""; - projectPodfileContent += `${EOL}post_install do |installer| - installer.pods_project.build_configurations.each do |config| - # config.build_settings.delete "VALID_ARCHS" - 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`; - this.$fs.writeFile(projectPodfilePath, projectPodfileContent); - } - } - public getProjectPodfilePath(projectRoot: string): string { return path.join(projectRoot, PODFILE_NAME); } @@ -156,6 +135,36 @@ ${versionResolutionHint}`); } } + public async applyPodfileArchExclusions( + projectData: IProjectData, + platformData: IPlatformData + ): Promise { + const { projectRoot } = platformData; + const exclusionsPodfile = path.join(projectRoot, "Podfile-exclusions"); + + if (!this.$fs.exists(exclusionsPodfile)) { + const exclusions = `${EOL} +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`; + 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, diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index ee5041ad6a..9ac2b56048 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -933,11 +933,14 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.setProductBundleIdentifier(projectData); await this.applyPluginsCocoaPods(pluginsData, projectData, platformData); - await this.$cocoapodsService.applyPodfileArchExclusions(platformData); await this.$cocoapodsService.applyPodfileFromAppResources( projectData, platformData ); + await this.$cocoapodsService.applyPodfileArchExclusions( + projectData, + platformData + ); const projectPodfilePath = this.$cocoapodsService.getProjectPodfilePath( platformData.projectRoot From c740a72ff86091b34eceb1c8aaa5b00069cedbe1 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sat, 3 Oct 2020 00:34:40 +0200 Subject: [PATCH 3/3] fix: tests --- .vscode/launch.json | 104 +++++++++++++++--------------- lib/services/cocoapods-service.ts | 4 +- test/ios-project-service.ts | 37 ++++++++++- 3 files changed, 90 insertions(+), 55 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index df2be71789..f05ba6546d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,54 +1,57 @@ { - // 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", "android@1.3.0", "--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", "android@1.3.0", "--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", + "name": "Attach to Node Debugger", "port": 9229, "request": "attach", "skipFiles": [ @@ -56,6 +59,5 @@ ], "type": "pwa-node" } - - ] -} \ No newline at end of file + ] +} diff --git a/lib/services/cocoapods-service.ts b/lib/services/cocoapods-service.ts index c94f394160..5ebc257102 100644 --- a/lib/services/cocoapods-service.ts +++ b/lib/services/cocoapods-service.ts @@ -143,14 +143,14 @@ ${versionResolutionHint}`); const exclusionsPodfile = path.join(projectRoot, "Podfile-exclusions"); if (!this.$fs.exists(exclusionsPodfile)) { - const exclusions = `${EOL} + 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`; +end`.trim(); this.$fs.writeFile(exclusionsPodfile, exclusions); } diff --git a/test/ios-project-service.ts b/test/ios-project-service.ts index 52589da2d9..e15079f69f 100644 --- a/test/ios-project-service.ts +++ b/test/ios-project-service.ts @@ -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); @@ -458,6 +476,7 @@ describe("Cocoapods support", () => { "platform :ios, '8.1'", "# End NativeScriptPlatformSection\n", ].join("\n"); + const expectedProjectPodfileContent = [ "use_frameworks!\n", `target "${projectName}" do`, @@ -465,6 +484,7 @@ describe("Cocoapods support", () => { `# Begin Podfile - ${pluginPodfilePath}`, expectedPluginPodfileContent, "# End Podfile", + expectedArchExclusions(projectPath), "end", ].join("\n"); assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent); @@ -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'", @@ -591,6 +611,7 @@ describe("Cocoapods support", () => { `# Begin Podfile - ${pluginPodfilePath}`, expectedPluginPodfileContent, "# End Podfile", + expectedArchExclusions(projectPath), "end", ].join("\n"); assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent); @@ -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 + ); }); } }); @@ -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);