From 4834e800809e11ddc8d7c372f6974528d2ad2c41 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 3 Dec 2015 08:40:18 +0000 Subject: [PATCH] Fix tns doctor command When ANDROID_HOME environment variable is not set, we call childProcess exec and spawn with undefined command. This leads to "futures left behind" errors. Make sure the commands will be executed only in case they are not undefined. Also make sure that `tns prepare android` will fail immediately in case ANDROID_HOME is not set (currently it shows warning for ANDROID_HOME and shows error for compile SDK). --- lib/android-tools-info.ts | 20 +++++++++++++------- lib/common | 2 +- lib/declarations.ts | 3 ++- lib/services/android-project-service.ts | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/android-tools-info.ts b/lib/android-tools-info.ts index 7f52036ac6..2e04ac4ae6 100644 --- a/lib/android-tools-info.ts +++ b/lib/android-tools-info.ts @@ -38,8 +38,11 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { private $logger: ILogger, private $options: IOptions) {} - public getPathToAndroidExecutable(): IFuture { + public getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture { return ((): string => { + if(options) { + this.showWarningsAsErrors = options.showWarningsAsErrors; + } if (!this.pathToAndroidExecutable) { if(this.validateAndroidHomeEnvVariable(this.androidHome).wait()) { let androidPath = path.join(this.androidHome, "tools", this.androidExecutableName); @@ -47,7 +50,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { this.printMessage(`Unable to find "${this.androidExecutableName}" executable file. Make sure you have set ANDROID_HOME environment variable correctly.`); } } else { - this.printMessage("ANDROID_HOME environment variable is not set correctly."); + this.$logger.trace("ANDROID_HOME environment variable is not set correctly."); } } @@ -338,11 +341,14 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { return (() => { if (!this.installedTargetsCache) { try { - let result = this.$childProcess.spawnFromEvent(this.getPathToAndroidExecutable().wait(), ["list", "targets"], "close", {}, {throwError: false}).wait(); - if(result.stdout) { - this.$logger.trace(result.stdout); - this.installedTargetsCache = []; - result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m)); + let pathToAndroidExecutable = this.getPathToAndroidExecutable().wait(); + if(pathToAndroidExecutable) { + let result = this.$childProcess.spawnFromEvent(pathToAndroidExecutable, ["list", "targets"], "close", {}, {throwError: false}).wait(); + if(result && result.stdout) { + this.$logger.trace(result.stdout); + this.installedTargetsCache = []; + result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m)); + } } } catch(err) { this.$logger.trace("Unable to get Android targets. Error is: " + err); diff --git a/lib/common b/lib/common index 9f4d4e91ad..2b0980f179 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 9f4d4e91ad8bc1a64ea7c713edfb5e4d99c74259 +Subproject commit 2b0980f17978c5cf8e2e9fe0bb9f9febf7c43576 diff --git a/lib/declarations.ts b/lib/declarations.ts index e8906ca5df..9c90f22085 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -126,9 +126,10 @@ interface IAndroidToolsInfo { /** * Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`. * In case ANDROID_HOME is not defined, check if `android` is part of $PATH. + * @param {any} options Defines if the warning messages should treated as error. * @return {string} Path to the `android` executable. */ - getPathToAndroidExecutable(): IFuture; + getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture; /** * Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists. diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index bdca9896d3..b33193f4c3 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -79,7 +79,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject this.validateProjectName(this.$projectData.projectName); // this call will fail in case `android` is not set correctly. - this.$androidToolsInfo.getPathToAndroidExecutable().wait(); + this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait(); this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait(); }).future()(); }