Skip to content

Commit

Permalink
feat(android on windows): Support android VMs on windows (angular#154)
Browse files Browse the repository at this point in the history
Closes angular#51
  • Loading branch information
sjelin committed Dec 20, 2016
1 parent 1d4a15a commit fc86c2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
27 changes: 9 additions & 18 deletions lib/cmds/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,16 @@ function downloadAndroidUpdates(

// Setup hardware acceleration for x86-64 emulation
function setupHardwareAcceleration(sdkPath: string) {
// TODO(sjelin): check that the BIOS option is set properly on linux
// TODO(sjelin): linux setup
let toolDir = path.resolve(sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager');
if (os.type() == 'Darwin') {
console.log('Enabling hardware acceleration (requires root access)');
// We don't need the wrapped spawnSync because we know we're on OSX
spawnSync(
'sudo', [path.resolve(
sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager',
'silent_install.sh')],
{stdio: 'inherit'});
spawnSync('sudo', ['silent_install.sh'], {stdio: 'inherit', cwd: toolDir});
} else if (os.type() == 'Windows_NT') {
console.log('Enabling hardware acceleration (requires admin access)');
// We don't need the wrapped spawnSync because we know we're on Windows
spawnSync(
'cmd',
[
'/c', 'runas', '/noprofile', '/user:Administrator',
path.resolve(
sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager',
'silent_install.bat')
],
{stdio: 'inherit'});
// We don't need the wrapped spawnSync because we know we're on windows
spawnSync('silent_install.bat', [], {stdio: 'inherit', cwd: toolDir});
}
}

Expand Down Expand Up @@ -169,12 +158,14 @@ class AVDDescriptor {
// SDKs which were downloaded
function getAVDDescriptors(sdkPath: string): q.Promise<AVDDescriptor[]> {
let deferred = q.defer<AVDDescriptor[]>();
glob(path.resolve(sdkPath, 'system-images', '*', '*', '*'), (err: Error, files: string[]) => {
// `glob` package always prefers patterns to use `/`
glob('system-images/*/*/*', {cwd: sdkPath}, (err: Error, files: string[]) => {
if (err) {
deferred.reject(err);
} else {
deferred.resolve(files.map((file: string) => {
let info = file.split(path.sep).slice(-3);
// `file` could use `/` or `\`, so we use `path.normalize`
let info = path.normalize(file).split(path.sep).slice(-3);
return new AVDDescriptor(info[0], info[1], info[2]);
}));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ function startAppium(outputDir: string, binary: Binary, androidSDK: Binary, port
process.env.ANDROID_HOME = path.resolve(outputDir, androidSDK.executableFilename(os.type()));
}
appiumProcess = spawn(
path.resolve(outputDir, binary.filename(), 'node_modules', '.bin', 'appium'),
port ? ['--port', port] : []);
'npm', ['run', 'appium'].concat(port ? ['--', '--port', port] : []), null,
{cwd: path.resolve(outputDir, binary.filename())});
}

function killAppium() {
Expand Down
3 changes: 2 additions & 1 deletion lib/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ function installAppium(binary: Binary, outputDir: string): void {
}

fs.mkdirSync(folder);
fs.writeFileSync(path.resolve(folder, 'package.json'), '{}');
fs.writeFileSync(
path.resolve(folder, 'package.json'), JSON.stringify({scripts: {appium: 'appium'}}));
spawn('npm', ['install', 'appium@' + binary.version()], null, {cwd: folder});
}

0 comments on commit fc86c2d

Please sign in to comment.