Add first version of tailing logs on Android

This commit is contained in:
Martijn Walraven
2015-08-23 20:18:14 +02:00
parent e55c9f46c4
commit df708d7309

View File

@@ -101,5 +101,45 @@ export class AndroidRunTarget extends CordovaRunTarget {
async start(cordovaProject) {
await cordovaProject.run(this.platform, this.isDevice);
this.tailLogs(cordovaProject).done();
}
async checkPlatformRequirementsAndSetEnv(cordovaProject) {
// Cordova Android is fairly good at applying various heuristics to find
// suitable values for JAVA_HOME and ANDROID_HOME, and to augment the PATH
// with those variables.
// Unfortunately, this is intertwined with checking requirements, so the
// only way to get access to this functionality is to run check_reqs and
// let it modify process.env
const check_reqs = require(files.pathJoin(
cordovaProject.projectRoot, 'platforms', this.platform,
'cordova', 'lib', 'check_reqs'));
// We can't use check_reqs.run() because that will print the values of
// JAVA_HOME and ANDROID_HOME to stdout.
await Promise.all([check_reqs.check_java(),
check_reqs.check_android().then(check_reqs.check_android_target)]);
}
async tailLogs(cordovaProject) {
cordovaProject.runCommands(`tailing logs for ${this.displayName}`, async () => {
await this.checkPlatformRequirementsAndSetEnv(cordovaProject);
// XXX This only works if we have at most one device or one emulator
// connected. We should find a way to get the target ID from run and use
// it instead of -d or -e.
const target = this.isDevice ? "-d" : "-e";
// Clear logs
await execFileAsync('adb', [target, 'logcat', '-c']);
const filterExpressions = ['CordovaLog:I', 'chromium:I',
'SystemWebViewClient:I', '*:S'];
// Asynchronously start tailing logs to stdout
execFileAsync('adb', [target, 'logcat',
...filterExpressions],
{ stdio: 'inherit' });
});
}
}