diff --git a/.vscode/launch.json b/.vscode/launch.json index e1dd227cc5..f05ba6546d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", "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 - } - - ] -} \ No newline at end of file + // 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 to Node Debugger", + "port": 9229, + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "pwa-node" + } + ] +} diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 5f092ae1f7..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. diff --git a/lib/services/cocoapods-service.ts b/lib/services/cocoapods-service.ts index 4163948628..5ebc257102 100644 --- a/lib/services/cocoapods-service.ts +++ b/lib/services/cocoapods-service.ts @@ -135,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 = ` +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, diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index f4795f4b04..9ac2b56048 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -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 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);