This is an automated email from the ASF dual-hosted git repository.

dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d5a81bd fix(create): Ensure unix paths in Xcode project file (#1312)
8d5a81bd is described below

commit 8d5a81bd1a745c7e04e78b2c6390350cb5cadf3f
Author: Darryl Pogue <[email protected]>
AuthorDate: Wed May 17 06:33:32 2023 -0700

    fix(create): Ensure unix paths in Xcode project file (#1312)
    
    Cordova-iOS requires macOS for building and deploying, but it seems to
    be a fairly common problem that people generate the iOS project files on
    Windows (which isn't technically supported, but _appears_ to work) and
    then Xcode can't open it on macOS because of a bad path separator.
    
    The path separator problem is fixable, so let's at least generate a
    valid Xcode project.
    
    This does *not* claim to add support for using Cordova-iOS on Windows.
    
    Closes #971.
    Closes #1016.
    Closes #1084.
---
 lib/create.js                                      |  9 +++-
 tests/spec/coverage.json                           |  2 +-
 .../{create.spec.js => createAndBuild.spec.js}     |  0
 tests/spec/{ => unit}/create.spec.js               | 52 ++++++++--------------
 4 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/lib/create.js b/lib/create.js
index 2473c487..9aefb6ac 100755
--- a/lib/create.js
+++ b/lib/create.js
@@ -129,7 +129,14 @@ class ProjectCreator {
         const cdvLibRealPath = fs.realpathSync(this.projectPath('CordovaLib'));
 
         const cdvLibXcodeAbsPath = path.join(cdvLibRealPath, 
'CordovaLib.xcodeproj');
-        const cdvLibXcodePath = path.relative(this.project.path, 
cdvLibXcodeAbsPath);
+        let cdvLibXcodePath = path.relative(this.project.path, 
cdvLibXcodeAbsPath);
+
+        if (path.sep !== path.posix.sep) {
+            // If the Cordova project is being created on Windows, we need to
+            // make sure the Xcode project file uses POSIX-style paths or else
+            // Xcode considers it invalid
+            cdvLibXcodePath = cdvLibXcodePath.replace(path.sep, 
path.posix.sep);
+        }
 
         // Replace magic line in project.pbxproj
         const pbxprojPath = 
this.projectPath('__PROJECT_NAME__.xcodeproj/project.pbxproj');
diff --git a/tests/spec/coverage.json b/tests/spec/coverage.json
index 43b90e66..f70d3440 100644
--- a/tests/spec/coverage.json
+++ b/tests/spec/coverage.json
@@ -2,7 +2,7 @@
   "spec_dir": "tests/spec",
   "spec_files": [
       "unit/**/*[sS]pec.js",
-      "create.spec.js"
+      "createAndBuild.spec.js"
   ],
   "stopSpecOnExpectationFailure": false,
   "random": false
diff --git a/tests/spec/create.spec.js b/tests/spec/createAndBuild.spec.js
similarity index 100%
copy from tests/spec/create.spec.js
copy to tests/spec/createAndBuild.spec.js
diff --git a/tests/spec/create.spec.js b/tests/spec/unit/create.spec.js
similarity index 71%
rename from tests/spec/create.spec.js
rename to tests/spec/unit/create.spec.js
index ff2f7992..bbbcdeeb 100644
--- a/tests/spec/create.spec.js
+++ b/tests/spec/unit/create.spec.js
@@ -1,4 +1,4 @@
-/*
+/**
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
@@ -21,7 +21,7 @@ const fs = require('fs-extra');
 const os = require('os');
 const path = require('path');
 const xcode = require('xcode');
-const create = require('../../lib/create');
+const create = require('../../../lib/create');
 
 const makeTempDir = () => path.join(
     fs.realpathSync(os.tmpdir()),
@@ -40,6 +40,13 @@ function verifyProjectFiles (tmpDir, projectName) {
     expect(fs.existsSync(path.join(tmpDir, 
`${projectName}.xcodeproj`))).toBe(true);
     expect(fs.existsSync(path.join(tmpDir, 
`${projectName}.xcworkspace`))).toBe(true);
     expect(fs.existsSync(path.join(tmpDir, 'CordovaLib'))).toBe(true);
+
+    const pbxproj = path.join(tmpDir, `${projectName}.xcodeproj`, 
'project.pbxproj');
+    const pbxcontents = fs.readFileSync(pbxproj, 'utf-8');
+    const regex = 
/(.+CordovaLib.xcodeproj.+PBXFileReference.+wrapper.pb-project.+)(path = 
.+?;)(.*)(sourceTree.+;)(.+)/;
+    const line = pbxcontents.split(/\r?\n/).find(l => regex.test(l));
+
+    expect(line).toMatch(/path = CordovaLib\/CordovaLib.xcodeproj;/);
 }
 
 /**
@@ -50,7 +57,7 @@ function verifyProjectFiles (tmpDir, projectName) {
  * @param {String} expectedBundleIdentifier
  */
 function verifyProjectBundleIdentifier (tmpDir, projectName, 
expectedBundleIdentifier) {
-    const pbxproj = path.join(tmpDir, 
`${projectName}.xcodeproj/project.pbxproj`);
+    const pbxproj = path.join(tmpDir, `${projectName}.xcodeproj`, 
'project.pbxproj');
     const xcodeproj = xcode.project(pbxproj);
     xcodeproj.parseSync();
     const actualBundleIdentifier = 
xcodeproj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER');
@@ -58,38 +65,17 @@ function verifyProjectBundleIdentifier (tmpDir, 
projectName, expectedBundleIdent
 }
 
 /**
- * Runs and expects for a successful build.
- *
- * @param {String} tmpDir
- * @returns {Promise}
- */
-function verifyBuild (tmpDir) {
-    // Allow test project to find the `cordova-ios` module
-    fs.ensureSymlinkSync(
-        path.join(__dirname, '../..'),
-        path.join(tmpDir, 'node_modules/cordova-ios'),
-        'junction'
-    );
-
-    const Api = require(path.join(tmpDir, 'cordova/Api.js'));
-
-    return expectAsync(new Api('ios', tmpDir).build({ emulator: true }))
-        .toBeResolved();
-}
-
-/**
- * Runs various create and build checks.
+ * Runs various project creation checks.
  *
  * @param {String} tmpDir
  * @param {String} packageName
  * @param {String} projectName
  * @returns {Promise}
  */
-async function verifyCreateAndBuild (tmpDir, packageName, projectName) {
+async function verifyCreatedProject (tmpDir, packageName, projectName) {
     await create.createProject(tmpDir, packageName, projectName, {}, undefined)
         .then(() => verifyProjectFiles(tmpDir, projectName))
-        .then(() => verifyProjectBundleIdentifier(tmpDir, projectName, 
packageName))
-        .then(() => verifyBuild(tmpDir));
+        .then(() => verifyProjectBundleIdentifier(tmpDir, projectName, 
packageName));
 }
 
 describe('create', () => {
@@ -103,15 +89,15 @@ describe('create', () => {
         fs.removeSync(tmpDir);
     });
 
-    it('Test#001 : create project with ascii name, no spaces', () => {
+    it('should create project with ascii name, no spaces', () => {
         const packageName = 'com.test.app1';
         const projectName = 'testcreate';
-        return verifyCreateAndBuild(tmpDir, packageName, projectName);
-    }, 10 * 60 * 1000); // first build takes longer (probably cold caches)
+        return verifyCreatedProject(tmpDir, packageName, projectName);
+    });
 
-    it('Test#002 : create project with complicated name', () => {
+    it('should create project with complicated name', () => {
         const packageName = 'com.test.app2';
         const projectName = '応応応応 hello & إثرا 用用用用';
-        return verifyCreateAndBuild(tmpDir, packageName, projectName);
-    }, 5 * 60 * 1000);
+        return verifyCreatedProject(tmpDir, packageName, projectName);
+    });
 });


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to