You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2016/12/16 12:30:16 UTC

cordova-windows git commit: CB-12239 Add buildFlag option similar to iOS

Repository: cordova-windows
Updated Branches:
  refs/heads/master 707bf9628 -> 6308e6974


CB-12239 Add buildFlag option similar to iOS


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

Branch: refs/heads/master
Commit: 6308e6974f5499857254fb79c91ded422b46486f
Parents: 707bf96
Author: Vladimir Kotikov <ko...@gmail.com>
Authored: Mon Dec 12 18:45:51 2016 +0300
Committer: Vladimir Kotikov <ko...@gmail.com>
Committed: Tue Dec 13 13:03:29 2016 +0300

----------------------------------------------------------------------
 spec/unit/build.spec.js              | 62 +++++++++++++++++++++++++++++++
 template/cordova/build               |  5 ++-
 template/cordova/lib/MSBuildTools.js |  9 ++---
 template/cordova/lib/build.js        | 27 ++++++++++----
 4 files changed, 88 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/6308e697/spec/unit/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/build.spec.js b/spec/unit/build.spec.js
index e8fd8d8..3abd630 100644
--- a/spec/unit/build.spec.js
+++ b/spec/unit/build.spec.js
@@ -17,6 +17,7 @@
     under the License.
 */
 var Q = require('q'),
+    fs = require('fs'),
     path = require('path'),
     rewire = require('rewire'),
     platformRoot = '../../template',
@@ -395,3 +396,64 @@ describe('run method', function() {
         });
     });
 });
