amis-rpc-design/node_modules/@react-native-community/cli-doctor/build/tools/windows/androidWinHelpers.js.map
2023-10-07 19:42:30 +08:00

1 line
14 KiB
Plaintext

{"version":3,"names":["getUserAndroidPath","join","process","env","LOCALAPPDATA","getAndroidSdkRootInstallation","ANDROID_SDK_ROOT","ANDROID_HOME","installPath","pathExistsSync","installComponent","component","androidSdkRoot","Promise","done","error","sdkmanager","command","child","executeCommand","stderr","stdout","on","data","includes","stdin","write","toString","exitStatus","undefined","parseHypervisor","status","customHypervisor","hypervisor","installed","test","getEmulatorAccelOutputInformation","androidSDKRoot","e","createAVD","name","device","image","abi","tag","avdmanager","configPath","HOMEPATH","content","readFile","updatedContent","replace","writeFile","getBestHypervisor","getProcessorType","lines","split","line","enableWHPX","enableHAXM","androidSdkInstallPath","enableAMDH"],"sources":["../../../src/tools/windows/androidWinHelpers.ts"],"sourcesContent":["import {readFile, writeFile, pathExistsSync} from 'fs-extra';\nimport {join} from 'path';\nimport {executeCommand} from './executeWinCommand';\nimport {getProcessorType} from './processorType';\n\ntype HypervisorStatus = {\n hypervisor: 'WHPX' | 'HAXM' | 'AMDH' | 'none';\n installed: boolean;\n};\n\n/**\n * Returns the path to where all Android related things should be installed\n * locally to the user.\n */\nexport const getUserAndroidPath = () => {\n return join(process.env.LOCALAPPDATA || '', 'Android');\n};\n\n/**\n * Deals with ANDROID_HOME, ANDROID_SDK_ROOT or generates a new one\n */\nexport const getAndroidSdkRootInstallation = () => {\n const env = process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME;\n const installPath = env\n ? // Happens if previous installations or not fully completed\n env\n : // All Android zip files have a root folder, using `Android` as the common place\n join(getUserAndroidPath(), 'Sdk');\n\n if (pathExistsSync(installPath)) {\n return installPath;\n } else {\n return '';\n }\n};\n\n/**\n * Installs an Android component (e.g.: `platform-tools`, `emulator`)\n * using the `sdkmanager` tool and automatically accepting the licenses.\n */\nexport const installComponent = (component: string, androidSdkRoot: string) => {\n return new Promise((done, error) => {\n const sdkmanager = join(androidSdkRoot, 'tools', 'bin', 'sdkmanager.bat');\n\n const command = `\"${sdkmanager}\" --sdk_root=\"${androidSdkRoot}\" \"${component}\"`;\n\n const child = executeCommand(command);\n let stderr = '';\n\n child.stdout?.on('data', (data) => {\n if (data.includes('(y/N)')) {\n child.stdin?.write('y\\n');\n }\n });\n\n child.stderr?.on('data', (data) => {\n stderr += data.toString('utf-8');\n });\n\n child.on('close', (exitStatus) => {\n if (exitStatus === 0) {\n done(undefined);\n } else {\n error({stderr});\n }\n });\n child.on('error', error);\n });\n};\n\n/**\n * For the given custom Hypervisor and the output of `emulator-check accel`\n * returns the preferred Hypervisor to use and its installation status.\n * The recommendation order is:\n * 1. WHPX\n * 2. HAXM if Intel\n * 3. AMDH if AMD\n */\nconst parseHypervisor = (\n status: string,\n customHypervisor: 'HAXM' | 'AMDH',\n): HypervisorStatus | null => {\n /**\n * Messages:\n * Android Emulator requires an Intel processor with VT-x and NX support. Your CPU: 'AuthenticAMD'\n * HAXM is not installed, but Windows Hypervisor Platform is available.\n * WHPX (10.0.19041) is installed and usable.\n * * This message outputs for WHPX and when the AMD Hypervisor is installed\n * HAXM version 6.2.1 (4) is installed and usable.\n * HAXM is not installed on this machine\n */\n\n if (\n status.includes(\n 'is not installed, but Windows Hypervisor Platform is available.',\n )\n ) {\n return {\n hypervisor: 'WHPX',\n installed: false,\n };\n }\n\n if (/WHPX \\((\\d|\\.)+\\) is installed and usable\\./.test(status)) {\n return {\n hypervisor: 'WHPX',\n installed: true,\n };\n }\n\n if (/is installed and usable\\./.test(status)) {\n return {\n hypervisor: customHypervisor,\n installed: true,\n };\n }\n\n if (status.includes(\"Your CPU: 'AuthenticAMD'\")) {\n return {\n hypervisor: customHypervisor,\n installed: false,\n };\n }\n\n if (status.includes('is not installed on this machine')) {\n return {\n hypervisor: 'none',\n installed: false,\n };\n }\n\n return null;\n};\n\nconst getEmulatorAccelOutputInformation = async (androidSDKRoot: string) => {\n /**\n * The output of the following command is something like:\n *\n * ```\n * accel:\n * 0\n * WHPX (10.0.19041) is installed and usable.\n * accel\n * ```\n *\n * If it fails it will still output to stdout with a similar format:\n *\n * ```\n * accel:\n * 1\n * Android Emulator does not support nested virtualization. Your VM host: 'Microsoft Hv' (Hyper-V)\n * accel\n * ```\n *\n */\n\n try {\n const {stdout} = await executeCommand(\n `\"${join(androidSDKRoot, 'emulator', 'emulator-check.exe')}\" accel`,\n );\n\n return stdout;\n } catch (e) {\n const {stdout} = e as any;\n\n return stdout;\n }\n};\n\n/**\n * Creates a new Android Virtual Device in the default folder with the\n * name, device and system image passed by parameter.\n */\nexport const createAVD = async (\n androidSDKRoot: string,\n name: string,\n device: string,\n image: string,\n) => {\n try {\n const abi = image.includes('x86_64') ? 'x86_64' : 'x86';\n const tag = image.includes('google_apis') ? 'google_apis' : 'generic';\n const avdmanager = join(androidSDKRoot, 'tools', 'bin', 'avdmanager.bat');\n\n const {stdout} = await executeCommand(\n `${avdmanager} -s create avd --force --name \"${name}\" --device \"${device}\" --package \"${image}\" --tag \"${tag}\" --abi \"${abi}\"`,\n );\n\n // For some reason `image.sysdir.1` in `config.ini` points to the wrong location and needs to be updated\n const configPath = join(\n process.env.HOMEPATH || '',\n '.android',\n 'avd',\n `${name}.avd`,\n 'config.ini',\n );\n\n const content = await readFile(configPath, 'utf-8');\n const updatedContent = content.replace(\n /Sdk\\\\system-images/g,\n 'system-images',\n );\n\n await writeFile(configPath, updatedContent, 'utf-8');\n\n return stdout;\n } catch (e) {\n const {stderr} = e as any;\n\n return stderr;\n }\n};\n\n/**\n * Returns what hypervisor should be installed for the Android emulator\n * using [Microsoft's official\n * documentation](https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?pivots=windows)\n * as a reference.\n */\nexport const getBestHypervisor = async (\n androidSDKRoot: string,\n): Promise<HypervisorStatus> => {\n const customHypervisor = getProcessorType() === 'Intel' ? 'HAXM' : 'AMDH';\n\n const stdout = await getEmulatorAccelOutputInformation(androidSDKRoot);\n\n const lines = stdout.split('\\n');\n\n for (const line of lines) {\n const hypervisor = parseHypervisor(line, customHypervisor);\n\n if (hypervisor) {\n return hypervisor;\n }\n }\n\n // Couldn't identify the best one to run so not doing anything\n return {\n hypervisor: 'none',\n installed: false,\n };\n};\n\n/**\n * Enables the Windows HypervisorPlatform and Hyper-V features.\n * Will prompt the User Account Control (UAC)\n */\nexport const enableWHPX = () => {\n return executeCommand(\n 'DISM /Quiet /NoRestart /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V /FeatureName:HypervisorPlatform',\n true,\n );\n};\n\n/**\n * Installs and enables the [HAXM](https://github.com/intel/haxm)\n * version available through the Android SDK manager.\n * @param androidSdkInstallPath The path to the Android SDK installation\n */\nexport const enableHAXM = async (androidSdkInstallPath: string) => {\n await installComponent(\n 'extras;intel;Hardware_Accelerated_Execution_Manager',\n androidSdkInstallPath,\n );\n\n await executeCommand(\n join(\n androidSdkInstallPath,\n 'Sdk',\n 'extras',\n 'intel',\n 'Hardware_Accelerated_Execution_Manager',\n 'silent_install.bat',\n ),\n );\n};\n\n/**\n * Installs and enables the\n * [Hypervisor Driver for AMD Processors](https://androidstudio.googleblog.com/2019/10/android-emulator-hypervisor-driver-for.html)\n * version available through the Android SDK manager.\n * @param androidSdkInstallPath The path to the Android SDK installation\n */\nexport const enableAMDH = async (androidSdkInstallPath: string) => {\n await installComponent(\n 'extras;google;Android_Emulator_Hypervisor_Driver',\n androidSdkInstallPath,\n );\n\n await executeCommand(\n join(\n androidSdkInstallPath,\n 'Sdk',\n 'extras',\n 'google',\n 'Android_Emulator_Hypervisor_Driver',\n 'silent_install.bat',\n ),\n );\n};\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AAOA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,MAAM;EACtC,OAAO,IAAAC,YAAI,EAACC,OAAO,CAACC,GAAG,CAACC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