Update to the Rust 2018 edition
Testing: cargo test plus build spinning_square_rs.
Change-Id: Id4b80979ce30266d4a4f0fd432c3fddba1296a56
diff --git a/Cargo.toml b/Cargo.toml
index 50a3933..ac22818 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,10 @@
+cargo-features = ["edition"]
+
[package]
name = "fargo"
version = "0.2.0"
authors = ["Rob Tsuk <robtsuk@google.com>"]
+edition = "2018"
[dependencies]
clap = "2"
diff --git a/README.md b/README.md
index c127954..c988b6a 100644
--- a/README.md
+++ b/README.md
@@ -69,11 +69,12 @@
./scripts/fx build-zircon
./scripts/fx build
-Once this build is complete, clone and build fargo.
+Once this build is complete, clone and build fargo. For this you will need
+a working host Rust installation, most easily installed with [rustup](https://rustup.rs).
git clone https://fuchsia.googlesource.com/fargo
cd fargo
- cargo install --force
+ cargo +nightly install --force
Fargo uses ssh to communicate between your host computer and either Qemu or a
real device to copy build results and execute them. For Qemu there is a bit of
diff --git a/cratest/src/main.rs b/cratest/src/main.rs
index 2c72697..c03dc60 100644
--- a/cratest/src/main.rs
+++ b/cratest/src/main.rs
@@ -85,7 +85,8 @@
"https://crates.io/api/v1/crates?page=1&per_page=",
&format!("{}", num),
"&sort=downloads",
- ].join("")
+ ]
+ .join("")
.into();
if verbose {
@@ -153,8 +154,7 @@
TestResult::Failure
},
}
- })
- .collect();
+ }).collect();
let (succ, fail, excl) = results.into_iter().fold(
(Vec::new(), Vec::new(), Vec::new()),
diff --git a/src/bin/fargo.rs b/src/bin/fargo.rs
index 66773c1..8920f95 100644
--- a/src/bin/fargo.rs
+++ b/src/bin/fargo.rs
@@ -1,9 +1,5 @@
#![recursion_limit = "1024"]
-extern crate failure;
-extern crate fargo;
-extern crate itertools;
-
use fargo::run;
use itertools::Itertools;
diff --git a/src/cross.rs b/src/cross.rs
index e6f06d8..b1b49e0 100644
--- a/src/cross.rs
+++ b/src/cross.rs
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+use crate::sdk::{sysroot_path, toolchain_path, TargetOptions};
use failure::{Error, ResultExt};
-use sdk::{sysroot_path, toolchain_path, TargetOptions};
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
-pub fn cross_root(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn cross_root(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let home_value = env::var("HOME")?;
Ok(PathBuf::from(home_value)
@@ -18,12 +18,12 @@
.join(target_options.target_cpu))
}
-pub fn pkg_config_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn pkg_config_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(cross_root(target_options)?.join("lib").join("pkgconfig"))
}
pub fn run_pkg_config(
- verbose: bool, args: &[&str], target_options: &TargetOptions,
+ verbose: bool, args: &[&str], target_options: &TargetOptions<'_, '_>,
) -> Result<i32, Error> {
let mut cmd = Command::new("pkg-config");
@@ -45,7 +45,7 @@
}
pub fn run_configure(
- verbose: bool, use_host: bool, args: &[&str], target_options: &TargetOptions,
+ verbose: bool, use_host: bool, args: &[&str], target_options: &TargetOptions<'_, '_>,
) -> Result<bool, Error> {
let cwd = fs::canonicalize(env::current_dir()?)
.context("run_configure: canonicalize working directory")?;
diff --git a/src/device.rs b/src/device.rs
index 9a43d38..e4258ff 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-use failure::{err_msg, Error, ResultExt};
-use sdk::{fuchsia_dir, fx_path, target_out_dir, TargetOptions};
+use crate::sdk::{fuchsia_dir, fx_path, target_out_dir, TargetOptions};
+use crate::utils::is_mac;
+use failure::{bail, err_msg, Error, ResultExt};
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::{str, thread, time};
-use utils::is_mac;
-pub fn netaddr(verbose: bool, target_options: &TargetOptions) -> Result<String, Error> {
+pub fn netaddr(verbose: bool, target_options: &TargetOptions<'_, '_>) -> Result<String, Error> {
let fuchsia_dir = fuchsia_dir(target_options)?;
let netaddr_binary = fuchsia_dir.join("out/build-zircon/tools/netaddr");
let mut args = vec!["--fuchsia"];
@@ -42,7 +42,7 @@
Ok(result)
}
-pub fn netls(verbose: bool, target_options: &TargetOptions) -> Result<(), Error> {
+pub fn netls(verbose: bool, target_options: &TargetOptions<'_, '_>) -> Result<(), Error> {
let fuchsia_dir = fuchsia_dir(target_options)?;
let netls_binary = fuchsia_dir.join("out/build-zircon/tools/netls");
let mut netls_command = Command::new(netls_binary);
@@ -67,7 +67,7 @@
];
pub fn scp_to_device(
- verbose: bool, target_options: &TargetOptions, netaddr: &str, source_path: &PathBuf,
+ verbose: bool, target_options: &TargetOptions<'_, '_>, netaddr: &str, source_path: &PathBuf,
destination_path: &str,
) -> Result<(), Error> {
let destination_with_address = format!("[{}]:{}", netaddr, destination_path);
@@ -104,7 +104,9 @@
Ok(())
}
-pub fn ssh(verbose: bool, target_options: &TargetOptions, command: &str) -> Result<(), Error> {
+pub fn ssh(
+ verbose: bool, target_options: &TargetOptions<'_, '_>, command: &str,
+) -> Result<(), Error> {
let netaddr = netaddr(verbose, target_options)?;
let ssh_config = target_out_dir(target_options)?.join("ssh-keys/ssh_config");
if !ssh_config.exists() {
@@ -235,7 +237,7 @@
}
pub fn start_emulator(
- options: &StartEmulatorOptions, params: &[&str], target_options: &TargetOptions,
+ options: &StartEmulatorOptions, params: &[&str], target_options: &TargetOptions<'_, '_>,
) -> Result<(), Error> {
let fuchsia_dir = fuchsia_dir(target_options)?;
let fx_script = fx_path(target_options)?;
diff --git a/src/lib.rs b/src/lib.rs
index 9e52567..ad19485 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,35 +8,32 @@
#![recursion_limit = "1024"]
-extern crate clap;
-#[macro_use]
-extern crate failure;
-extern crate toml;
-extern crate uname;
-
mod cross;
mod device;
mod sdk;
mod utils;
+pub use crate::sdk::TargetOptions;
+
+use crate::cross::{pkg_config_path, run_configure, run_pkg_config};
+use crate::device::{enable_networking, netaddr, netls, scp_to_device, ssh, start_emulator,
+ stop_emulator, StartEmulatorOptions};
+use crate::sdk::{cargo_out_dir, cargo_path, clang_archiver_path, clang_c_compiler_path,
+ clang_cpp_compiler_path, clang_linker_path, clang_ranlib_path, rustc_path,
+ rustdoc_path, shared_libraries_path, sysroot_path, zircon_build_path,
+ FuchsiaConfig};
+use crate::utils::strip_binary;
+
use clap::{App, AppSettings, Arg, SubCommand};
-use cross::{pkg_config_path, run_configure, run_pkg_config};
-use device::{enable_networking, netaddr, netls, scp_to_device, ssh, start_emulator, stop_emulator,
- StartEmulatorOptions};
-use failure::{err_msg, Error, ResultExt};
-pub use sdk::TargetOptions;
-use sdk::{cargo_out_dir, cargo_path, clang_archiver_path, clang_c_compiler_path,
- clang_cpp_compiler_path, clang_linker_path, clang_ranlib_path, rustc_path, rustdoc_path,
- shared_libraries_path, sysroot_path, zircon_build_path, FuchsiaConfig};
+use failure::{bail, err_msg, Error, ResultExt};
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
-use utils::strip_binary;
fn copy_to_target(
- source_path: &PathBuf, verbose: bool, target_options: &TargetOptions,
+ source_path: &PathBuf, verbose: bool, target_options: &TargetOptions<'_, '_>,
) -> Result<String, Error> {
let netaddr = netaddr(verbose, target_options)?;
if verbose {
@@ -62,7 +59,7 @@
}
fn run_program_on_target(
- filename: &str, verbose: bool, target_options: &TargetOptions, run_with_tiles: bool,
+ filename: &str, verbose: bool, target_options: &TargetOptions<'_, '_>, run_with_tiles: bool,
params: &[&str], test_args: Option<&str>,
) -> Result<(), Error> {
let source_path = PathBuf::from(&filename);
@@ -95,7 +92,7 @@
use std::time::Duration;
fn autotest(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions,
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>,
) -> Result<(), Error> {
let (tx, rx) = channel();
let mut watcher: RecommendedWatcher =
@@ -131,7 +128,7 @@
}
fn build_tests(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions, test_target: &str,
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>, test_target: &str,
) -> Result<bool, Error> {
run_tests(
run_cargo_options,
@@ -145,7 +142,7 @@
}
fn run_tests(
- run_cargo_options: &RunCargoOptions, no_run: bool, target_options: &TargetOptions,
+ run_cargo_options: &RunCargoOptions, no_run: bool, target_options: &TargetOptions<'_, '_>,
test_target: &str, params: &[&str], target_params: Option<&str>,
) -> Result<(), Error> {
let mut args = vec![];
@@ -181,7 +178,7 @@
}
fn build_binary(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions, params: &[&str],
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>, params: &[&str],
) -> Result<(), Error> {
run_cargo(
run_cargo_options,
@@ -194,7 +191,7 @@
}
fn check_binary(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions, params: &[&str],
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>, params: &[&str],
) -> Result<(), Error> {
run_cargo(
run_cargo_options,
@@ -207,14 +204,15 @@
}
fn run_binary(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions, params: &[&str],
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>, params: &[&str],
) -> Result<(), Error> {
run_cargo(run_cargo_options, "run", params, target_options, None, None)?;
Ok(())
}
fn build_doc(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions, no_deps: bool, open: bool,
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>, no_deps: bool,
+ open: bool,
) -> Result<(), Error> {
let mut args = vec![];
if no_deps {
@@ -227,7 +225,7 @@
}
fn load_driver(
- run_cargo_options: &RunCargoOptions, target_options: &TargetOptions,
+ run_cargo_options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>,
) -> Result<(), Error> {
let args = vec![];
run_cargo(
@@ -315,7 +313,7 @@
}
}
-fn get_triple_cpu(target_options: &TargetOptions) -> String {
+fn get_triple_cpu(target_options: &TargetOptions<'_, '_>) -> String {
if (target_options.target_cpu) == X64 {
"x86_64"
} else {
@@ -323,14 +321,14 @@
}.to_string()
}
-fn get_target_triple(target_options: &TargetOptions) -> String {
+fn get_target_triple(target_options: &TargetOptions<'_, '_>) -> String {
let triple_cpu = get_triple_cpu(target_options);
format!("{}-fuchsia", triple_cpu)
}
fn get_rustflags(
- target_options: &TargetOptions, sysroot_as_path: &PathBuf,
+ target_options: &TargetOptions<'_, '_>, sysroot_as_path: &PathBuf,
) -> Result<String, Error> {
Ok(format!(
"-C link-arg=--target={} -C link-arg=--sysroot={} -Lnative={}",
@@ -341,7 +339,7 @@
}
fn make_fargo_command(
- runner: Option<PathBuf>, options: &RunCargoOptions, target_options: &TargetOptions,
+ runner: Option<PathBuf>, options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>,
additional_target_args: Option<&str>,
) -> Result<String, Error> {
let tiles_arg = format!("--{}", TILES);
@@ -419,8 +417,9 @@
/// );
/// ```
pub fn run_cargo(
- options: &RunCargoOptions, subcommand: &str, args: &[&str], target_options: &TargetOptions,
- runner: Option<PathBuf>, additional_target_args: Option<&str>,
+ options: &RunCargoOptions, subcommand: &str, args: &[&str],
+ target_options: &TargetOptions<'_, '_>, runner: Option<PathBuf>,
+ additional_target_args: Option<&str>,
) -> Result<(), Error> {
if options.verbose {
println!("target_options = {:?}", target_options);
@@ -541,7 +540,9 @@
Ok(())
}
-fn write_config(options: &RunCargoOptions, target_options: &TargetOptions) -> Result<(), Error> {
+fn write_config(
+ options: &RunCargoOptions, target_options: &TargetOptions<'_, '_>,
+) -> Result<(), Error> {
let cargo_dir_path = Path::new(".cargo");
if cargo_dir_path.exists() {
if !cargo_dir_path.is_dir() {
diff --git a/src/sdk.rs b/src/sdk.rs
index 86d6361..3b3d9c6 100644
--- a/src/sdk.rs
+++ b/src/sdk.rs
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-use failure::Error;
-use get_target_triple;
+use crate::get_target_triple;
+use crate::utils::is_mac;
+use crate::X64;
+use failure::{bail, Error};
use std::env;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
-use utils::is_mac;
-use X64;
/// The `TargetOptions` struct bundles together a number of parameters specific to
/// the Fuchsia target that need to be passed through various internal functions. For
@@ -70,7 +70,7 @@
Ok(None)
}
-pub fn fuchsia_dir(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn fuchsia_dir(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let fuchsia_dir = if let Some(fuchsia_root) = get_path_from_env("FUCHSIA_ROOT", true)? {
fuchsia_root
} else if let Some(fuchsia_dir) = get_path_from_env("FUCHSIA_DIR", true)? {
@@ -97,7 +97,7 @@
}
pub fn possible_target_out_dir(
- fuchsia_dir: &PathBuf, options: &TargetOptions,
+ fuchsia_dir: &PathBuf, options: &TargetOptions<'_, '_>,
) -> Result<PathBuf, Error> {
let out_dir_name_prefix = if options.release_os {
"release"
@@ -112,12 +112,12 @@
Ok(target_out_dir)
}
-pub fn target_out_dir(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn target_out_dir(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let fuchsia_dir = fuchsia_dir(options)?;
possible_target_out_dir(&fuchsia_dir, options)
}
-pub fn cargo_out_dir(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn cargo_out_dir(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let fuchsia_dir = fuchsia_dir(options)?;
let target_triple = get_target_triple(options);
Ok(fuchsia_dir
@@ -127,11 +127,11 @@
.join("debug"))
}
-pub fn strip_tool_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn strip_tool_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?.join("bin/llvm-objcopy"))
}
-pub fn sysroot_path(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn sysroot_path(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(target_out_dir(&options)?
.join("sdks")
.join("zircon_sysroot")
@@ -140,7 +140,7 @@
.join("sysroot"))
}
-pub fn zircon_build_path(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn zircon_build_path(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let fuchsia_dir = fuchsia_dir(options)?;
let build_name = if options.target_cpu == X64 {
"build-x64"
@@ -154,7 +154,7 @@
Ok(zircon_build)
}
-pub fn shared_libraries_path(options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn shared_libraries_path(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let shared_name = if options.target_cpu == X64 {
"x64-shared"
} else {
@@ -163,14 +163,14 @@
Ok(target_out_dir(&options)?.join(shared_name))
}
-fn buildtools_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+fn buildtools_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let platform_name = if is_mac() { "mac-x64" } else { "linux-x64" };
Ok(fuchsia_dir(target_options)?
.join("buildtools")
.join(platform_name))
}
-pub fn cargo_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn cargo_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
if let Some(cargo_path) = get_path_from_env("FARGO_CARGO", false)? {
Ok(cargo_path)
} else {
@@ -178,7 +178,7 @@
}
}
-pub fn rustc_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn rustc_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
if let Some(rustc_path) = get_path_from_env("FARGO_RUSTC", false)? {
Ok(rustc_path)
} else {
@@ -186,7 +186,7 @@
}
}
-pub fn rustdoc_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn rustdoc_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
if let Some(rustdoc_path) = get_path_from_env("FARGO_RUSTDOC", false)? {
Ok(rustdoc_path)
} else {
@@ -194,33 +194,33 @@
}
}
-pub fn toolchain_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn toolchain_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(buildtools_path(target_options)?.join("clang"))
}
-pub fn clang_linker_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn clang_linker_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?.join("bin").join("clang"))
}
-pub fn clang_c_compiler_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn clang_c_compiler_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?.join("bin").join("clang"))
}
-pub fn clang_cpp_compiler_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn clang_cpp_compiler_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?.join("bin").join("clang++"))
}
-pub fn clang_archiver_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn clang_archiver_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?.join("bin").join("llvm-ar"))
}
-pub fn clang_ranlib_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn clang_ranlib_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
Ok(toolchain_path(target_options)?
.join("bin")
.join("llvm-ranlib"))
}
-pub fn fx_path(target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn fx_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
let fuchsia_dir = fuchsia_dir(target_options)?;
Ok(fuchsia_dir.join("scripts/fx"))
}
@@ -234,7 +234,7 @@
}
impl FuchsiaConfig {
- pub fn new(target_options: &TargetOptions) -> Result<FuchsiaConfig, Error> {
+ pub fn new(target_options: &TargetOptions<'_, '_>) -> Result<FuchsiaConfig, Error> {
let mut config = FuchsiaConfig {
fuchsia_build_dir: String::from(""),
fuchsia_variant: String::from(""),
diff --git a/src/utils.rs b/src/utils.rs
index 00722bf..b472f91 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-use failure::{Error, ResultExt};
-use sdk::{strip_tool_path, TargetOptions};
+use crate::sdk::{strip_tool_path, TargetOptions};
+use failure::{bail, Error, ResultExt};
use std::path::PathBuf;
use std::process::Command;
use std::time::Duration;
@@ -19,7 +19,9 @@
uname().unwrap().sysname == "Darwin"
}
-pub fn strip_binary(binary: &PathBuf, target_options: &TargetOptions) -> Result<PathBuf, Error> {
+pub fn strip_binary(
+ binary: &PathBuf, target_options: &TargetOptions<'_, '_>,
+) -> Result<PathBuf, Error> {
let file_name = binary.file_name().unwrap();
let new_file_name = file_name.to_string_lossy().into_owned() + "_stripped";
let target_path = binary.parent().unwrap().join(new_file_name);