+
+describe('buildFlags', function () {
+
+    describe('parseAndValidateArgs method', function () {
+        var parseAndValidateArgs;
+        var readFileSync;
+
+        beforeEach(function () {
+            parseAndValidateArgs = build.__get__('parseAndValidateArgs');
+            readFileSync = spyOn(fs, 'readFileSync');
+        });
+
+        it('should handle build flags from both CLI and buildConfig.json', function () {
+            readFileSync.andReturn(JSON.stringify({
+                windows: { debug: { buildFlag: 'baz="quux"' } }
+            }));
+
+            var buildOptions = {
+                argv: ['--buildFlag', 'foo=bar', '--buildFlag', 'bar=baz', '--buildConfig', 'buildConfig.json']
+            };
+
+            expect(parseAndValidateArgs(buildOptions).buildFlags).toEqual([ 'baz="quux"', 'foo=bar', 'bar=baz' ]);
+        });
+    });
+
+    describe('build', function () {
+        beforeEach(function () {
+            spyOn(utils, 'isCordovaProject').andReturn(true);
+            spyOn(prepare, 'applyPlatformConfig');
+            spyOn(prepare, 'updateBuildConfig');
+            spyOn(package, 'getPackage').andReturn(Q({}));
+
+            spyOn(AppxManifest, 'get').andReturn({
+                getIdentity: function () {
+                    return  { setPublisher: function () {} };
+                },
+                write: function () {}
+            });
+        });
+
+        it('should pass buildFlags directly to MSBuild', function(done) {
+            var fail = jasmine.createSpy('fail');
+            var buildTools = {version: '14.0', buildProject: jasmine.createSpy('buildProject').andReturn(Q()), path: testPath };
+            var buildOptions = {
+                argv: ['--buildFlag', 'foo=bar']
+            };
+
+            createFindAllAvailableVersionsMock([buildTools]);
+
+            build.run(buildOptions)
+            .fail(fail)
+            .finally(function() {
+                expect(fail).not.toHaveBeenCalled();
+                expect(buildTools.buildProject).toHaveBeenCalledWith(jasmine.any(String),
+                    jasmine.any(String), jasmine.any(String), [ 'foo=bar' ]);
+
+                done();
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/6308e697/template/cordova/build
----------------------------------------------------------------------
diff --git a/template/cordova/build b/template/cordova/build
index 9816d41..18762e2 100644
--- a/template/cordova/build
+++ b/template/cordova/build
@@ -49,6 +49,7 @@ if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >=
     console.log('    --packageThumbprint         : Thumbprint associated with the certificate.');
     console.log('    --publisherId               : Sets publisher id field in manifest.');
     console.log('    --buildConfig               : Sets build settings from configuration file.');
+    console.log('    --buildFlag                 : Sets build flag to pass to MSBuild (can be specified multiple times)');
     console.log('');
     console.log('examples:');
     console.log('    build ');
@@ -59,6 +60,7 @@ if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >=
     console.log('    build --packageCertificateKeyFile="CordovaApp_TemporaryKey.pfx"');
     console.log('    build --publisherId="CN=FakeCorp, C=US"');
     console.log('    build --buildConfig="build.json"');
+    console.log('    build --buildFlag="/clp:Verbosity=normal" --buildFlag="/p:myBuildProperty=Foo"');
     console.log('');
 
     process.exit(0);
@@ -71,7 +73,8 @@ var buildOpts = nopt({
     'debug' : Boolean,
     'release' : Boolean,
     'nobuild': Boolean,
-    'buildConfig' : path
+    'buildConfig' : path,
+    'buildFlag': [String, Array]
 }, { d : '--verbose', r: '--release' });
 
 // Make buildOptions compatible with PlatformApi build method spec

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/6308e697/template/cordova/lib/MSBuildTools.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/MSBuildTools.js b/template/cordova/lib/MSBuildTools.js
index 7cc6794..6da98c8 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -29,7 +29,7 @@ function MSBuildTools (version, path) {
     this.path = path;
 }
 
-MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch, otherConfigProperties) {
+MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch, buildFlags) {
     events.emit('log', 'Building project: ' + projFile);
     events.emit('log', '\tConfiguration : ' + buildType);
     events.emit('log', '\tPlatform      : ' + buildarch);
@@ -46,11 +46,8 @@ MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch, o
     '/p:Configuration=' + buildType,
     '/p:Platform=' + buildarch];
 
-    if (otherConfigProperties) {
-        var keys = Object.keys(otherConfigProperties);
-        keys.forEach(function(key) {
-            args.push('/p:' + key + '=' + otherConfigProperties[key]);
-        });
+    if (buildFlags) {
+        args = args.concat(buildFlags);
     }
 
     var that = this;

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/6308e697/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/build.js b/template/cordova/lib/build.js
index b917ad0..b50d05a 100644
--- a/template/cordova/lib/build.js
+++ b/template/cordova/lib/build.js
@@ -161,7 +161,8 @@ function parseAndValidateArgs(options) {
         'packageCertificateKeyFile': String,
         'packageThumbprint': String,
         'publisherId': String,
-        'buildConfig': String
+        'buildConfig': String,
+        'buildFlag': [String, Array]
     }, {}, options.argv, 0);
 
     var config = {};
@@ -197,12 +198,16 @@ function parseAndValidateArgs(options) {
     }
 
     // if build.json is provided, parse it
-    var buildConfigPath = options.buildConfig;
+    var buildConfigPath = options.buildConfig || args.buildConfig;
     if (buildConfigPath) {
         buildConfig = parseBuildConfig(buildConfigPath, config.buildType);
         for (var prop in buildConfig) { config[prop] = buildConfig[prop]; }
     }
 
+    // Merge buildFlags from build config and CLI arguments into
+    // single array ensuring that ones from CLI take a precedence
+    config.buildFlags = [].concat(buildConfig.buildFlag || [], args.buildFlag || []);
+
     // CLI arguments override build.json config
     if (args.packageCertificateKeyFile) {
         args.packageCertificateKeyFile = path.resolve(process.cwd(), args.packageCertificateKeyFile);
@@ -260,6 +265,10 @@ function parseBuildConfig(buildConfigPath, buildType) {
         result.publisherId = windowsInfo.publisherId;
     }
 
+    if (windowsInfo.buildFlag) {
+        result.buildFlag = windowsInfo.buildFlag;
+    }
+
     return result;
 }
 
@@ -326,13 +335,15 @@ function buildTargets(allMsBuildVersions, config) {
                 build.arch = 'anycpu';
             }
 
-            var otherProperties = { };
-            // Only add the CordovaBundlePlatforms argument when on the last build step
-            if (shouldBundle && index === configsArray.length - 1) {
-                otherProperties.CordovaBundlePlatforms = bundleTerms;
-            } else if (shouldBundle) {
-                otherProperties.CordovaBundlePlatforms = build.arch;
+            // Send build flags to MSBuild
+            var otherProperties = [].concat(config.buildFlags);
+
+            if (shouldBundle) {
+                // Only add the CordovaBundlePlatforms argument when on the last build step
+                var bundleArchs = (index === configsArray.length - 1) ? bundleTerms : build.arch;
+                otherProperties.push('/p:CordovaBundlePlatforms=' + bundleArchs);
             }
+
             return msbuild.buildProject(path.join(ROOT, build.target), config.buildType,  build.arch, otherProperties);
          });
     }, Q());


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