From 9948e289cbfe43097b1205fa6f1272b5750b635d Mon Sep 17 00:00:00 2001
From: Carlos Sotelo <carlos.sotelo@outsystems.com>
Date: Fri, 25 Nov 2022 09:35:17 +0000
Subject: [PATCH] fix: changes default of CONFIGURATION_BUILD_DIR

this aims to fix #659 and #617
---
 bin/templates/scripts/cordova/lib/build.js |  6 ++++--
 tests/spec/unit/build.spec.js              | 22 ++++++++--------------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js
index ddcc4b6d00..c405f4cd90 100644
--- a/bin/templates/scripts/cordova/lib/build.js
+++ b/bin/templates/scripts/cordova/lib/build.js
@@ -326,7 +326,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
         ];
         buildActions = ['archive'];
         settings = [
-            customArgs.configuration_build_dir || `CONFIGURATION_BUILD_DIR=${path.join(projectPath, 'build', 'device')}`,
             customArgs.shared_precomps_dir || `SHARED_PRECOMPS_DIR=${path.join(projectPath, 'build', 'sharedpch')}`
         ];
         // Add other matched flags to otherFlags to let xcodebuild present an appropriate error.
@@ -348,7 +347,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
         ];
         buildActions = ['build'];
         settings = [
-            customArgs.configuration_build_dir || `CONFIGURATION_BUILD_DIR=${path.join(projectPath, 'build', 'emulator')}`,
             customArgs.shared_precomps_dir || `SHARED_PRECOMPS_DIR=${path.join(projectPath, 'build', 'sharedpch')}`
         ];
         // Add other matched flags to otherFlags to let xcodebuild present an appropriate error.
@@ -358,6 +356,10 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
         }
     }
 
+    if (customArgs.configuration_build_dir) {
+        settings.push(customArgs.configuration_build_dir);
+    }
+
     return options.concat(buildActions).concat(settings).concat(customArgs.otherFlags);
 }
 
diff --git a/tests/spec/unit/build.spec.js b/tests/spec/unit/build.spec.js
index 7ecf40eace..d78dfa0a36 100644
--- a/tests/spec/unit/build.spec.js
+++ b/tests/spec/unit/build.spec.js
@@ -47,10 +47,9 @@ describe('build', () => {
                 '-archivePath',
                 'TestProjectName.xcarchive',
                 'archive',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'device')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`
             ]);
-            expect(args.length).toEqual(13);
+            expect(args.length).toEqual(12);
         });
 
         it('should generate appropriate args if buildFlags are passed in', () => {
@@ -78,8 +77,8 @@ describe('build', () => {
                 '-archivePath',
                 'TestArchivePathFlag',
                 'archive',
-                'CONFIGURATION_BUILD_DIR=TestConfigBuildDirFlag',
-                'SHARED_PRECOMPS_DIR=TestSharedPrecompsDirFlag'
+                'SHARED_PRECOMPS_DIR=TestSharedPrecompsDirFlag',
+                'CONFIGURATION_BUILD_DIR=TestConfigBuildDirFlag'
             ]);
             expect(args.length).toEqual(13);
         });
@@ -99,10 +98,9 @@ describe('build', () => {
                 '-archivePath',
                 'TestProjectName.xcarchive',
                 'archive',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'device')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`
             ]);
-            expect(args.length).toEqual(13);
+            expect(args.length).toEqual(12);
         });
 
         it('should generate appropriate args for simulator', () => {
@@ -120,10 +118,9 @@ describe('build', () => {
                 '-destination',
                 'platform=iOS Simulator,name=iPhone 5s',
                 'build',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'emulator')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`
             ]);
-            expect(args.length).toEqual(13);
+            expect(args.length).toEqual(12);
         });
 
         it('should add matched flags that are not overriding for device', () => {
@@ -143,12 +140,11 @@ describe('build', () => {
                 '-archivePath',
                 'TestProjectName.xcarchive',
                 'archive',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'device')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`,
                 '-sdk',
                 'TestSdkFlag'
             ]);
-            expect(args.length).toEqual(15);
+            expect(args.length).toEqual(14);
         });
 
         it('should add matched flags that are not overriding for simulator', () => {
@@ -168,12 +164,11 @@ describe('build', () => {
                 '-destination',
                 'platform=iOS Simulator,name=iPhone 5s',
                 'build',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'emulator')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`,
                 '-archivePath',
                 'TestArchivePathFlag'
             ]);
-            expect(args.length).toEqual(15);
+            expect(args.length).toEqual(14);
         });
 
         it('should generate appropriate args for automatic provisioning', () => {
@@ -192,10 +187,9 @@ describe('build', () => {
                 'TestProjectName.xcarchive',
                 '-allowProvisioningUpdates',
                 'archive',
-                `CONFIGURATION_BUILD_DIR=${path.join(testProjectPath, 'build', 'device')}`,
                 `SHARED_PRECOMPS_DIR=${path.join(testProjectPath, 'build', 'sharedpch')}`
             ]);
-            expect(args.length).toEqual(14);
+            expect(args.length).toEqual(13);
         });
     });