cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject cordova-lib git commit: CB-8354 Add --link support for iOS source and header files
Date Fri, 23 Jan 2015 03:23:36 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 15adc1b9f -> 9e26991a3


CB-8354 Add --link support for iOS source and header files


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

Branch: refs/heads/master
Commit: 9e26991a3091ac198e2a8775d7e4fbba08eec5a2
Parents: 15adc1b
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jan 22 22:22:50 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jan 22 22:22:50 2015 -0500

----------------------------------------------------------------------
 cordova-lib/spec-plugman/platforms/ios.spec.js |  22 ++--
 cordova-lib/src/plugman/platforms/ios.js       | 131 ++++++++++----------
 2 files changed, 77 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/9e26991a/cordova-lib/spec-plugman/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/ios.spec.js b/cordova-lib/spec-plugman/platforms/ios.spec.js
index 0a032ab..0809d61 100644
--- a/cordova-lib/spec-plugman/platforms/ios.spec.js
+++ b/cordova-lib/spec-plugman/platforms/ios.spec.js
@@ -120,7 +120,7 @@ describe('ios project handler', function() {
                 var source = copyArray(invalid_source);
                 expect(function() {
                     ios['source-file'].install(source[1], faultyplugin, temp, faulty_id,
null, proj_files);
-                }).toThrow('cannot find "' + path.resolve(faultyplugin, 'src/ios/FaultyPluginCommand.m')
+ '" ios <source-file>');
+                }).toThrow();
             });
             it('should throw if source-file target already exists', function() {
                 var source = copyArray(valid_source);
@@ -129,7 +129,7 @@ describe('ios project handler', function() {
                 fs.writeFileSync(target, 'some bs', 'utf-8');
                 expect(function() {
                     ios['source-file'].install(source[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                }).toThrow('target destination "' + target + '" already exists');
+                }).toThrow();
             });
             it('should call into xcodeproj\'s addSourceFile appropriately when element has
no target-dir', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.targetDir
== undefined});
@@ -147,13 +147,13 @@ describe('ios project handler', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.targetDir
== undefined});
                 var spy = spyOn(shell, 'cp');
                 ios['source-file'].install(source[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.m'),
path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.m'));
+                expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios',
'DummyPluginCommand.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.m'));
             });
             it('should cp the file to the right target location when element has a target-dir',
function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.targetDir
!= undefined});
                 var spy = spyOn(shell, 'cp');
                 ios['source-file'].install(source[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.m'),
path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'));
+                expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios',
'TargetDirTest.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'));
             });
             it('should call into xcodeproj\'s addFramework appropriately when element has
framework=true set', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.framework;
});
@@ -169,7 +169,7 @@ describe('ios project handler', function() {
                 var headers = copyArray(invalid_headers);
                 expect(function() {
                     ios['header-file'].install(headers[1], faultyplugin, temp, faulty_id,
null, proj_files);
-                }).toThrow('cannot find "' + path.resolve(faultyplugin, 'src/ios/FaultyPluginCommand.h')
+ '" ios <header-file>');
+                }).toThrow();
             });
             it('should throw if header-file target already exists', function() {
                 var headers = copyArray(valid_headers);
@@ -178,7 +178,7 @@ describe('ios project handler', function() {
                 fs.writeFileSync(target, 'some bs', 'utf-8');
                 expect(function() {
                     ios['header-file'].install(headers[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                }).toThrow('target destination "' + target + '" already exists');
+                }).toThrow();
             });
             it('should call into xcodeproj\'s addHeaderFile appropriately when element has
no target-dir', function() {
                 var headers = copyArray(valid_headers).filter(function(s) { return s.targetDir
== undefined});
@@ -196,13 +196,13 @@ describe('ios project handler', function() {
                 var headers = copyArray(valid_headers).filter(function(s) { return s.targetDir
== undefined});
                 var spy = spyOn(shell, 'cp');
                 ios['header-file'].install(headers[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.h'),
path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.h'));
+                expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios',
'DummyPluginCommand.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.h'));
             });
             it('should cp the file to the right target location when element has a target-dir',
function() {
                 var headers = copyArray(valid_headers).filter(function(s) { return s.targetDir
!= undefined});
                 var spy = spyOn(shell, 'cp');
                 ios['header-file'].install(headers[0], dummyplugin, temp, dummy_id, null,
proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.h'),
path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.h'));
+                expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios',
'TargetDirTest.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.h'));
             });
         });
 
