UNPKG

android-tools-bin

Version:

Pre-built binaries for android tools such as adb, fastboot and heimdall.

72 lines 3.03 kB
"use strict"; /* * Copyright (C) 2020-2022 UBports Foundation <info@ubports.com> * Copyright (C) 2020-2022 Johannah Sprinz <hannah@ubports.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getAndroidToolPath = exports.getAndroidToolBaseDir = void 0; const path_1 = require("path"); const fs_1 = require("fs"); // HACK: Currently required for CommonJS compatibility. // const __dirname = dirname(fileURLToPath(import.meta.url)); /** Get base directory path for debugging */ function getAndroidToolBaseDir(platform = process.platform, arch = process.arch) { return (0, path_1.join)(__dirname, "..", "dist", platform, normalizedArch(arch)); } exports.getAndroidToolBaseDir = getAndroidToolBaseDir; /** Group architectures together */ function normalizedArch(arch = process.arch) { switch (arch) { case "ia32": case "x64": return "x86"; case "arm": case "arm64": return "arm"; default: return arch; } } /** Returns path to an android tool. If the env var USE_SYSTEM_<tool> where <tool> is the capitalized name of the tool is set, the function will return the native tool for that tool accordingly. If the env var USE_NATIVE_SYSTEM_TOOLS is said, all tools will return the native tools. */ function getAndroidToolPath(tool, optimistic = true, native = {}, platform = process.platform, arch = process.arch) { try { if (native.all || process.env.USE_SYSTEM_TOOLS || native[tool] || process.env[`USE_SYSTEM_${tool.toUpperCase()}`]) { return tool; } const assumedPath = (0, path_1.join)(getAndroidToolBaseDir(platform, arch), platform === "win32" ? `${tool}.exe` : tool); if ((0, fs_1.existsSync)(assumedPath)) { return assumedPath; } else { throw new Error(`No binary of ${tool} for ${arch} ${platform}`); } } catch (error) { if (optimistic) return tool; else throw new Error(`Failed to get tool: ${error}`); } } exports.getAndroidToolPath = getAndroidToolPath; exports.default = { getAndroidToolPath: (tool, optimistic = true, native = {}) => getAndroidToolPath(tool, optimistic, native), getAndroidToolBaseDir: () => getAndroidToolBaseDir() }; //# sourceMappingURL=module.js.map