Skip to content

Commit 3f74d7e

Browse files
committed
Auto merge of #1284 - apasel422:issue-1277, r=alexcrichton
This is a WIP for #1277. I would like to add a test for the new behavior in `tests/test_cargo_test.rs`, but I'm having a hard time getting the output to match. Some feedback would be great to see if this is even the right approach.
2 parents 13f32f9 + 256faff commit 3f74d7e

30 files changed

+154
-106
lines changed

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo::ops::CompileOptions;
44
use cargo::ops;
@@ -47,7 +47,7 @@ the --release flag will use the `release` profile instead.
4747
";
4848

4949
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
50-
debug!("executing; cmd=cargo-build; args={:?}", os::args());
50+
debug!("executing; cmd=cargo-build; args={:?}", env::args().collect::<Vec<_>>());
5151
config.shell().set_verbose(options.flag_verbose);
5252

5353
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));

src/bin/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn list_command_directory() -> Vec<Path> {
245245
dirs.push(path.join("../lib/cargo"));
246246
dirs.push(path);
247247
}
248-
if let Some(val) = env::var("PATH") {
248+
if let Some(val) = env::var_os("PATH") {
249249
dirs.extend(env::split_paths(&val));
250250
}
251251
dirs

src/bin/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo::ops;
44
use cargo::util::{CliResult, CliError, Config};
@@ -33,7 +33,7 @@ and its format, see the `cargo help pkgid` command.
3333

3434
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
3535
config.shell().set_verbose(options.flag_verbose);
36-
debug!("executing; cmd=cargo-clean; args={:?}", os::args());
36+
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
3737

3838
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
3939
let opts = ops::CleanOptions {

src/bin/generate_lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo::ops;
44
use cargo::util::{CliResult, CliError, Config};
@@ -23,7 +23,7 @@ Options:
2323
";
2424

2525
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
26-
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", os::args());
26+
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
2727
config.shell().set_verbose(options.flag_verbose);
2828
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
2929

src/bin/new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo::ops;
44
use cargo::util::{CliResult, CliError, Config};
@@ -28,7 +28,7 @@ Options:
2828
";
2929

3030
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
31-
debug!("executing; cmd=cargo-new; args={:?}", os::args());
31+
debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
3232
config.shell().set_verbose(options.flag_verbose);
3333

3434
let Options { flag_bin, arg_path, flag_vcs, .. } = options;

src/bin/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo::ops;
44
use cargo::util::{CliResult, CliError, Config};
@@ -49,7 +49,7 @@ For more information about package id specifications, see `cargo help pkgid`.
4949
";
5050

5151
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
52-
debug!("executing; cmd=cargo-update; args={:?}", os::args());
52+
debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
5353
config.shell().set_verbose(options.flag_verbose);
5454
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
5555

src/bin/verify_project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
extern crate toml;
22

33
use std::collections::HashMap;
4+
use std::env;
45
use std::old_io::File;
5-
use std::os;
66

77
use cargo::util::{CliResult, Config};
88

@@ -47,6 +47,6 @@ pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
4747
fn fail(reason: &str, value: &str) -> CliResult<Option<Error>>{
4848
let mut h = HashMap::new();
4949
h.insert(reason.to_string(), value.to_string());
50-
os::set_exit_status(1);
50+
env::set_exit_status(1);
5151
Ok(Some(h))
5252
}

src/bin/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os;
1+
use std::env;
22

33
use cargo;
44
use cargo::util::{CliResult, Config};
@@ -16,7 +16,7 @@ Options:
1616
";
1717

1818
pub fn execute(_: Options, _: &Config) -> CliResult<Option<()>> {
19-
debug!("executing; cmd=cargo-version; args={:?}", os::args());
19+
debug!("executing; cmd=cargo-version; args={:?}", env::args().collect::<Vec<_>>());
2020

2121
println!("{}", cargo::version());
2222

src/cargo/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn process<V, F>(mut callback: F)
9595
let mut shell = shell(true);
9696
process_executed((|| {
9797
let config = try!(Config::new(&mut shell));
98-
let args: Vec<_> = try!(env::args().map(|s| {
98+
let args: Vec<_> = try!(env::args_os().map(|s| {
9999
s.into_string().map_err(|s| {
100100
human(format!("invalid unicode in argument: {:?}", s))
101101
})

src/cargo/ops/cargo_new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ fn discover_author() -> CargoResult<(String, Option<String>)> {
134134
let git_config = git_config.as_ref();
135135
let name = git_config.and_then(|g| g.get_str("user.name").ok())
136136
.map(|s| s.to_string())
137-
.or_else(|| env::var_string("USER").ok()) // unix
138-
.or_else(|| env::var_string("USERNAME").ok()); // windows
137+
.or_else(|| env::var("USER").ok()) // unix
138+
.or_else(|| env::var("USERNAME").ok()); // windows
139139
let name = match name {
140140
Some(name) => name,
141141
None => {

src/cargo/ops/cargo_rustc/compilation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{HashMap, HashSet};
22
use std::dynamic_lib::DynamicLibrary;
33
use std::ffi::CString;
44
use std::old_path::BytesContainer;
@@ -42,6 +42,9 @@ pub struct Compilation {
4242

4343
/// Top-level package that was compiled
4444
pub package: Package,
45+
46+
/// Features enabled during this compilation.
47+
pub features: HashSet<String>,
4548
}
4649

4750
impl Compilation {
@@ -55,6 +58,7 @@ impl Compilation {
5558
binaries: Vec::new(),
5659
extra_env: HashMap::new(),
5760
package: pkg.clone(),
61+
features: HashSet::new(),
5862
}
5963
}
6064

src/cargo/ops/cargo_rustc/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl CommandPrototype {
8585

8686
pub fn get_env(&self, var: &str) -> Option<CString> {
8787
self.env.get(var).cloned().or_else(|| {
88-
Some(env::var_string(var).ok().map(|s| CString::from_vec(s.into_bytes())))
88+
Some(env::var(var).ok().map(|s| CString::from_vec(s.into_bytes())))
8989
}).and_then(|val| val)
9090
}
9191

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ pub fn compile_targets<'a, 'b>(env: &str,
189189
let out_dir = cx.layout(pkg, Kind::Target).build_out(pkg)
190190
.display().to_string();
191191
cx.compilation.extra_env.insert("OUT_DIR".to_string(), Some(out_dir));
192+
193+
if let Some(feats) = cx.resolve.features(pkg.package_id()) {
194+
cx.compilation.features.extend(feats.iter().cloned());
195+
}
196+
192197
for (&(ref pkg, _), output) in cx.build_state.outputs.lock().unwrap().iter() {
193198
let any_dylib = output.library_links.iter().any(|l| {
194199
!l.ends_with(":static") && !l.ends_with(":framework")

src/cargo/ops/cargo_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub fn run_tests(manifest_path: &Path,
7272
p = p.arg("--test-args").arg(test_args.connect(" "));
7373
}
7474

75+
for feat in compile.features.iter() {
76+
p = p.arg("--cfg").arg(format!("feature=\"{}\"", feat));
77+
}
78+
7579
for (pkg, libs) in compile.libraries.iter() {
7680
for lib in libs.iter() {
7781
let mut arg = pkg.name().as_bytes().to_vec();

src/cargo/ops/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
191191
}
192192
Err(..) => {}
193193
}
194-
Ok(env::var_string("HTTP_PROXY").ok())
194+
Ok(env::var("HTTP_PROXY").ok())
195195
}
196196

197197
pub fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {
198198
match try!(config.get_i64("http.timeout")) {
199199
Some((s, _)) => return Ok(Some(s)),
200200
None => {}
201201
}
202-
Ok(env::var_string("HTTP_TIMEOUT").ok().and_then(|s| s.parse().ok()))
202+
Ok(env::var("HTTP_TIMEOUT").ok().and_then(|s| s.parse().ok()))
203203
}
204204

205205
pub fn registry_login(config: &Config, token: String) -> CargoResult<()> {

src/cargo/sources/git/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ impl<'a> GitCheckout<'a> {
308308
// as the submodule's head, then we can bail out and go to the
309309
// next submodule.
310310
let head_and_repo = child.open().and_then(|repo| {
311-
Ok((try!(repo.head()).target(), repo))
311+
let target = try!(repo.head()).target();
312+
Ok((target, repo))
312313
});
313314
let repo = match head_and_repo {
314315
Ok((head, repo)) => {

src/cargo/util/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl ConfigValue {
380380
}
381381

382382
fn homedir() -> Option<Path> {
383-
let cargo_home = env::var_string("CARGO_HOME").map(|p| Path::new(p)).ok();
383+
let cargo_home = env::var("CARGO_HOME").map(|p| Path::new(p)).ok();
384384
let user_home = env::home_dir().map(|p| p.join(".cargo"));
385385
return cargo_home.or(user_home);
386386
}

src/cargo/util/hex.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use std::old_io::MemWriter;
21
use std::hash::{Hasher, Hash, SipHasher};
32

43
use rustc_serialize::hex::ToHex;
54

65
pub fn to_hex(num: u64) -> String {
7-
let mut writer = MemWriter::with_capacity(8);
6+
let mut writer = Vec::with_capacity(8);
87
writer.write_le_u64(num).unwrap(); // this should never fail
9-
writer.get_ref().to_hex()
8+
writer.to_hex()
109
}
1110

1211
pub fn short_hash<H: Hash<SipHasher>>(hashable: &H) -> String {

src/cargo/util/profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Profiler {
1414
desc: String,
1515
}
1616

17-
fn enabled() -> bool { env::var("CARGO_PROFILE").is_some() }
17+
fn enabled() -> bool { env::var_os("CARGO_PROFILE").is_some() }
1818

1919
pub fn start<T: fmt::Display>(desc: T) -> Profiler {
2020
if !enabled() { return Profiler { desc: String::new() } }

src/rustversion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2015-02-09
1+
2015-02-12

tests/support/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<T, E: fmt::Display> ErrMsg<T> for Result<T, E> {
227227

228228
// Path to cargo executables
229229
pub fn cargo_dir() -> Path {
230-
env::var_string("CARGO_BIN_PATH").map(Path::new).ok()
230+
env::var("CARGO_BIN_PATH").map(Path::new).ok()
231231
.or_else(|| env::current_exe().ok().map(|s| s.dir_path()))
232232
.unwrap_or_else(|| {
233233
panic!("CARGO_BIN_PATH wasn't set. Cannot continue running test")

tests/test_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn fake_executable(proj: ProjectBuilder, dir: &Path, name: &str) -> ProjectBuild
2525
}
2626

2727
fn path() -> Vec<Path> {
28-
env::split_paths(&env::var("PATH").unwrap_or(OsString::new())).collect()
28+
env::split_paths(&env::var_os("PATH").unwrap_or(OsString::new())).collect()
2929
}
3030

3131
test!(list_commands_looks_at_path {

0 commit comments

Comments
 (0)