You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/09/29 23:23:42 UTC

ios commit: CB-11771 Deep symlink directories to target project instead of linking the directory itself

Repository: cordova-ios
Updated Branches:
  refs/heads/master 35df991ea -> c6587cffe


CB-11771 Deep symlink directories to target project instead of linking the directory itself

When installing a plugin with custom library using the --link option the whole directory is symlinked and temporary
files leak into the original plugin directory on build. This leads to broken builds if the same plugin is linked in
2 projects targeting different Cordova versions.

Respect the --link option in resource-file and framework handlers.
Fix failing unit test on Windows.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c6587cff
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c6587cff
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c6587cff

Branch: refs/heads/master
Commit: c6587cffe7afded445500c2f30addfdf65290797
Parents: 35df991
Author: Martin Bektchiev <ma...@telerik.com>
Authored: Fri Aug 26 17:45:59 2016 +0300
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Sep 29 16:22:01 2016 -0700

----------------------------------------------------------------------
 .../cordova/lib/plugman/pluginHandlers.js       | 31 +++++++++++++++-----
 tests/spec/unit/Plugman/pluginHandler.spec.js   | 24 +++++++++++++--
 2 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c6587cff/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js
index e0eafdc..297e386 100644
--- a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js
+++ b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js
@@ -53,7 +53,8 @@ var handlers = {
             if (!fs.existsSync(srcFile)) throw new CordovaError('Cannot find resource file "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform');
             if (fs.existsSync(destFile)) throw new CordovaError('File already exists at detination "' + destFile + '" for resource file specified by plugin ' + plugin.id + ' in iOS platform');
             project.xcode.addResourceFile(path.join('Resources', path.basename(src)));
-            shell.cp('-R', srcFile, project.resources_dir);
+            var link = !!(options && options.link);
+            copyFile(plugin.dir, src, project.projectDir, destFile, link);
         },
         uninstall:function(obj, plugin, project, options) {
             var src = obj.src,
@@ -69,7 +70,7 @@ var handlers = {
             if (!custom) {
                 var keepFrameworks = keep_these_frameworks;
 
-                if (keepFrameworks.indexOf(src) < 0) { 
+                if (keepFrameworks.indexOf(src) < 0) {
                     if (obj.type === 'podspec') {
                         //podspec handled in Api.js
                     } else {
@@ -84,8 +85,8 @@ var handlers = {
                 targetDir = path.resolve(project.plugins_dir, plugin.id, path.basename(src));
             if (!fs.existsSync(srcFile)) throw new CordovaError('Cannot find framework "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform');
             if (fs.existsSync(targetDir)) throw new CordovaError('Framework "' + targetDir + '" for plugin ' + plugin.id + ' already exists in iOS platform');
-            shell.mkdir('-p', path.dirname(targetDir));
-            shell.cp('-R', srcFile, path.dirname(targetDir)); // frameworks are directories
+            var link = !!(options && options.link);
+            copyFile(plugin.dir, src, project.projectDir, targetDir, link); // frameworks are directories
             // CB-10773 translate back slashes to forward on win32
             var project_relative = fixPathSep(path.relative(project.projectDir, targetDir));
             var pbxFile = project.xcode.addFramework(project_relative, {customFramework: true});
@@ -109,7 +110,7 @@ var handlers = {
                             }
                         }
                     } else {
-                        //this should be refactored 
+                        //this should be refactored
                         project.frameworks[src] = project.frameworks[src] || 1;
                         project.frameworks[src]--;
                         if (project.frameworks[src] < 1) {
@@ -303,10 +304,10 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
     shell.mkdir('-p', path.dirname(dest));
 
     if (link) {
-        fs.symlinkSync(path.relative(path.dirname(dest), src), dest);
+        symlinkFileOrDirTree(src, dest);
     } else if (fs.statSync(src).isDirectory()) {
         // XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
-        shell.cp('-Rf', src+'/*', dest);
+        shell.cp('-Rf', path.join(src, '/*'), dest);
     } else {
         shell.cp('-f', src, dest);
     }
@@ -321,6 +322,22 @@ function copyNewFile (plugin_dir, src, project_dir, dest, link) {
     copyFile(plugin_dir, src, project_dir, dest, !!link);
 }
 
+function symlinkFileOrDirTree(src, dest) {
+    if (fs.existsSync(dest)) {
+        shell.rm('-Rf', dest);
+    }
+
+    if (fs.statSync(src).isDirectory()) {
+        shell.mkdir('-p', dest);
+        fs.readdirSync(src).forEach(function(entry) {
+            symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
+        });
+    }
+    else {
+        fs.symlinkSync(path.relative(fs.realpathSync(path.dirname(dest)), src), dest);
+    }
+}
+
 // checks if file exists and then deletes. Error if doesn't exist
 function removeFile (project_dir, src) {
     var file = path.resolve(project_dir, src);

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c6587cff/tests/spec/unit/Plugman/pluginHandler.spec.js
----------------------------------------------------------------------
diff --git a/tests/spec/unit/Plugman/pluginHandler.spec.js b/tests/spec/unit/Plugman/pluginHandler.spec.js
index 8f3846e..a217838 100644
--- a/tests/spec/unit/Plugman/pluginHandler.spec.js
+++ b/tests/spec/unit/Plugman/pluginHandler.spec.js
@@ -215,7 +215,16 @@ describe('ios plugin handler', function() {
                 var resources = copyArray(valid_resources);
                 var spy = spyOn(shell, 'cp');
                 install(resources[0], dummyPluginInfo, dummyProject);
-                expect(spy).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources'));
+                expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources', 'DummyPlugin.bundle'));
+            });
+            it('should symlink files to the right target location', function() {
+                var resources = copyArray(valid_resources);
+                var spy = spyOn(fs, 'symlinkSync');
+                install(resources[0], dummyPluginInfo, dummyProject, { link: true });
+                var src_bundle = path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle');
+                var dest_bundle = path.join(temp, 'SampleApp/Resources/DummyPlugin.bundle');
+                expect(spy).toHaveBeenCalledWith(path.relative(fs.realpathSync(path.dirname(dest_bundle)), src_bundle),
+                                                    dest_bundle);
             });
         });
 
@@ -256,8 +265,17 @@ describe('ios plugin handler', function() {
                     var frameworks = copyArray(valid_custom_frameworks);
                     var spy = spyOn(shell, 'cp');
                     install(frameworks[0], dummyPluginInfo, dummyProject);
-                    expect(spy).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'src', 'ios', 'Custom.framework'),
-                                                     path.join(temp, 'SampleApp/Plugins/org.test.plugins.dummyplugin'));
+                    expect(spy).toHaveBeenCalledWith('-Rf', path.join(dummyplugin, 'src', 'ios', 'Custom.framework', '*'),
+                                                     path.join(temp, 'SampleApp/Plugins/org.test.plugins.dummyplugin/Custom.framework'));
+                });
+                it('should deep symlink files to the right target location', function() {
+                    var frameworks = copyArray(valid_custom_frameworks);
+                    var spy = spyOn(fs, 'symlinkSync');
+                    install(frameworks[0], dummyPluginInfo, dummyProject, { link: true });
+                    var src_binlib = path.join(dummyplugin, 'src', 'ios', 'Custom.framework', 'somebinlib');
+                    var dest_binlib = path.join(temp, 'SampleApp/Plugins/org.test.plugins.dummyplugin/Custom.framework/somebinlib');
+                    expect(spy).toHaveBeenCalledWith(path.relative(fs.realpathSync(path.dirname(dest_binlib)), src_binlib),
+                                                     dest_binlib);
                 });
             });
         });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org