You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ro...@apache.org on 2015/07/31 19:08:47 UTC
cordova-windows git commit: CB-9359: Adds support for .appxbundle
creation
Repository: cordova-windows
Updated Branches:
refs/heads/master 16103ea2f -> eeda3df07
CB-9359: Adds support for .appxbundle creation
.appxbundle files are convenient app packages which can be uploaded to the
Windows Store. They contain debug or release (typically release) versions
of more than one of the x86, x64, and ARM architectures, and/or they
contain multiple resource packs (for example, both the scale-100 and
scale-240 packs).
To enable bundling, pass in the --bundle flag:
cordova build windows -- --archs="x86 x64 arm" --bundle
Bundling is disabled if `anycpu` is one of the architectures and multiple
architectures are passed, since bundles can't contain both an
architecture-specific target and a neutral target. For example, the
following command line would be invalid, and bundling would be disabled:
cordova build windows -- --archs="x86 x64 arm anycpu" --bundle
Bundling is not supported for Windows 8 as the feature is not available
for that platform in general.
Also corrected an issue in run.spec.js, that caused the build to not be
executed when running as an administrator.
Note: Also contains CR feedback and changed the approach to opt-in instead of opt-out, since
there may be times (specifically around resource generation) in which it
would be interesting to build a .appxbundle with AnyCPU targeted.
This closes #102
Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/eeda3df0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/eeda3df0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/eeda3df0
Branch: refs/heads/master
Commit: eeda3df0711cee0ff7beb761aac33e18b534b5f0
Parents: 16103ea
Author: Rob Paveza <Ro...@microsoft.com>
Authored: Mon Jul 13 13:37:45 2015 -0700
Committer: Rob Paveza <Ro...@microsoft.com>
Committed: Fri Jul 31 10:08:06 2015 -0700
----------------------------------------------------------------------
bin/lib/check_reqs.js | 2 +-
spec/unit/build.spec.js | 31 ++--
spec/unit/package.spec.js | 20 +--
spec/unit/run.spec.js | 29 +++-
template/CordovaApp.Phone.jsproj | 4 +
template/CordovaApp.Windows.jsproj | 4 +
template/CordovaApp.Windows10.jsproj | 5 +
template/cordova/lib/MSBuildTools.js | 19 ++-
template/cordova/lib/build.js | 248 +++++++++++++++++++++++++++---
template/cordova/lib/package.js | 22 ++-
template/cordova/lib/run.js | 18 ++-
11 files changed, 336 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 41eac1e..377f0f3 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -281,7 +281,7 @@ var checkOS = function () {
* or rejected with error message.
*/
var checkMSBuild = function () {
- return MSBuildTools.findAvailableVersions()
+ return MSBuildTools.findAllAvailableVersions()
.then(function (msbuildToolsVersions) {
var msbuildRequiredVersion = getMinimalRequiredVersionFor('msbuild');
msbuildToolsVersions = msbuildToolsVersions.map(function (msbuildToolsVersion) {
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/spec/unit/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/build.spec.js b/spec/unit/build.spec.js
index 44f0a08..e87ca3e 100644
--- a/spec/unit/build.spec.js
+++ b/spec/unit/build.spec.js
@@ -39,6 +39,12 @@ function createFindAvailableVersionMock(version, path, buildSpy) {
});
}
+function createFindAllAvailableVersionsMock(versionSet) {
+ build.__set__('MSBuildTools.findAllAvailableVersions', function() {
+ return Q.resolve(versionSet);
+ });
+}
+
function createConfigParserMock(winVersion, phoneVersion) {
build.__set__('ConfigParser', function() {
return {
@@ -99,7 +105,7 @@ describe('run method', function() {
buildSpy = jasmine.createSpy();
build.__set__('utils.isCordovaProject', isCordovaProjectFalse);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.run([ 'node', buildPath, '--release', '--debug' ])
.fail(rejectSpy)
@@ -148,7 +154,7 @@ describe('run method', function() {
});
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
build.run([ 'node', buildPath, '--release' ])
@@ -164,7 +170,7 @@ describe('run method', function() {
});
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
build.run([ 'node', buildPath ])
@@ -180,7 +186,7 @@ describe('run method', function() {
});
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
build.run([ 'node', buildPath, '--archs=arm' ])
@@ -197,11 +203,11 @@ describe('run method', function() {
anyCpuBuild = jasmine.createSpy();
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- build.__set__('MSBuildTools.findAvailableVersion', function() {
- return Q.resolve({
+ createFindAllAvailableVersionsMock([
+ {
version: '14.0',
path: testPath,
- buildProject: function (solutionFile, buildType, buildArch) {
+ buildProject: function(solutionFile, buildType, buildArch) {
expect(buildArch).toMatch(/^arm$|^any\s?cpu$|^x86$|^x64$/);
switch (buildArch) {
case 'arm':
@@ -221,8 +227,7 @@ describe('run method', function() {
return Q.reject();
}
}
- });
- });
+ }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
build.run([ 'node', buildPath, '--archs=arm x86 x64 anycpu', '--phone' ])
@@ -239,7 +244,7 @@ describe('run method', function() {
var buildSpy = jasmine.createSpy();
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('4.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '4.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
createConfigParserMock('8.0');
@@ -254,7 +259,7 @@ describe('run method', function() {
var buildSpy = jasmine.createSpy();
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
createConfigParserMock('8.1');
@@ -290,7 +295,7 @@ describe('run method', function() {
var buildSpy = jasmine.createSpy();
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
createConfigParserMock(null, '8.1');
@@ -329,7 +334,7 @@ describe('run method', function() {
});
build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
- createFindAvailableVersionMock('14.0', testPath, buildSpy);
+ createFindAllAvailableVersionsMock([{version: '14.0', buildProject: buildSpy, path: testPath }]);
build.__set__('prepare.applyPlatformConfig', function() {} );
// provision config to target Windows 8.1
createConfigParserMock('8.1', '8.1');
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/spec/unit/package.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/package.spec.js b/spec/unit/package.spec.js
index cc7be6f..6eeea4c 100644
--- a/spec/unit/package.spec.js
+++ b/spec/unit/package.spec.js
@@ -48,16 +48,16 @@ describe('getPackage method', function() {
var rejected = jasmine.createSpy();
pkg.getPackage('windows80', 'debug', 'anycpu')
- .then(function(pkgInfo) {
- expect(pkgInfo.type).toBe('windows80');
- expect(pkgInfo.buildtype).toBe('debug');
- expect(pkgInfo.arch).toBe('anycpu');
- expect(pkgInfo.script).toBeDefined();
- }, rejected)
- .finally(function() {
- expect(rejected).not.toHaveBeenCalled();
- done();
- });
+ .then(function(pkgInfo) {
+ expect(pkgInfo.type).toBe('windows80');
+ expect(pkgInfo.buildtype).toBe('debug');
+ expect(pkgInfo.arch).toBe('anycpu');
+ expect(pkgInfo.script).toBeDefined();
+ }, rejected)
+ .finally(function() {
+ expect(rejected).not.toHaveBeenCalled();
+ done();
+ });
});
it('spec.2 should find windows phone anycpu debug package', function(done) {
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/spec/unit/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/run.spec.js b/spec/unit/run.spec.js
index 2491bca..3171dfb 100644
--- a/spec/unit/run.spec.js
+++ b/spec/unit/run.spec.js
@@ -131,12 +131,22 @@ describe('run method', function() {
it('spec.5 should build and deploy on phone if --phone arg specified', function(done) {
var build = jasmine.createSpy(),
deployToPhone = jasmine.createSpy(),
- deployToDesktop = jasmine.createSpy();
+ deployToDesktop = jasmine.createSpy(),
+ failed = jasmine.createSpy();
run.__set__('utils.isCordovaProject', isCordovaProjectTrue);
run.__set__('build.run', function () {
build();
- return Q();
+ var buildResult = {
+ type : 'phone',
+ arch : 'arm',
+ archs : ['arm'],
+ buildtype : 'release',
+ appx : 'testfile',
+ script : 'testfile.ps1',
+ phoneId : 'undefined'
+ };
+ return Q(buildResult);
});
run.__set__('packages.getPackage', function () {
return Q({
@@ -153,8 +163,10 @@ describe('run method', function() {
return Q();
});
- run.run([ 'node', buildPath, '--phone' ])
+ run.run([ 'node', buildPath, '--phone', '--break' ])
+ .catch(failed)
.finally(function(){
+ expect(failed).not.toHaveBeenCalled();
expect(build).toHaveBeenCalled();
expect(deployToPhone).toHaveBeenCalled();
expect(deployToDesktop).not.toHaveBeenCalled();
@@ -170,7 +182,16 @@ describe('run method', function() {
run.__set__('utils.isCordovaProject', isCordovaProjectTrue);
run.__set__('build.run', function () {
build();
- return Q();
+ var buildResult = {
+ type : 'windows80',
+ arch : 'anycpu',
+ archs : ['anycpu'],
+ buildtype : 'release',
+ appx : 'testfile',
+ script : 'testfile.ps1',
+ phoneId : 'undefined'
+ };
+ return Q(buildResult);
});
run.__set__('packages.getPackage', function () {
return Q({
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/CordovaApp.Phone.jsproj
----------------------------------------------------------------------
diff --git a/template/CordovaApp.Phone.jsproj b/template/CordovaApp.Phone.jsproj
index 3a151dd..fb900e3 100644
--- a/template/CordovaApp.Phone.jsproj
+++ b/template/CordovaApp.Phone.jsproj
@@ -59,6 +59,10 @@
<PropertyGroup Label="Globals">
<ProjectGuid>31b67a35-9503-4213-857e-f44eb42ae549</ProjectGuid>
</PropertyGroup>
+ <PropertyGroup Label="CordovaBuildParameters" Condition="'$(CordovaBundlePlatforms)' != ''">
+ <AppxBundle>Always</AppxBundle>
+ <AppxBundlePlatforms>$(CordovaBundlePlatforms)</AppxBundlePlatforms>
+ </PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '12.0'">
<VisualStudioVersion>12.0</VisualStudioVersion>
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/CordovaApp.Windows.jsproj
----------------------------------------------------------------------
diff --git a/template/CordovaApp.Windows.jsproj b/template/CordovaApp.Windows.jsproj
index 65951a1..f13153e 100644
--- a/template/CordovaApp.Windows.jsproj
+++ b/template/CordovaApp.Windows.jsproj
@@ -59,6 +59,10 @@
<PropertyGroup Label="Globals">
<ProjectGuid>58950fb6-2f93-4963-b9cd-637f83f3efbf</ProjectGuid>
</PropertyGroup>
+ <PropertyGroup Label="CordovaBuildParameters" Condition="'$(CordovaBundlePlatforms)' != ''">
+ <AppxBundle>Always</AppxBundle>
+ <AppxBundlePlatforms>$(CordovaBundlePlatforms)</AppxBundlePlatforms>
+ </PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '12.0'">
<VisualStudioVersion>12.0</VisualStudioVersion>
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/CordovaApp.Windows10.jsproj
----------------------------------------------------------------------
diff --git a/template/CordovaApp.Windows10.jsproj b/template/CordovaApp.Windows10.jsproj
index bc3bf3e..a5957fe 100644
--- a/template/CordovaApp.Windows10.jsproj
+++ b/template/CordovaApp.Windows10.jsproj
@@ -60,6 +60,10 @@
<PropertyGroup Label="Globals">
<ProjectGuid>f9b0ae20-c91c-42b9-9c6e-d3bc28b4509e</ProjectGuid>
</PropertyGroup>
+ <PropertyGroup Label="CordovaBuildParameters" Condition="'$(CordovaBundlePlatforms)' != ''">
+ <AppxBundle>Always</AppxBundle>
+ <AppxBundlePlatforms>$(CordovaBundlePlatforms)</AppxBundlePlatforms>
+ </PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0'">
<VisualStudioVersion>14.0</VisualStudioVersion>
@@ -71,6 +75,7 @@
<TargetPlatformVersion>10.0.10030.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10030.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
+ <UapDefaultAssetScale>100</UapDefaultAssetScale>
</PropertyGroup>
<!--
MSBuild\12.0\Bin\Microsoft.Common.CurrentVersion.targets contains a "TargetPlatformVersion" check, which will throw if
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/cordova/lib/MSBuildTools.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/MSBuildTools.js b/template/cordova/lib/MSBuildTools.js
index d18502d..f4af64d 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) {
+MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch, otherConfigProperties) {
console.log('Building project: ' + projFile);
console.log('\tConfiguration : ' + buildType);
console.log('\tPlatform : ' + buildarch);
@@ -38,6 +38,13 @@ MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch) {
'/p:Configuration=' + buildType,
'/p:Platform=' + buildarch];
+ if (otherConfigProperties) {
+ var keys = Object.keys(otherConfigProperties);
+ keys.forEach(function(key) {
+ args.push('/p:' + key + '=' + otherConfigProperties[key]);
+ });
+ }
+
return spawn(path.join(this.path, 'msbuild'), [projFile].concat(args));
};
@@ -53,14 +60,12 @@ module.exports.findAvailableVersion = function () {
});
};
-module.exports.findAvailableVersions = function () {
+module.exports.findAllAvailableVersions = function () {
var versions = ['14.0', '12.0', '4.0'];
- return Q.all(versions.map(checkMSBuildVersion))
- .then(function (toolsVersions) {
- return toolsVersions
- .filter(function (tool) {
- return tool;
+ return Q.all(versions.map(checkMSBuildVersion)).then(function(unprocessedResults) {
+ return unprocessedResults.filter(function(item) {
+ return !!item;
});
});
};
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/build.js b/template/cordova/lib/build.js
index b6eeff9..e693d37 100644
--- a/template/cordova/lib/build.js
+++ b/template/cordova/lib/build.js
@@ -23,6 +23,7 @@ var Q = require('Q'),
shell = require('shelljs'),
utils = require('./utils'),
prepare = require('./prepare'),
+ package = require('./package'),
MSBuildTools = require('./MSBuildTools'),
ConfigParser = require('./ConfigParser'),
fs = require('fs');
@@ -39,21 +40,22 @@ var projFiles = {
// builds cordova-windows application with parameters provided.
// See 'help' function for args list
module.exports.run = function run (argv) {
- // MSBuild Tools available on this development machine
- var msbuild;
if (!utils.isCordovaProject(ROOT)){
return Q.reject('Could not find project at ' + ROOT);
}
- return Q.all([parseAndValidateArgs(argv), MSBuildTools.findAvailableVersion()])
+ return Q.all([parseAndValidateArgs(argv), MSBuildTools.findAllAvailableVersions()])
.spread(function(buildConfig, msbuildTools) {
// Apply build related configs
prepare.updateBuildConfig(buildConfig);
+ // bug: Windows 8 build fails on a system with MSBuild 14 on it.
+ // Don't regress, make sure MSBuild 4 is selected for a Windows 8 build.
cleanIntermediates();
- msbuild = msbuildTools;
- console.log('MSBuildToolsPath: ' + msbuild.path);
- return buildTargets(msbuild, buildConfig);
+ return buildTargets(msbuildTools, buildConfig).then(function(pkg) {
+ console.log(' BUILD OUTPUT: ' + pkg.appx);
+ return pkg;
+ });
}, function(error) {
return Q.reject(error);
});
@@ -62,20 +64,21 @@ module.exports.run = function run (argv) {
// help/usage function
module.exports.help = function help() {
console.log('');
- console.log('Usage: build [--debug | --release] [--archs="<list of architectures...>"]');
- console.log(' [--phone | --win] [--packageCertificateKeyFile="key path"]');
+ console.log('Usage: build [--debug | --release] [--phone | --win] [--bundle]');
+ console.log(' [--archs="<list of architectures...>"');
+ console.log(' [--packageCertificateKeyFile="key path"]');
console.log(' [--packageThumbprint="thumbprint"] [--publisherId]');
console.log(' [--buildConfig="file path"]');
console.log(' --help : Displays this dialog.');
console.log(' --debug : Builds project in debug mode. (Default).');
- console.log(' --release : Builds project in release mode.');
- console.log(' -r : (shortcut) Builds project in release mode.');
+ console.log(' --release (-r) : Builds project in release mode.');
+ console.log(' --phone, --win : Specifies, what type of project to build.');
+ console.log(' --bundle : Tells the compiler to create a .appxbundle.');
+ console.log(' Bundling is disabled when `anycpu` is built.');
console.log(' --archs : Builds project binaries for specific chip');
console.log(' architectures (`anycpu`, `arm`, `x86`, `x64`).');
console.log(' Separate multiple choices with spaces and if');
console.log(' passing multiple choices, enclose with " ".');
- console.log(' --phone, --win');
- console.log(' : Specifies, what type of project to build.');
console.log(' --appx=<8.1-win|8.1-phone|uap>');
console.log(' : Overrides windows-target-version to build');
console.log(' Windows 8.1, Windows Phone 8.1, or');
@@ -89,7 +92,7 @@ module.exports.help = function help() {
console.log(' build ');
console.log(' build --debug');
console.log(' build --release');
- console.log(' build --release --archs="arm x86"');
+ console.log(' build --release --archs="arm x86" --bundle');
console.log(' build --appx=8.1-phone -r');
console.log(' build --packageCertificateKeyFile="CordovaApp_TemporaryKey.pfx"');
console.log(' build --publisherId="CN=FakeCorp, C=US"');
@@ -175,6 +178,7 @@ function parseAndValidateArgs(argv) {
'appx': String,
'phone': Boolean,
'win': Boolean,
+ 'bundle': Boolean,
'packageCertificateKeyFile': String,
'packageThumbprint': String,
'publisherId': String,
@@ -199,7 +203,17 @@ function parseAndValidateArgs(argv) {
config.buildArchs = args.archs ? args.archs.split(' ') : ['anycpu'];
config.phone = args.phone ? true : false;
config.win = args.win ? true : false;
- config.projOverride = args.appx;
+ config.projVerOverride = args.appx;
+ // only set config.bundle if architecture is not anycpu
+ if (args.bundle) {
+ if ((config.buildArchs.indexOf('anycpu') > -1 || config.buildArchs.indexOf('any cpu') > -1) && config.buildArchs.length > 1) {
+ // Not valid to bundle anycpu with cpu-specific architectures. warn, then don't bundle
+ console.warn('Warning: anycpu and CPU-specific architectures were selected. This is not valid');
+ console.warn(' when enabling bundling with --bundle. Disabling bundling for this build.');
+ } else {
+ config.bundle = true;
+ }
+ }
// if build.json is provided, parse it
var buildConfigPath = args.buildConfig;
@@ -216,7 +230,6 @@ function parseAndValidateArgs(argv) {
config.packageThumbprint = config.packageThumbprint || args.packageThumbprint;
config.publisherId = config.publisherId || args.publisherId;
-
resolve(config);
});
}
@@ -268,11 +281,26 @@ function parseBuildConfig(buildConfigPath, config) {
return result;
}
-function buildTargets(msbuild, config) {
+function buildTargets(allMsBuildVersions, config) {
// filter targets to make sure they are supported on this development machine
- var myBuildTargets = filterSupportedTargets(module.exports.getBuildTargets(config.win, config.phone, config.projOverride), msbuild);
+ var selectedBuildTargets = getBuildTargets(config);
+ var msbuild = getMsBuildForTargets(selectedBuildTargets, config, allMsBuildVersions);
+ if (!msbuild) {
+ return Q.reject('No valid MSBuild was detected for the selected target.');
+ }
+ console.log('MSBuildToolsPath: ' + msbuild.path);
+ var myBuildTargets = filterSupportedTargets(selectedBuildTargets, msbuild);
var buildConfigs = [];
+ var bundleTerms = '';
+ var hasAnyCpu = false;
+ var shouldBundle = !!config.bundle;
+ if (myBuildTargets.indexOf(projFiles.win80) > -1) {
+ if (shouldBundle) {
+ console.warn('Warning: Bundling is disabled because a Windows 8 project was detected.');
+ }
+ shouldBundle = false;
+ }
// collect all build configurations (pairs of project to build and target architecture)
myBuildTargets.forEach(function(buildTarget) {
@@ -281,11 +309,23 @@ function buildTargets(msbuild, config) {
target:buildTarget,
arch: buildArch
});
+
+ if (buildArch === 'anycpu' || buildArch === 'any cpu') {
+ hasAnyCpu = true;
+ bundleTerms = 'neutral';
+ }
+
+ if (!hasAnyCpu) {
+ if (bundleTerms.length > 0) {
+ bundleTerms += '|';
+ }
+ bundleTerms += buildArch;
+ }
});
});
// run builds serially
- return buildConfigs.reduce(function (promise, build) {
+ var buildsCompleted = buildConfigs.reduce(function (promise, build, index, configsArray) {
return promise.then(function () {
// support for "any cpu" specified with or without space
if (build.arch == 'any cpu') {
@@ -295,9 +335,179 @@ function buildTargets(msbuild, config) {
if (msbuild.version == '4.0' && build.target == projFiles.win80) {
build.target = 'CordovaApp.vs2012.sln';
}
- return msbuild.buildProject(path.join(ROOT, build.target), config.buildType, build.arch);
+
+ 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;
+ }
+ return msbuild.buildProject(path.join(ROOT, build.target), config.buildType, build.arch, otherProperties);
});
}, Q());
+
+ if (shouldBundle) {
+ return buildsCompleted.then(function() {
+ return clearIntermediatesAndGetPackage(bundleTerms, config, hasAnyCpu);
+ });
+ } else {
+ return buildsCompleted.then(function() {
+ return package.getPackage(config.targetProject, config.buildType, config.buildArchs[0]);
+ });
+ }
+}
+
+function clearIntermediatesAndGetPackage(bundleTerms, config, hasAnyCpu) {
+ // msbuild isn't capable of generating bundles unless you enable bundling for each individual arch
+ // However, that generates intermediate bundles, like "CordovaApp.Windows10_0.0.1.0_x64.appxbundle"
+ // We need to clear the intermediate bundles, or else "cordova run" will fail because of too
+ // many .appxbundle files.
+
+ console.log('Clearing intermediates...');
+ var appPackagesPath = path.join(ROOT, 'AppPackages');
+ var childDirectories = shell.ls(path.join(appPackagesPath, '*')).map(function(pathName) {
+ return { path: pathName, stats: fs.statSync(pathName) };
+ }).filter(function(fileInfo) {
+ return fileInfo.stats.isDirectory();
+ });
+
+ if (childDirectories.length === 0) {
+ throw new Error('Could not find a completed app package directory.');
+ }
+
+ // find the most-recently-modified directory
+ childDirectories.sort(function(a, b) { return b.stats.mtime - a.stats.mtime; });
+ var outputDirectory = childDirectories[0];
+
+ var finalFile = '';
+ var archSearchString = bundleTerms.replace(/\|/g, '_') + (config.buildType === 'debug' ? '_debug' : '') + '.appxbundle';
+ if (hasAnyCpu) {
+ archSearchString = 'AnyCPU' + (config.buildType === 'debug' ? '_debug' : '') + '.appxbundle';
+ }
+
+ var filesToDelete = shell.ls(path.join(outputDirectory.path, '*.appx*')).filter(function(appxbundle) {
+ var isMatch = appxbundle.indexOf(archSearchString) === -1;
+ if (!isMatch) {
+ finalFile = appxbundle;
+ }
+ return isMatch;
+ });
+ filesToDelete.forEach(function(file) {
+ shell.rm(file);
+ });
+
+ return package.getPackageFileInfo(finalFile);
+}
+
+// Can update buildConfig in the following ways:
+// * Sets targetProject property, the project to launch when complete
+function getBuildTargets(buildConfig) {
+ var configXML = new ConfigParser(path.join(ROOT, 'config.xml'));
+ var targets = [];
+ var noSwitches = !(buildConfig.phone || buildConfig.win);
+
+ // Windows
+ if (buildConfig.win || noSwitches) { // if --win or no arg
+ var windowsTargetVersion = configXML.getWindowsTargetVersion();
+ switch(windowsTargetVersion) {
+ case '8':
+ case '8.0':
+ targets.push(projFiles.win80);
+ break;
+ case '8.1':
+ targets.push(projFiles.win);
+ break;
+ case '10.0':
+ case 'UAP':
+ targets.push(projFiles.win10);
+ break;
+ default:
+ throw new Error('Unsupported windows-target-version value: ' + windowsTargetVersion);
+ }
+ }
+
+ // Windows Phone
+ if (buildConfig.phone || noSwitches) { // if --phone or no arg
+ var windowsPhoneTargetVersion = configXML.getWindowsPhoneTargetVersion();
+ switch(windowsPhoneTargetVersion) {
+ case '8.1':
+ targets.push(projFiles.phone);
+ break;
+ case '10.0':
+ case 'UAP':
+ if (!buildConfig.win && !noSwitches) {
+ // Already built due to --win or no switches
+ // and since the same thing can be run on Phone as Windows,
+ // we can skip this one.
+ targets.push(projFiles.win10);
+ }
+ break;
+ default:
+ throw new Error('Unsupported windows-phone-target-version value: ' + windowsPhoneTargetVersion);
+ }
+ }
+
+ // apply build target override if one was specified
+ if (buildConfig.projVerOverride) {
+ switch (buildConfig.projVerOverride) {
+ case '8.1-phone':
+ targets = [projFiles.phone];
+ break;
+ case '8.1-win':
+ targets = [projFiles.win];
+ break;
+ case 'uap':
+ targets = [projFiles.win10];
+ break;
+ default:
+ console.warn('Unrecognized --appx parameter passed to build: "' + buildConfig.projVerOverride + '", ignoring.');
+ break;
+ }
+ }
+
+ // As part of reworking how build and package determine the winning project, set the 'target type' project
+ // as part of build configuration. This will be used for determining the binary to 'run' after build is done.
+ if (targets.length > 0) {
+ switch (targets[0]) {
+ case projFiles.win80:
+ buildConfig.targetProject = 'windows80';
+ break;
+ case projFiles.phone:
+ buildConfig.targetProject = 'phone';
+ break;
+ case projFiles.win10:
+ buildConfig.targetProject = 'windows10';
+ break;
+ case projFiles.win:
+ /* falls through */
+ default:
+ buildConfig.targetProject = 'windows';
+ break;
+ }
+ }
+
+ return targets;
+}
+
+function getMsBuildForTargets(selectedTargets, buildConfig, allMsBuildVersions) {
+ var availableVersions = allMsBuildVersions.reduce(function(obj, msbuildVersion) {
+ obj[msbuildVersion.version] = msbuildVersion;
+ return obj;
+ }, {});
+
+ var result = null;
+
+ if (selectedTargets.indexOf(projFiles.win80) > -1) {
+ // building Windows 8; prefer 4.0, unless phone is also present, in which case prefer 12
+ // prefer 12. If not present, can't build this; error in the filterSupportedTargets function
+ result = availableVersions['12.0'] || availableVersions['4.0'];
+ } else {
+ // 14 can build Windows 10, Windows 8.1, and Windows Phone 8.1, so resolve to 14 if available, else 12
+ result = (availableVersions['14.0'] || availableVersions['12.0']);
+ }
+
+ return result;
}
// TODO: Fix this so that it outlines supported versions based on version criteria:
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/cordova/lib/package.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/package.js b/template/cordova/lib/package.js
index 5906355..8aaad69 100644
--- a/template/cordova/lib/package.js
+++ b/template/cordova/lib/package.js
@@ -40,13 +40,16 @@ module.exports.getPackage = function (projectType, buildtype, buildArch) {
return fs.statSync(pkgDir).isDirectory();
});
- for (var dir in pkgDirs) {
- var packageFiles = fs.readdirSync(pkgDirs[dir]).filter(function(e) {
+ for (var dirIndex = 0; dirIndex < pkgDirs.length; dirIndex++) {
+ var dir = pkgDirs[dirIndex];
+ var packageFiles = fs.readdirSync(dir).filter(function(e) {
return e.match('.*.(appx|appxbundle)$');
});
- for (var pkgFile in packageFiles) {
- var packageFile = path.join(pkgDirs[dir], packageFiles[pkgFile]);
+ for (var pkgIndex = 0; pkgIndex < packageFiles.length; pkgIndex++) {
+ var pkgFile = packageFiles[pkgIndex];
+
+ var packageFile = path.join(dir, pkgFile);
var pkgInfo = module.exports.getPackageFileInfo(packageFile);
if (pkgInfo && pkgInfo.type == projectType &&
@@ -57,6 +60,7 @@ module.exports.getPackage = function (projectType, buildtype, buildArch) {
}
}
}
+
// reject because seems that no corresponding packages found
return Q.reject('Package with specified parameters not found in AppPackages folder');
};
@@ -69,14 +73,18 @@ function getPackagePhoneProductId(packageFile) {
// returns package info object or null if it is not valid package
module.exports.getPackageFileInfo = function (packageFile) {
var pkgName = path.basename(packageFile);
+
// CordovaApp.Windows_0.0.1.0_anycpu_debug.appx
// CordovaApp.Phone_0.0.1.0_x86_debug.appxbundle
- var props = /.*\.(Phone|Windows|Windows80|Windows10)_((?:\d*\.)*\d*)_(AnyCPU|x64|x86|ARM)(?:_(Debug))?.(appx|appxbundle)$/i.exec(pkgName);
+ // CordovaApp.Windows10_0.0.1.0_x64_x86_arm.appxbundle
+
+ var props = /.*\.(Phone|Windows|Windows80|Windows10)_((?:\d*\.)*\d*)*((?:_(AnyCPU|x86|x64|ARM)){1,4})(?:(_Debug))?.(appx|appxbundle)$/i.exec(pkgName);
if (props) {
return {
type : props[1].toLowerCase(),
- arch : props[3].toLowerCase(),
- buildtype : props[4] ? props[4].toLowerCase() : 'release',
+ arch : props[3].toLowerCase().substring(1),
+ archs : props[3].toLowerCase().substring(1).split('_'),
+ buildtype : props[5] ? props[5].substring(1).toLowerCase() : 'release',
appx : packageFile,
script : path.join(packageFile, '..', 'Add-AppDevPackage.ps1'),
phoneId : getPackagePhoneProductId(packageFile)
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/eeda3df0/template/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/run.js b/template/cordova/lib/run.js
index b59d70c..80ebf1e 100644
--- a/template/cordova/lib/run.js
+++ b/template/cordova/lib/run.js
@@ -68,12 +68,17 @@ module.exports.run = function (argv) {
// what project type we should deploy
var projectType = projFileToType(buildTargets[0]);
+ if (projectType === 'windows80' && argv.indexOf('--bundle') > -1) {
+ // Don't enable bundling for Windows 8.
+ // Assumes the commander only enters the --bundle param once
+ argv.splice(argv.indexOf('--bundle'), 1);
+ }
+
// if --nobuild isn't specified then build app first
- var buildPackages = args.nobuild ? Q() : build.run(argv);
+ var buildPackages = args.nobuild ? packages.getPackage(projectType, buildType, buildArchs) : build.run(argv);
- return buildPackages.then(function () {
- return packages.getPackage(projectType, buildType, buildArchs[0]);
- }).then(function(pkg) {
+ // buildPackages also deploys bundles
+ return buildPackages.then(function(pkg) {
console.log('\nDeploying ' + pkg.type + ' package to ' + deployTarget + ':\n' + pkg.appx);
switch (pkg.type) {
case 'phone':
@@ -106,7 +111,7 @@ module.exports.run = function (argv) {
module.exports.help = function () {
console.log('\nUsage: run [ --device | --emulator | --target=<id> ] [ --debug | --release | --nobuild ]');
- console.log(' [ --x86 | --x64 | --arm ] [--phone | --win]');
+ console.log(' [ --x86 | --x64 | --arm | --archs="list" ] [--bundle] [--phone | --win]');
console.log(' --device : Deploys and runs the project on the connected device.');
console.log(' --emulator : Deploys and runs the project on an emulator.');
console.log(' --target=<id> : Deploys and runs the project on the specified target.');
@@ -116,6 +121,8 @@ module.exports.help = function () {
console.log(' --archs : Specific chip architectures (`anycpu`, `arm`, `x86`, `x64`).');
console.log(' Separate multiple choices with a space and, if choosing');
console.log(' multiple choices, enclose in quotes (").');
+ console.log(' --bundle : Generates an .appxbundle. Not valid if anycpu AND chip-specific');
+ console.log(' architectures are used.');
console.log(' --phone, --win');
console.log(' : Specifies project type to deploy');
console.log(' --appx=<8.1-win|8.1-phone|uap>');
@@ -130,6 +137,7 @@ module.exports.help = function () {
console.log(' run --target=7988B8C3-3ADE-488d-BA3E-D052AC9DC710');
console.log(' run --device --release');
console.log(' run --emulator --debug');
+ console.log(' run --archs="x64 x86 arm" --no-bundle');
console.log(' run --device --appx=phone-8.1');
console.log(' run --device --archs="x64 x86 arm"');
console.log('');
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org