|
1 | | -import * as path from "path"; |
2 | | -import * as shelljs from "shelljs"; |
3 | | -import * as os from "os"; |
4 | 1 | import * as _ from "lodash"; |
| 2 | +import * as path from "path"; |
| 3 | +import { IFileSystem } from "./common/declarations"; |
| 4 | +import { IInjector } from "./common/definitions/yok"; |
| 5 | +import { injector } from "./common/yok"; |
5 | 6 | import { |
| 7 | + IAndroidToolsInfo, |
6 | 8 | IConfiguration, |
7 | 9 | IStaticConfig, |
8 | | - IAndroidToolsInfo, |
9 | 10 | } from "./declarations"; |
10 | | -import { IFileSystem, IChildProcess, IHostInfo } from "./common/declarations"; |
11 | | -import { IInjector } from "./common/definitions/yok"; |
12 | | -import { injector } from "./common/yok"; |
13 | 11 |
|
14 | 12 | export class Configuration implements IConfiguration { |
15 | 13 | // User specific config |
@@ -77,9 +75,7 @@ export class StaticConfig implements IStaticConfig { |
77 | 75 | if (!this._adbFilePath) { |
78 | 76 | const androidToolsInfo: IAndroidToolsInfo = |
79 | 77 | this.$injector.resolve("androidToolsInfo"); |
80 | | - this._adbFilePath = |
81 | | - (await androidToolsInfo.getPathToAdbFromAndroidHome()) || |
82 | | - (await this.getAdbFilePathCore()); |
| 78 | + this._adbFilePath = await androidToolsInfo.getPathToAdbFromAndroidHome(); |
83 | 79 | } |
84 | 80 |
|
85 | 81 | return this._adbFilePath; |
@@ -110,79 +106,5 @@ export class StaticConfig implements IStaticConfig { |
110 | 106 | public get HTML_COMMON_HELPERS_DIR(): string { |
111 | 107 | return path.join(__dirname, "common", "docs", "helpers"); |
112 | 108 | } |
113 | | - |
114 | | - private async getAdbFilePathCore(): Promise<string> { |
115 | | - const $childProcess: IChildProcess = |
116 | | - this.$injector.resolve("$childProcess"); |
117 | | - |
118 | | - try { |
119 | | - // Do NOT use the adb wrapper because it will end blow up with Segmentation fault because the wrapper uses this method!!! |
120 | | - const proc = await $childProcess.spawnFromEvent( |
121 | | - "adb", |
122 | | - ["version"], |
123 | | - "exit", |
124 | | - undefined, |
125 | | - { throwError: false } |
126 | | - ); |
127 | | - |
128 | | - if (proc.stderr) { |
129 | | - return await this.spawnPrivateAdb(); |
130 | | - } |
131 | | - } catch (e) { |
132 | | - if (e.code === "ENOENT") { |
133 | | - return await this.spawnPrivateAdb(); |
134 | | - } |
135 | | - } |
136 | | - |
137 | | - return "adb"; |
138 | | - } |
139 | | - |
140 | | - /* |
141 | | - Problem: |
142 | | - 1. Adb forks itself as a server which keeps running until adb kill-server is invoked or crashes |
143 | | - 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. |
144 | | - 3. Update and uninstall scenarios are broken |
145 | | - Solution: |
146 | | - - Copy adb and associated files into a temporary directory. Let this copy of adb run persistently |
147 | | - - On Posix OSes, immediately delete the file to not take file space |
148 | | - - Tie common lib version to updates of adb, so that when we integrate a newer adb we can use it |
149 | | - - Adb is named differently on OSes and may have additional files. The code is hairy to accommodate these differences |
150 | | - */ |
151 | | - private async spawnPrivateAdb(): Promise<string> { |
152 | | - const $fs: IFileSystem = this.$injector.resolve("$fs"), |
153 | | - $childProcess: IChildProcess = this.$injector.resolve("$childProcess"), |
154 | | - $hostInfo: IHostInfo = this.$injector.resolve("$hostInfo"); |
155 | | - |
156 | | - // prepare the directory to host our copy of adb |
157 | | - const defaultAdbDirPath = path.join( |
158 | | - __dirname, |
159 | | - "common", |
160 | | - "resources", |
161 | | - "platform-tools", |
162 | | - "android", |
163 | | - process.platform |
164 | | - ); |
165 | | - const pathToPackageJson = path.join(__dirname, "..", "package.json"); |
166 | | - const nsCliVersion = require(pathToPackageJson).version; |
167 | | - const tmpDir = path.join(os.tmpdir(), `nativescript-cli-${nsCliVersion}`); |
168 | | - $fs.createDirectory(tmpDir); |
169 | | - |
170 | | - // copy the adb and associated files |
171 | | - const targetAdb = path.join(tmpDir, "adb"); |
172 | | - |
173 | | - // In case directory is missing or it's empty, copy the new adb |
174 | | - if (!$fs.exists(tmpDir) || !$fs.readDirectory(tmpDir).length) { |
175 | | - shelljs.cp(path.join(defaultAdbDirPath, "*"), tmpDir); // deliberately ignore copy errors |
176 | | - // adb loses its executable bit when packed inside electron asar file. Manually fix the issue |
177 | | - if (!$hostInfo.isWindows) { |
178 | | - shelljs.chmod("+x", targetAdb); |
179 | | - } |
180 | | - } |
181 | | - |
182 | | - // let adb start its global server |
183 | | - await $childProcess.spawnFromEvent(targetAdb, ["start-server"], "exit"); |
184 | | - |
185 | | - return targetAdb; |
186 | | - } |
187 | 109 | } |
188 | 110 | injector.register("staticConfig", StaticConfig); |
0 commit comments