-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes build & run related bugs from builder refactor #490
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,10 @@ var events = require('cordova-common').events; | |
var spawn = require('cordova-common').superspawn.spawn; | ||
var CordovaError = require('cordova-common').CordovaError; | ||
|
||
module.exports.parseBuildOptions = parseOpts; | ||
function parseOpts (options, resolvedTarget, projectRoot) { | ||
options = options || {}; | ||
options.argv = nopt({ | ||
gradle: Boolean, | ||
studio: Boolean, | ||
prepenv: Boolean, | ||
versionCode: String, | ||
minSdkVersion: String, | ||
|
@@ -50,26 +49,13 @@ function parseOpts (options, resolvedTarget, projectRoot) { | |
// Android Studio Build method is the default | ||
var ret = { | ||
buildType: options.release ? 'release' : 'debug', | ||
buildMethod: process.env.ANDROID_BUILD || 'studio', | ||
prepEnv: options.argv.prepenv, | ||
arch: resolvedTarget && resolvedTarget.arch, | ||
extraArgs: [] | ||
}; | ||
|
||
if (options.argv.gradle || options.argv.studio) { | ||
ret.buildMethod = options.argv.studio ? 'studio' : 'gradle'; | ||
} | ||
|
||
// This comes from cordova/run | ||
if (options.studio) ret.buildMethod = 'studio'; | ||
if (options.gradle) ret.buildMethod = 'gradle'; | ||
|
||
if (options.nobuild) ret.buildMethod = 'none'; | ||
|
||
if (options.argv.versionCode) { ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode); } | ||
|
||
if (options.argv.minSdkVersion) { ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion); } | ||
|
||
if (options.argv.gradleArg) { | ||
ret.extraArgs = ret.extraArgs.concat(options.argv.gradleArg); | ||
} | ||
|
@@ -129,7 +115,8 @@ function parseOpts (options, resolvedTarget, projectRoot) { | |
*/ | ||
module.exports.runClean = function (options) { | ||
var opts = parseOpts(options, null, this.root); | ||
var builder = builders.getBuilder(opts.buildMethod); | ||
var builder = builders.getBuilder(); | ||
|
||
return builder.prepEnv(opts).then(function () { | ||
return builder.clean(opts); | ||
}); | ||
|
@@ -149,8 +136,8 @@ module.exports.runClean = function (options) { | |
*/ | ||
module.exports.run = function (options, optResolvedTarget) { | ||
var opts = parseOpts(options, optResolvedTarget, this.root); | ||
console.log(opts.buildMethod); | ||
var builder = builders.getBuilder(opts.buildMethod); | ||
var builder = builders.getBuilder(); | ||
|
||
return builder.prepEnv(opts).then(function () { | ||
if (opts.prepEnv) { | ||
events.emit('verbose', 'Build file successfully prepared.'); | ||
|
@@ -161,8 +148,7 @@ module.exports.run = function (options, optResolvedTarget) { | |
events.emit('log', 'Built the following apk(s): \n\t' + apkPaths.join('\n\t')); | ||
return { | ||
apkPaths: apkPaths, | ||
buildType: opts.buildType, | ||
buildMethod: opts.buildMethod | ||
buildType: opts.buildType | ||
}; | ||
}); | ||
}); | ||
|
@@ -276,12 +262,10 @@ module.exports.help = function () { | |
console.log('Flags:'); | ||
console.log(' \'--debug\': will build project in debug mode (default)'); | ||
console.log(' \'--release\': will build project for release'); | ||
console.log(' \'--ant\': will build project with ant'); | ||
console.log(' \'--gradle\': will build project with gradle (default)'); | ||
console.log(' \'--nobuild\': will skip build process (useful when using run command)'); | ||
console.log(' \'--prepenv\': don\'t build, but copy in build scripts where necessary'); | ||
console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs. Requires --gradle.'); | ||
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs. Requires --gradle.'); | ||
console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these flags still work with an Android Studio build? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These flag should still work. It appears that there is an issue where the flags are not being accepted. I am not sure when this issue was introduced but it appears that it also existed in the latest release. I will create a separate ticket and PR to fix CLI parameter issue. |
||
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs.'); | ||
console.log(' \'--gradleArg=<gradle command line arg>\': Extra args to pass to the gradle command. Use one flag per arg. Ex. --gradleArg=-PcdvBuildMultipleApks=true'); | ||
console.log(''); | ||
console.log('Signed APK flags (overwrites debug/release-signing.proprties) :'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,29 +17,18 @@ | |
under the License. | ||
*/ | ||
|
||
var CordovaError = require('cordova-common').CordovaError; | ||
|
||
var knownBuilders = { | ||
gradle: 'ProjectBuilder', | ||
studio: 'ProjectBuilder' | ||
}; | ||
const CordovaError = require('cordova-common').CordovaError; | ||
|
||
/** | ||
* Helper method that instantiates and returns a builder for specified build | ||
* type. | ||
* Helper method that instantiates and returns a builder for specified build type. | ||
* | ||
* @param {String} builderType Builder name to construct and return. Must | ||
* be one of gradle' or 'studio' | ||
* | ||
* @return {Builder} A builder instance for specified build type. | ||
* @return {Builder} A builder instance for specified build type. | ||
*/ | ||
module.exports.getBuilder = function (builderType, projectRoot) { | ||
if (!knownBuilders[builderType]) { throw new CordovaError('Builder ' + builderType + ' is not supported.'); } | ||
|
||
module.exports.getBuilder = function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't you completely get rid of this? Or is this used from externally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will scan across our repos to verify. I believe this entire file could be safely removed and point directly to the ProjectBuilder. I am not sure though if anyone uses this in their own personal build system but shouldn't affect us from removing if we don't use. It might also be possible to do this type of task in separate PR as a final cleanup PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I scanned across repos and it seems only Android uses it. I will say its safe to remove, but I believe a cleanup PR will be better for this so we do not delay the fix. I tried changing them and it ended up breaking around 70 tests. I would like to focus on that after. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, makes sense to do this individually as it is a major rip-out operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it's best to leave this for another PR, as it would require a large refactor across the rest of the codebase. |
||
try { | ||
var Builder = require('./' + knownBuilders[builderType]); | ||
return new Builder(projectRoot); | ||
const Builder = require('./ProjectBuilder'); | ||
return new Builder(); | ||
} catch (err) { | ||
throw new CordovaError('Failed to instantiate ' + knownBuilders[builderType] + ' builder: ' + err); | ||
throw new CordovaError('Failed to instantiate ProjectBuilder builder: ' + err); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably for the next round of cleaning, but there's a bunch of stuff around here that could be simplified with arrow functions and could use native Promises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also agree. Some of the things I was thinking about in the clean up PR would be:
let
andconst
fs-extra
to replace things likeshell.cp
etc.builders/builders.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Best create a cleanup issue with these tasks so they won't be forgotten)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.