@@ -313,7 +313,7 @@ describe('ios project handler', function() {
 
                 var spy = spyOn(shell, 'rm');
                 ios['source-file'].uninstall(source[0], temp, dummy_id, null, proj_files);
-                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id, 'DummyPluginCommand.m'));
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id));
             });
             it('should rm the file from the right target location when element has a target-dir',
function(){
                 var source = copyArray(valid_source).filter(function(s) { return s.targetDir
!= undefined});
@@ -321,7 +321,7 @@ describe('ios project handler', function() {
                 var spy = spyOn(shell, 'rm');
 
                 ios['source-file'].uninstall(source[0], temp, dummy_id, null, proj_files);
-                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id, 'targetDir', 'TargetDirTest.m'));
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id, 'targetDir'));
             });
             it('should call into xcodeproj\'s removeFramework appropriately when element
framework=true set', function(){
                 var source = copyArray(valid_source).filter(function(s) { return s.framework;
});
@@ -357,7 +357,7 @@ describe('ios project handler', function() {
                 var spy = spyOn(shell, 'rm');
 
                 ios['header-file'].uninstall(headers[0], temp, dummy_id, null, proj_files);
-                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id, 'targetDir', 'TargetDirTest.h'));
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
dummy_id, 'targetDir'));
             });
         });
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/9e26991a/cordova-lib/src/plugman/platforms/ios.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/platforms/ios.js b/cordova-lib/src/plugman/platforms/ios.js
index 41d768f..4966a9d 100644
--- a/cordova-lib/src/plugman/platforms/ios.js
+++ b/cordova-lib/src/plugman/platforms/ios.js
@@ -23,6 +23,7 @@
 */
 
 var path = require('path')
+  , common = require('./common')
   , fs   = require('fs')
   , glob = require('glob')
   , xcode = require('xcode')
@@ -32,6 +33,67 @@ var path = require('path')
   , cachedProjectFiles = {}
   ;
 
