Zirconify

Also remove update-crates command, since it no longer works and
I’m taking a different approach with it.

Also update error-chain to release version.

Change-Id: I06bd0765f7218c5d242ce5c18f39d5b19eb69f1c
diff --git a/Cargo.lock b/Cargo.lock
index 866ab45..093c2c3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -242,7 +242,7 @@
 
 [[package]]
 name = "error-chain"
-version = "0.11.0-rc.2"
+version = "0.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -253,12 +253,8 @@
 version = "0.1.0"
 dependencies = [
  "clap 2.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "error-chain 0.11.0-rc.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "toml 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "uname 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1019,14 +1015,6 @@
 ]
 
 [[package]]
-name = "toml"
-version = "0.4.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
 name = "uname"
 version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1147,7 +1135,7 @@
 "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
 "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
 "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
-"checksum error-chain 0.11.0-rc.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38d3a55d9a7a456748f2a3912c0941a5d9a68006eb15b3c3c9836b8420dc102d"
+"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
 "checksum fidl 0.1.0 (git+https://fuchsia.googlesource.com/fuchsia-crates)" = "<none>"
 "checksum filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5363ab8e4139b8568a6237db5248646e5a8a2f89bd5ccb02092182b11fd3e922"
 "checksum foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e4056b9bd47f8ac5ba12be771f77a0dae796d1bbaaf5fd0b9c2d38b69b8a29d"
@@ -1232,7 +1220,6 @@
 "checksum tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fbb47ae81353c63c487030659494b295f6cb6576242f907f203473b191b0389"
 "checksum tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24da22d077e0f15f55162bdbdc661228c1581892f52074fb242678d015b45162"
 "checksum tokio-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d88e411cac1c87e405e4090be004493c5d8072a370661033b1a64ea205ec2e13"
-"checksum toml 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e5e16033aacf7eead46cbcb62d06cf9d1c2aa1b12faa4039072f7ae5921103b"
 "checksum uname 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b72f89f0ca32e4db1c04e2a72f5345d59796d4866a1ee0609084569f73683dc8"
 "checksum unicase 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e01da42520092d0cd2d6ac3ae69eb21a22ad43ff195676b86f8c37f487d6b80"
 "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
diff --git a/Cargo.toml b/Cargo.toml
index 7b6489e..52b8a13 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,11 +5,7 @@
 
 [dependencies]
 clap = "2"
-error-chain = "0.11.0-rc.2"
-serde = "1.0.9"
-serde_derive = "1.0.9"
-serde_json = "1.0.2"
-toml = "0.4.2"
+error-chain = "0.11.0"
 uname = "0.1.1"
 notify = "4.0.0"
 
