CB-5793 Add work-around for library references not working with custom output directory (ugh).

This commit is contained in:
Andrew Grieve 2014-01-21 15:09:15 -05:00
parent 7094047b3d
commit f83d7a7cd1
4 changed files with 47 additions and 6 deletions

View File

@ -87,6 +87,11 @@ function runAndroidUpdate(projectPath, target_api, shared) {
return exec('android update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"'); return exec('android update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');
} }
function copyAntRules(projectPath) {
var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
shell.cp('-f', path.join(srcDir, 'custom_rules.xml'), projectPath);
}
function copyScripts(projectPath) { function copyScripts(projectPath) {
var srcScriptsDir = path.join(ROOT, 'bin', 'templates', 'cordova'); var srcScriptsDir = path.join(ROOT, 'bin', 'templates', 'cordova');
var destScriptsDir = path.join(projectPath, 'cordova'); var destScriptsDir = path.join(projectPath, 'cordova');
@ -186,6 +191,7 @@ exports.createProject = function(project_path, package_name, project_name, proje
shell.sed('-i', /__PACKAGE__/, package_name, manifest_path); shell.sed('-i', /__PACKAGE__/, package_name, manifest_path);
shell.sed('-i', /__APILEVEL__/, target_api.split('-')[1], manifest_path); shell.sed('-i', /__APILEVEL__/, target_api.split('-')[1], manifest_path);
copyScripts(project_path); copyScripts(project_path);
copyAntRules(project_path);
}); });
// Link it to local android install. // Link it to local android install.
return runAndroidUpdate(project_path, target_api, use_shared_project); return runAndroidUpdate(project_path, target_api, use_shared_project);
@ -209,6 +215,7 @@ exports.updateProject = function(projectPath) {
var target_api = check_reqs.get_target(); var target_api = check_reqs.get_target();
copyJsAndLibrary(projectPath, false, null); copyJsAndLibrary(projectPath, false, null);
copyScripts(projectPath); copyScripts(projectPath);
copyAntRules(projectPath);
removeDebuggableFromManifest(projectPath); removeDebuggableFromManifest(projectPath);
return runAndroidUpdate(projectPath, target_api, false) return runAndroidUpdate(projectPath, target_api, false)
.then(function() { .then(function() {

View File

@ -26,6 +26,19 @@ var shell = require('shelljs'),
fs = require('fs'), fs = require('fs'),
ROOT = path.join(__dirname, '..', '..'); ROOT = path.join(__dirname, '..', '..');
function hasCustomRules() {
return fs.existsSync(path.join(ROOT, 'custom_rules.xml'));
}
module.exports.getAntArgs = function(cmd) {
var args = [cmd, '-f', path.join(ROOT, 'build.xml')];
// custom_rules.xml is required for incremental builds.
if (hasCustomRules()) {
args.push('-Dout.dir=ant-build', '-Dgen.absolute.dir=ant-gen');
}
return args;
};
/* /*
* Builds the project with ant. * Builds the project with ant.
* Returns a promise. * Returns a promise.
@ -33,7 +46,7 @@ var shell = require('shelljs'),
module.exports.run = function(build_type) { module.exports.run = function(build_type) {
//default build type //default build type
build_type = typeof build_type !== 'undefined' ? build_type : "--debug"; build_type = typeof build_type !== 'undefined' ? build_type : "--debug";
var args = ['debug', '-f', path.join(ROOT, 'build.xml'), '-Dout.dir=ant-build', '-Dgen.dir=ant-build/gen']; var args = module.exports.getAntArgs('debug');
switch(build_type) { switch(build_type) {
case '--debug' : case '--debug' :
break; break;
@ -46,7 +59,14 @@ module.exports.run = function(build_type) {
default : default :
return Q.reject('Build option \'' + build_type + '\' not recognized.'); return Q.reject('Build option \'' + build_type + '\' not recognized.');
} }
// Without our custom_rules.xml, we need to clean before building.
var ret = Q();
if (!hasCustomRules()) {
ret = require('./clean').run();
}
return ret.then(function() {
return spawn('ant', args); return spawn('ant', args);
});
} }
/* /*

View File

@ -19,16 +19,16 @@
under the License. under the License.
*/ */
var spawn = require('./spawn'), var build = require('./build'),
path = require('path'), spawn = require('./spawn'),
ROOT = path.join(__dirname, '..', '..'); path = require('path');
/* /*
* Cleans the project using ant * Cleans the project using ant
* Returns a promise. * Returns a promise.
*/ */
module.exports.run = function() { module.exports.run = function() {
var args = ['clean', '-f', path.join(ROOT, 'build.xml'), '-Dout.dir=ant-build', '-Dgen.dir=ant-build/gen']; var args = build.getAntArgs('clean');
return spawn('ant', args); return spawn('ant', args);
} }

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<target name="-pre-compile">
<!-- Fix library references due to bug in build.xml: See: https://groups.google.com/forum/#!topic/android-developers/0ivH-YqCjzg -->
<pathconvert property="fixedJarsPath" refid="project.all.jars.path">
<filtermapper>
<replacestring from="/bin/" to="/ant-build/"/>
</filtermapper>
</pathconvert>
<path id="project.all.jars.path">
<pathelement path="${fixedJarsPath}"/>
</path>
</target>
</project>