+
+function installHelper(type, obj, plugin_dir, project_dir, plugin_id, options, project) {
+    var srcFile = path.resolve(plugin_dir, obj.src);
+    var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || '');
+    var destFile = path.join(targetDir, path.basename(obj.src));
+
+    var project_ref;
+    var link = !!(options && options.link);
+    if (link) {
+        var trueSrc = fs.realpathSync(srcFile);
+        // Create a symlink in the expected place, so that uninstall can use it.
+        common.copyNewFile(plugin_dir, trueSrc, project_dir, destFile, link);
+
+        // Xcode won't save changes to a file if there is a symlink involved.
+        // Make the Xcode reference the file directly.
+        // Note: Can't use path.join() here since it collapses 'Plugins/..', and xcode
+        // library special-cases Plugins/ prefix.
+        project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, trueSrc));
+    } else {
+        common.copyNewFile(plugin_dir, srcFile, project_dir, destFile, link);
+        project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, destFile));
+    }
+
+    if (type == 'header-file') {
+        project.xcode.addHeaderFile(project_ref);
+    } else if (obj.framework) {
+        var opt = { weak: obj.weak };
+        var project_relative = path.join(path.basename(project.xcode_path), project_ref);
+        project.xcode.addFramework(project_relative, opt);
+        project.xcode.addToLibrarySearchPaths({path:project_ref});
+    } else {
+        project.xcode.addSourceFile(project_ref, obj.compilerFlags ? {compilerFlags:obj.compilerFlags}
: {});
+    }
+}
+
+function uninstallHelper(type, obj, project_dir, plugin_id, options, project) {
+    var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || '');
+    var destFile = path.join(targetDir, path.basename(obj.src));
+
+    var project_ref;
+    var link = !!(options && options.link);
+    if (link) {
+        var trueSrc = fs.readlinkSync(destFile);
+        project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, trueSrc));
+    } else {
+        project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, destFile));
+    }
+
+    shell.rm('-rf', targetDir);
+
+    if (type == 'header-file') {
+        project.xcode.removeHeaderFile(project_ref);
+    } else if (obj.framework) {
+        var project_relative = path.join(path.basename(project.xcode_path), project_ref);
+        project.xcode.removeFramework(project_relative);
+        project.xcode.removeFromLibrarySearchPaths({path:project_ref});
+    } else {
+        project.xcode.removeSourceFile(project_ref);
+    }
+}
+
 module.exports = {
     www_dir:function(project_dir) {
         return path.join(project_dir, 'www');
@@ -42,79 +104,18 @@ module.exports = {
     },
     'source-file':{
         install:function(obj, plugin_dir, project_dir, plugin_id, options, project) {
-            var src = obj.src;
-            var srcFile = path.resolve(plugin_dir, src);
-            var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir ||
'');
-            var destFile = path.resolve(targetDir, path.basename(src));
-            var is_framework = obj.framework;
-
-            if (!fs.existsSync(srcFile)) throw new Error('cannot find "' + srcFile + '" ios
<source-file>');
-            if (fs.existsSync(destFile)) throw new Error('target destination "' + destFile
+ '" already exists');
-            var project_ref = path.join('Plugins', path.relative(project.plugins_dir, destFile));
-            project_ref = fixPathSep(project_ref);
-
-            if (is_framework) {
-                var opt = { weak: obj.weak };
-                var project_relative = path.join(path.basename(project.xcode_path), project_ref);
-                project.xcode.addFramework(project_relative, opt);
-                project.xcode.addToLibrarySearchPaths({path:project_ref});
-            } else {
-                project.xcode.addSourceFile(project_ref, obj.compilerFlags ? {compilerFlags:obj.compilerFlags}
: {});
-            }
-            shell.mkdir('-p', targetDir);
-            shell.cp(srcFile, destFile);
+            installHelper('source-file', obj, plugin_dir, project_dir, plugin_id, options,
project);
         },
         uninstall:function(obj, project_dir, plugin_id, options, project) {
-            var src = obj.src;
-            var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir ||
'');
-            var destFile = path.resolve(targetDir, path.basename(src));
-            var is_framework = obj.framework;
-
-            var project_ref = path.join('Plugins', path.relative(project.plugins_dir, destFile));
-            project_ref = fixPathSep(project_ref);
-            
-            project.xcode.removeSourceFile(project_ref);
-            if (is_framework) {
-                var project_relative = path.join(path.basename(project.xcode_path), project_ref);
-                project.xcode.removeFramework(project_relative);
-                project.xcode.removeFromLibrarySearchPaths({path:project_ref});
-            }
-            shell.rm('-rf', destFile);
-
-            if(fs.existsSync(targetDir) && fs.readdirSync(targetDir).length>0){
-                shell.rm('-rf', targetDir);
-            }
+            uninstallHelper('source-file', obj, project_dir, plugin_id, options, project);
         }
     },
     'header-file':{
         install:function(obj, plugin_dir, project_dir, plugin_id, options, project) {
-            var src = obj.src;
-            var srcFile = path.resolve(plugin_dir, src);
-            var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir ||
'');
-            var destFile = path.resolve(targetDir, path.basename(src));
-            if (!fs.existsSync(srcFile)) throw new Error('cannot find "' + srcFile + '" ios
<header-file>');
-            if (fs.existsSync(destFile)) throw new Error('target destination "' + destFile
+ '" already exists');
-            
-            var project_ref = path.join('Plugins', path.relative(project.plugins_dir, destFile));
-            project_ref = fixPathSep(project_ref);
-            
-            project.xcode.addHeaderFile(project_ref);
-            shell.mkdir('-p', targetDir);
-            shell.cp(srcFile, destFile);
+            installHelper('header-file', obj, plugin_dir, project_dir, plugin_id, options,
project);
         },
         uninstall:function(obj, project_dir, plugin_id, options, project) {
-            var src = obj.src;
-            var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir ||
'');
-            var destFile = path.resolve(targetDir, path.basename(src));
-            
-            var project_ref = path.join('Plugins', path.relative(project.plugins_dir, destFile));
-            project_ref = fixPathSep(project_ref);
-            
-            project.xcode.removeHeaderFile(project_ref);
-            shell.rm('-rf', destFile);
-            if(fs.existsSync(targetDir) && fs.readdirSync(targetDir).length>0){
-                shell.rm('-rf', targetDir);
-            }
+            uninstallHelper('header-file', obj, project_dir, plugin_id, options, project);
         }
     },
     'resource-file':{


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


Mime
View raw message