diff --git a/src/device.rs b/src/device.rs
index 7fddd62..39a29ba 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -20,7 +20,7 @@
 
 pub fn netaddr(verbose: bool, target_options: &TargetOptions) -> Result<String> {
     let fuchsia_root = fuchsia_root()?;
-    let netaddr_binary = fuchsia_root.join("out/build-magenta/tools/netaddr");
+    let netaddr_binary = fuchsia_root.join("out/build-zircon/tools/netaddr");
     let mut args = vec!["--fuchsia"];
     if let Some(device_name) = target_options.device_name {
         args.push(device_name);
@@ -39,7 +39,7 @@
 
 pub fn netls(verbose: bool) -> Result<()> {
     let fuchsia_root = fuchsia_root()?;
-    let netls_binary = fuchsia_root.join("out/build-magenta/tools/netls");
+    let netls_binary = fuchsia_root.join("out/build-zircon/tools/netls");
     let mut netls_command = Command::new(netls_binary);
     netls_command.arg("--nowait").arg("--timeout=500");
     if verbose {
@@ -168,7 +168,7 @@
 #[cfg_attr(rustfmt, rustfmt_skip)]
 static TUNCTL_NOT_FOUND_ERROR: &'static str =
 "tunctl command not found. Please install uml-utilities.
-For help see https://fuchsia.googlesource.com/magenta/+/
+For help see https://fuchsia.googlesource.com/zircon/+/
 master/docs/qemu.md#Enabling-Networking-under-QEMU-x86_64-only";
 
 pub fn setup_network_linux(user: &str) -> Result<()> {
@@ -222,9 +222,9 @@
     target_options: &TargetOptions,
 ) -> Result<()> {
     let fuchsia_root = fuchsia_root()?;
-    let run_magenta_script = fuchsia_root.join("scripts/run-magenta-x86-64");
-    if !run_magenta_script.exists() {
-        bail!("run magenta script not found at {:?}", run_magenta_script);
+    let run_zircon_script = fuchsia_root.join("scripts/run-zircon-x86-64");
+    if !run_zircon_script.exists() {
+        bail!("run zircon script not found at {:?}", run_zircon_script);
     }
     let user_bootfs = target_out_dir(target_options)?.join("user.bootfs");
     if !user_bootfs.exists() {
@@ -236,12 +236,12 @@
         args.push("-g");
     }
 
-    let child = Command::new(run_magenta_script)
+    let child = Command::new(run_zircon_script)
         .args(&args)
         .stdout(Stdio::null())
         .stderr(Stdio::null())
         .spawn()
-        .chain_err(|| "unable to run magenta")?;
+        .chain_err(|| "unable to run zircon")?;
 
     println!("emulator started with process ID {}", child.id());
 
diff --git a/src/lib.rs b/src/lib.rs
index 9fa30f9..7d7d6c4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,16 +11,12 @@
 extern crate clap;
 #[macro_use]
 extern crate error_chain;
-#[macro_use]
-extern crate serde_derive;
-extern crate toml;
 extern crate uname;
 
 mod device;
 mod cross;
 mod sdk;
 mod utils;
-mod update_crates;
 
 mod errors {
     // Create the Error, ErrorKind, ResultExt, and Result types
@@ -48,7 +44,6 @@
 use std::fs;
 use std::path::PathBuf;
 use std::process::Command;
-use update_crates::update_crates;
 use utils::strip_binary;
 
 fn run_program_on_target(
@@ -417,18 +412,6 @@
                 .setting(AppSettings::Hidden),
         )
         .subcommand(
-            SubCommand::with_name("update-crates")
-                .about("Update the FIDL generated crates")
-                .arg(
-                    Arg::with_name("target")
-                        .long("target")
-                        .value_name("target")
-                        .required(true)
-                        .help("Target directory for updated crates"),
-                )
-                .setting(AppSettings::Hidden),
-        )
-        .subcommand(
             SubCommand::with_name("pkg-config")
                 .about("Run pkg-config for the cross compilation environment")
                 .arg(Arg::with_name("pkgconfig_param").index(1).multiple(true)),
@@ -569,11 +552,6 @@
         );
     }
 
-    if let Some(update_matches) = matches.subcommand_matches("update-crates") {
-        let update_target = update_matches.value_of("target").unwrap();
-        return update_crates(update_target).chain_err(|| "update-crates failed");
-    }
-
     if let Some(pkg_matches) = matches.subcommand_matches("pkg-config") {
         let pkg_params =
             pkg_matches.values_of("pkgconfig_param").map(|x| x.collect()).unwrap_or_else(|| vec![]);
diff --git a/src/sdk.rs b/src/sdk.rs
index 03be2a9..c19b52f 100644
--- a/src/sdk.rs
+++ b/src/sdk.rs
@@ -66,12 +66,12 @@
 }
 
 pub fn sysroot_path(options: &TargetOptions) -> Result<PathBuf> {
-    let magenta_name = if options.target_cpu == "x86-64" {
-        "build-magenta-pc-x86-64"
+    let zircon_name = if options.target_cpu == "x86-64" {
+        "build-zircon-pc-x86-64"
     } else {
-        "build-magenta-qemu-arm64"
+        "build-zircon-qemu-arm64"
     };
-    Ok(fuchsia_root()?.join("out").join("build-magenta").join(magenta_name).join("sysroot"))
+    Ok(fuchsia_root()?.join("out").join("build-zircon").join(zircon_name).join("sysroot"))
 }
 
 pub fn toolchain_path() -> Result<PathBuf> {
diff --git a/src/update_crates.rs b/src/update_crates.rs
deleted file mode 100644
index 114153b..0000000
--- a/src/update_crates.rs
+++ /dev/null
@@ -1,139 +0,0 @@
-use sdk::fuchsia_root;
-use std::collections::HashMap;
-use std::fs;
-use std::fs::File;
-use std::io;
-use std::io::{Read, Write};
-use std::path::{Path, PathBuf};
-use toml;
-
-error_chain!{
-    links {
-        SDK(::sdk::Error, ::sdk::ErrorKind);
-    }
-
-    foreign_links {
-        Io(::std::io::Error);
-    }
-}
-
-#[cfg_attr(rustfmt, rustfmt_skip)]
-static LICENSE_RS_FILE_HEADER: &'static str =
-r#"// Copyright 2017 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-"#;
-
-#[cfg_attr(rustfmt, rustfmt_skip)]
-static LICENSE_TOML_FILE_HEADER: &'static str =
-r#"# Copyright 2017 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"#;
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-struct Dependency {
-    path: Option<String>,
-    git: Option<String>,
-    version: Option<String>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-struct Package {
-    name: String,
-    version: String,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-struct Library {
-    path: String,
-    name: String,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-struct Cargo {
-    package: Package,
-    lib: Option<Library>,
-    dependencies: Option<HashMap<String, Dependency>>,
-}
-
-impl Cargo {
-    fn rewrite(&self) -> Cargo {
-        let new_deps = if self.dependencies.is_some() {
-            let mut new_deps_map: HashMap<String, Dependency> = HashMap::new();
-            let old_deps = self.dependencies.clone().unwrap().clone();
-            for (k, mut v) in old_deps {
-                v.path = None;
-                if k == "magenta" || k == "mxruntime" {
-                    v.version = Some("0.1.0".to_string());
-                } else {
-                    v.git = Some("https://fuchsia.googlesource.com/fuchsia-crates".to_string());
-                }
-                new_deps_map.insert(k, v);
-            }
-            Some(new_deps_map)
-        } else {
-            None
-        };
-        Cargo {
-            package: self.package.clone(),
-            lib: self.lib.clone(),
-            dependencies: new_deps,
-        }
-    }
-}
-
-fn look_for_crates(dir: &Path, root: &Path, target: &Path) -> io::Result<()> {
-    if dir.is_dir() {
-        for entry in fs::read_dir(dir)? {
-            let entry = entry?;
-            let path = entry.path();
-            if path.is_dir() {
-                look_for_crates(&path, root, target)?;
-            } else if let Some(file_name) = path.file_name() {
-                let partial_parent = path.parent().unwrap().strip_prefix(root).unwrap();
-                if file_name.to_str() == Some("Cargo.toml") {
-                    let mut input = String::new();
-                    File::open(&path).and_then(|mut f| f.read_to_string(&mut input)).unwrap();
-                    let decoded: Cargo = toml::from_str(&input).unwrap();
-                    if decoded.lib.is_some() {
-                        let rewritten = decoded.rewrite();
-                        let target_parent = target.join(partial_parent);
-                        fs::create_dir_all(&target_parent).unwrap();
-                        let toml2 = toml::to_string(&rewritten).unwrap();
-                        let target_cargo = target_parent.join("Cargo.toml");
-                        let mut file = File::create(target_cargo)?;
-                        file.write_all(LICENSE_TOML_FILE_HEADER.as_bytes())?;
-                        file.write_all(toml2.into_bytes().as_slice())?;
-                    }
-                } else if let Some(extension) = path.extension() {
-                    if extension.to_str() == Some("rs") {
-                        let target_parent = target.join(partial_parent);
-                        fs::create_dir_all(&target_parent).unwrap();
-                        let mut input = String::new();
-                        File::open(&path).and_then(|mut f| f.read_to_string(&mut input)).unwrap();
-                        let target_rust_file = target_parent.join(file_name);
-                        let mut file = File::create(target_rust_file)?;
-                        file.write_all(LICENSE_RS_FILE_HEADER.as_bytes())?;
-                        file.write_all(input.into_bytes().as_slice())?;
-                    }
-
-                }
-            }
-        }
-
-    }
-    Ok(())
-}
-
-pub fn update_crates(target: &str) -> Result<()> {
-    let gen_root = fuchsia_root()?.join("out/debug-x86-64/gen");
-    let crate_sources = vec!["application", "apps/mozart", "apps/ledger", "apps/modular"];
-    for one_source in crate_sources {
-        let one_source_path = gen_root.join(one_source);
-        look_for_crates(&one_source_path, &gen_root, &PathBuf::from(target))?;
-    }
-    Ok(())
-}