Support aemu as well as qemu

Change-Id: I4d4d7a3fe7a1d2b39bd008e99451fe0ce296ee74
diff --git a/src/command_line.rs b/src/command_line.rs
index 665b379..94093c1 100644
--- a/src/command_line.rs
+++ b/src/command_line.rs
@@ -4,12 +4,12 @@
     check_binary,
     cross::run_pkg_config,
     device::{netls, ssh, start_emulator, stop_emulator, StartEmulatorOptions},
-    sdk::TargetOptions,
     enable_networking, format_project,
     package::make_package,
     random_story_name, run_binary, run_cargo, run_configure, run_program_on_target,
-    run_switches_to_mode, run_tests, write_config, FuchsiaConfig, RunCargoOptions, RunMode,
-    DEFAULT_MOD_NAME,
+    run_switches_to_mode, run_tests,
+    sdk::TargetOptions,
+    write_config, FuchsiaConfig, RunCargoOptions, RunMode, DEFAULT_MOD_NAME,
 };
 use failure::Error;
 use std::path::PathBuf;
@@ -248,13 +248,17 @@
 
 #[derive(Debug, StructOpt)]
 struct Start {
+    /// Start aemu instead of qemu
+    #[structopt(short = "a")]
+    aemu: bool,
+
     /// Start a simulator with graphics enabled.
     #[structopt(short = "g")]
     graphics: bool,
 
-    /// Start a simulator with KVM (Linux only)
+    /// Start a simulator with acceleration (for qemu, Linux only)
     #[structopt(short = "k")]
-    kvm: bool,
+    with_acceleration: bool,
 
     /// Don't set up networking
     #[structopt(long)]
@@ -496,8 +500,9 @@
             return start_emulator(
                 &StartEmulatorOptions {
                     verbose: verbose,
+                    aemu: start_opts.aemu,
                     with_graphics: start_opts.graphics,
-                    with_kvm: start_opts.kvm,
+                    with_acceleration: start_opts.with_acceleration,
                     with_networking: !start_opts.no_net,
                     disable_virtcon: start_opts.disable_virtcon,
                 },
@@ -574,8 +579,9 @@
             return start_emulator(
                 &StartEmulatorOptions {
                     verbose: verbose,
+                    aemu: start_opts.aemu,
                     with_graphics: start_opts.graphics,
-                    with_kvm: start_opts.kvm,
+                    with_acceleration: start_opts.with_acceleration,
                     with_networking: !start_opts.no_net,
                     disable_virtcon: start_opts.disable_virtcon,
                 },
diff --git a/src/device.rs b/src/device.rs
index d5a4906..66412b7 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -223,8 +223,9 @@
 
 pub struct StartEmulatorOptions {
     pub verbose: bool,
+    pub aemu: bool,
     pub with_graphics: bool,
-    pub with_kvm: bool,
+    pub with_acceleration: bool,
     pub with_networking: bool,
     pub disable_virtcon: bool,
 }
@@ -235,12 +236,44 @@
     if !fx_script.exists() {
         bail!("fx script not found at {:?}", fx_script);
     }
-    let mut args = vec!["run", "-N"];
-    if options.with_graphics {
-        args.push("-g");
+
+    let mut args = vec![];
+    if options.aemu {
+        args.push("aemu");
+    } else {
+        args.push("run");
     }
-    if options.with_kvm {
-        args.push("-k");
+
+    if options.with_networking {
+        args.push("-N");
+    }
+
+    if options.with_graphics {
+        if !options.aemu {
+            args.push("-g");
+        }
+    } else {
+        if options.aemu {
+            args.push("--headless");
+        }
+    }
+
+    if options.with_acceleration {
+        if options.aemu {
+            args.push("-a");
+            if is_mac() {
+                args.push("hax");
+            } else {
+                args.push("kvm");
+            }
+        } else {
+            args.push("-k");
+        }
+    } else {
+        if options.aemu {
+            args.push("-a");
+            args.push("off");
+        }
     }
 
     if options.disable_virtcon {
@@ -273,7 +306,7 @@
 }
 
 pub fn stop_emulator() -> Result<(), Error> {
-    Command::new("killall").arg("qemu-system-x86_64").status()?;
+    Command::new("killall").arg("-9").arg("-m").arg("qemu-system-x86_64.*").status()?;
     Ok(())
 }
 
diff --git a/src/lib.rs b/src/lib.rs
index f83aa43..cbc037b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,25 +9,23 @@
 #![recursion_limit = "1024"]
 
 mod build_rustc;
+pub mod command_line;
 mod cross;
 mod device;
 mod package;
-pub mod command_line;
 mod sdk;
 mod utils;
 
 pub use crate::sdk::{FuchsiaConfig, TargetOptions};
 
 use crate::cross::{pkg_config_path, run_configure};
-use crate::device::{
-    enable_networking, netaddr, scp_to_device, ssh,
-};
+use crate::device::{enable_networking, netaddr, scp_to_device, ssh};
 use crate::package::make_package;
 use crate::{
     sdk::{
-        cargo_path, clang_archiver_path, clang_c_compiler_path,
-        clang_cpp_compiler_path, clang_ranlib_path, clang_resource_dir, rustc_path, rustdoc_path,
-        shared_libraries_path, sysroot_path, zircon_build_path,
+        cargo_path, clang_archiver_path, clang_c_compiler_path, clang_cpp_compiler_path,
+        clang_ranlib_path, clang_resource_dir, rustc_path, rustdoc_path, shared_libraries_path,
+        sysroot_path, zircon_build_path,
     },
     utils::strip_binary,
 };
@@ -677,5 +675,3 @@
 static RUN_ON_TARGET: &str = "run-on-target";
 
 static FORMAT: &str = "fmt";
-
-