erisu commented on a change in pull request #765: Fix error parsing 
plist_file_entry when adding extension in xcode
URL: https://github.com/apache/cordova-ios/pull/765#discussion_r367726717
 
 

 ##########
 File path: bin/templates/scripts/cordova/lib/projectFile.js
 ##########
 @@ -40,8 +40,18 @@ function parseProjectFile (locations) {
     const xcodeproj = xcode.project(pbxPath);
     xcodeproj.parseSync();
 
-    const xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection();
-    const plist_file_entry = _.find(xcBuildConfiguration, entry => 
entry.buildSettings && entry.buildSettings.INFOPLIST_FILE);
+    var projectName = '';
+    if (fs.readdirSync(project_dir).find(d => d.includes('.xcworkspace'))) {
+        projectName = fs.readdirSync(project_dir).find(d => 
d.includes('.xcworkspace')).replace('.xcworkspace', '');
+    }
+    var xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection();
+    var plist_file_entry = _.find(xcBuildConfiguration, function (entry) {
+        return (
+            entry.buildSettings &&
+            entry.buildSettings.INFOPLIST_FILE &&
+            projectName ? 
entry.buildSettings.INFOPLIST_FILE.includes(projectName) : true
+        );
+    });
     const plist_file = path.join(project_dir, 
plist_file_entry.buildSettings.INFOPLIST_FILE.replace(/^"(.*)"$/g, 
'$1').replace(/\\&/g, '&'));
 
 Review comment:
   I am not sure if this produces correct results always.
   
   What happens if there is two `-Info.plist` that has very close identical 
names.
   
   For example lets say our `projectName` is `MyApp`. The expected plist would 
be `MyApp-Info.plist`. Now what if there was another plist named 
`MyAppExtension-Info.plist`. This would also match from what is described 
above. It seems we are assuming that the order of the `xcBuildConfiguration` 
always returns our project first before other.
   
   Additionally, we are trying to remove the need of using third-party 
libraries such as `lodash`. I would recommend rewriting this area are such.
   
   ```
   const { buildSettings: { INFOPLIST_FILE : infoPlistFile } } = 
Object.values(xcBuildConfiguration)
       .filter(({ buildSettings }) => (
           buildSettings &&
           buildSettings.INFOPLIST_FILE &&
           projectName ? buildSettings.INFOPLIST_FILE.match(new 
RegExp(`/${projectName}-Info.plist"$`)) : false
       ))[0];
   const plist_file = path.join(project_dir, infoPlistFile.replace(/^"(.*)"$/g, 
'$1').replace(/\\&/g, '&'));
   ```
   
   If you use the above code, would recommend confirming that it continues to 
produce the same results as you expect.
   
   The code above will always expect to find at least one and in my case I 
always expect actually two results (`Debug` and `Release`). Since the InfoPlist 
path will be identical, I only take the first one `[0]`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to