Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 79dd939

Browse files
committed
Merge pull request #558 from telerik/totev/dont-stop-adb-uninstall
Don't stop adb uninstall
2 parents 2b0980f + 20a3bed commit 79dd939

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

commands/preuninstall.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"use strict";
33

44
import * as path from "path";
5-
import * as util from "util";
65

76
export class PreUninstallCommand implements ICommand {
8-
private static ADB_RELATIVE_PATH = "../resources/platform-tools/android/%s/adb";
97

108
constructor(private $fs: IFileSystem,
119
private $childProcess: IChildProcess,
@@ -17,19 +15,6 @@ export class PreUninstallCommand implements ICommand {
1715

1816
public execute(args: string[]): IFuture<void> {
1917
return (() => {
20-
let relativeAdbPath = util.format(PreUninstallCommand.ADB_RELATIVE_PATH, process.platform);
21-
let adbPath = path.join(__dirname, relativeAdbPath);
22-
23-
let killAdbServerCommand = util.format("\"%s\" kill-server", adbPath);
24-
this.$logger.warn("Trying to kill adb server. Some running Android related operations may fail.");
25-
26-
try {
27-
this.$childProcess.exec(killAdbServerCommand).wait();
28-
} catch(err) {
29-
this.$logger.trace(err);
30-
this.$logger.warn("Unable to kill adb server.");
31-
}
32-
3318
this.$fs.deleteFile(path.join(this.$options.profileDir, "KillSwitches", "cli")).wait();
3419
}).future<void>()();
3520
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mobile-cli-lib",
33
"preferGlobal": false,
4-
"version": "0.0.5",
4+
"version": "0.1.1",
55
"author": "Telerik <[email protected]>",
66
"description": "common lib used by different CLI",
77
"bin": {
@@ -60,7 +60,7 @@
6060
"ref-struct": "https://github.com/telerik/ref-struct/tarball/v1.0.1.0-proton",
6161
"rimraf": "2.2.6",
6262
"semver": "4.3.4",
63-
"shelljs": "0.5.1",
63+
"shelljs": "0.5.3",
6464
"tabtab": "https://github.com/Icenium/node-tabtab/tarball/master",
6565
"temp": "0.8.1",
6666
"unzip": "0.1.11",

static-config-base.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"use strict";
33

44
import * as path from "path";
5+
import * as shelljs from "shelljs";
6+
import * as os from "os";
57

68
export class StaticConfigBase implements Config.IStaticConfig {
79
public PROJECT_FILE_NAME: string = null;
@@ -52,24 +54,56 @@ export class StaticConfigBase implements Config.IStaticConfig {
5254

5355
private getAdbFilePathCore(): IFuture<string> {
5456
return ((): string => {
55-
let defaultAdbFilePath = path.join(__dirname, `resources/platform-tools/android/${process.platform}/adb`);
5657
let $childProcess: IChildProcess = this.$injector.resolve("$childProcess");
5758

5859
try {
5960
let proc = $childProcess.spawnFromEvent("adb", ["version"], "exit", undefined, { throwError: false }).wait();
6061

6162
if(proc.stderr) {
62-
return defaultAdbFilePath;
63+
return this.spawnPrivateAdb().wait();
6364
}
6465
} catch(e) {
6566
if(e.code === "ENOENT") {
66-
return defaultAdbFilePath;
67+
return this.spawnPrivateAdb().wait();
6768
}
6869
}
6970

7071
return "adb";
7172
}).future<string>()();
7273
}
7374

75+
/*
76+
Problem:
77+
1. Adb forks itself as a server which keeps running until adb kill-server is invoked or crashes
78+
2. On Windows running processes lock their image files due to memory mapping. Locked files prevent their parent directories from deletion and cannot be overwritten.
79+
3. Update and uninstall scenarios are broken
80+
Solution:
81+
- Copy adb and associated files into a temporary directory. Let this copy of adb run persistently
82+
- On Posix OSes, immediately delete the file to not take file space
83+
- Tie common lib version to updates of adb, so that when we integrate a newer adb we can use it
84+
- Adb is named differently on OSes and may have additional files. The code is hairy to accommodate these differences
85+
*/
86+
private spawnPrivateAdb(): IFuture<string> {
87+
return (():string => {
88+
let $fs: IFileSystem = this.$injector.resolve("$fs");
89+
let $childProcess: IChildProcess = this.$injector.resolve("$childProcess");
90+
91+
// prepare the directory to host our copy of adb
92+
let defaultAdbDirPath = path.join(__dirname, `resources/platform-tools/android/${process.platform}`);
93+
let commonLibVersion = require(path.join(__dirname, "package.json")).version;
94+
let tmpDir = path.join(os.tmpdir(), `telerik-common-lib-${commonLibVersion}`);
95+
$fs.createDirectory(tmpDir).wait();
96+
97+
// copy the adb and associated files
98+
shelljs.cp(path.join(defaultAdbDirPath, "*"), tmpDir); // deliberately ignore copy errors
99+
100+
// let adb start its global server
101+
let targetAdb = path.join(tmpDir, "adb");
102+
$childProcess.spawnFromEvent(targetAdb, ["start-server"], "exit", undefined, { throwError: false }).wait();
103+
104+
return targetAdb;
105+
}).future<string>()();
106+
}
107+
74108
public PATH_TO_BOOTSTRAP: string;
75109
}

0 commit comments

Comments
 (0)