Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul how cargo treats profiles #1441

Merged
merged 24 commits into from
Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9e77919
Overhaul how cargo treats profiles
alexcrichton Feb 19, 2015
26cf004
Fix cargo test filtering for binaries
alexcrichton Mar 21, 2015
5408fd7
Remove an extraneous is_test condition
alexcrichton Mar 21, 2015
1a452fb
Fix test for `--test` filtering
alexcrichton Mar 21, 2015
07b53ec
Fix cargo test --no-run
alexcrichton Mar 21, 2015
0a187e7
Fix configuring lib targets with profile options
alexcrichton Mar 21, 2015
eb2b6f0
Only doctest libs by default
alexcrichton Mar 21, 2015
a54d240
Fix a subtesting test
alexcrichton Mar 21, 2015
48a5d75
Don't fail `cargo run` with bins + examples
alexcrichton Mar 21, 2015
fb8a3e3
List examples in binaries built
alexcrichton Mar 21, 2015
8989d82
Fix test for bins/examples
alexcrichton Mar 21, 2015
c18158b
Update error message for missing examples
alexcrichton Mar 21, 2015
fc9212c
Fix `cargo run` with no binaries
alexcrichton Mar 21, 2015
891da62
Don't compile build scripts if they aren't run
alexcrichton Mar 21, 2015
a83a50f
Update some error messages in tests
alexcrichton Mar 21, 2015
9adbdef
Fix fingerprints of build scripts that aren't compiled
alexcrichton Mar 21, 2015
201aa61
Don't factor bins into fingerprint calculations
alexcrichton Mar 21, 2015
7d1419d
Update tests for tweaked error messages
alexcrichton Mar 21, 2015
8350cd1
Fix `cargo doc`
alexcrichton Mar 22, 2015
1273003
Fix documenting binaries with libraries
alexcrichton Mar 23, 2015
8bebb3e
Fix trying to document build scripts
alexcrichton Mar 23, 2015
23d3def
Fix printing `Fresh` for crates
alexcrichton Mar 23, 2015
3ce79da
len() == 0 => is_empty()
alexcrichton Mar 23, 2015
0c28783
Fix tests for windows
alexcrichton Mar 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,31 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
config.shell().set_verbose(options.flag_verbose);

let mut benches = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this vector looks unnecessary - seems you could use options.flag_bench.as_slice()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently trying to keep Cargo on stable Rust as much as possible, and unfortunately these methods are currently unstable. I had not considered this though, and it's a good idea! I may try to facilitate the stability of as_slice now...

if let Some(s) = options.flag_bench {
benches.push(s);
}

let ops = ops::TestOptions {
name: options.flag_bench.as_ref().map(|s| &s[..]),
no_run: options.flag_no_run,
compile_opts: ops::CompileOptions {
env: "bench",
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
dev_deps: true,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
lib_only: false,
exec_engine: None,
release: true,
mode: ops::CompileMode::Bench,
filter: if benches.is_empty() {
ops::CompileFilter::Everything
} else {
ops::CompileFilter::Only {
lib: false, bins: &[], examples: &[], tests: &[],
benches: &benches,
}
},
},
};

Expand Down
21 changes: 11 additions & 10 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,29 @@ the --release flag will use the `release` profile instead.
";

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

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

let env = if options.flag_release {
"release"
} else {
"compile"
};

let opts = CompileOptions {
env: env,
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
dev_deps: false,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
lib_only: options.flag_lib,
exec_engine: None,
mode: ops::CompileMode::Build,
release: options.flag_release,
filter: if options.flag_lib {
ops::CompileFilter::Only {
lib: true, bins: &[], examples: &[], benches: &[], tests: &[]
}
} else {
ops::CompileFilter::Everything
},
};

ops::compile(&root, &opts).map(|_| None).map_err(|err| {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
// For the commands `cargo` and `cargo help`, re-execute ourselves as
// `cargo -h` so we can go through the normal process of printing the
// help message.
"" | "help" if flags.arg_args.len() == 0 => {
"" | "help" if flags.arg_args.is_empty() => {
config.shell().set_verbose(true);
let args = &["cargo".to_string(), "-h".to_string()];
let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
Expand Down
9 changes: 5 additions & 4 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));

let mut doc_opts = ops::DocOptions {
all: !options.flag_no_deps,
open_result: options.flag_open,
compile_opts: ops::CompileOptions {
env: if options.flag_no_deps {"doc"} else {"doc-all"},
config: config,
jobs: options.flag_jobs,
target: None,
dev_deps: false,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
lib_only: false,
exec_engine: None,
filter: ops::CompileFilter::Everything,
release: false,
mode: ops::CompileMode::Doc {
deps: !options.flag_no_deps,
},
},
};

Expand Down
38 changes: 18 additions & 20 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cargo::ops;
use cargo::core::manifest::TargetKind;
use cargo::util::{CliResult, CliError, human, Config};
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::{find_root_manifest_for_cwd};

#[derive(RustcDecodable)]
Expand Down Expand Up @@ -47,36 +46,35 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config.shell().set_verbose(options.flag_verbose);
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));

let env = match (options.flag_release, options.flag_example.is_some()) {
(true, _) => "release",
(false, true) => "test",
(false, false) => "compile"
};
let (mut examples, mut bins) = (Vec::new(), Vec::new());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto single-element vectors

if let Some(s) = options.flag_bin {
bins.push(s);
}
if let Some(s) = options.flag_example {
examples.push(s);
}

let compile_opts = ops::CompileOptions {
env: env,
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
dev_deps: true,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: None,
lib_only: false,
exec_engine: None,
};

let (target_kind, name) = match (options.flag_bin, options.flag_example) {
(Some(bin), None) => (TargetKind::Bin, Some(bin)),
(None, Some(example)) => (TargetKind::Example, Some(example)),
(None, None) => (TargetKind::Bin, None),
(Some(_), Some(_)) => return Err(CliError::from_boxed(
human("specify either `--bin` or `--example`, not both"), 1)),
release: options.flag_release,
mode: ops::CompileMode::Build,
filter: if examples.is_empty() && bins.is_empty() {
ops::CompileFilter::Everything
} else {
ops::CompileFilter::Only {
lib: false, tests: &[], benches: &[],
bins: &bins, examples: &examples,
}
},
};

let err = try!(ops::run(&root,
target_kind,
name,
&compile_opts,
&options.arg_args).map_err(|err| {
CliError::from_boxed(err, 101)
Expand Down
26 changes: 21 additions & 5 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct Options {
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_test: Option<String>,
flag_bin: Option<String>,
flag_no_default_features: bool,
flag_no_run: bool,
flag_package: Option<String>,
Expand All @@ -24,7 +25,8 @@ Usage:

Options:
-h, --help Print this message
--test NAME Name of the test executable to run
--test NAME Name of the integration test to run
--bin NAME Name of the binary to run tests for
--no-run Compile, but don't run tests
-p SPEC, --package SPEC Package to run tests for
-j N, --jobs N The number of jobs to run in parallel
Expand Down Expand Up @@ -52,20 +54,34 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
config.shell().set_verbose(options.flag_verbose);

let (mut tests, mut bins) = (Vec::new(), Vec::new());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

if let Some(s) = options.flag_test {
tests.push(s);
}
if let Some(s) = options.flag_bin {
bins.push(s);
}

let ops = ops::TestOptions {
name: options.flag_test.as_ref().map(|s| &s[..]),
no_run: options.flag_no_run,
compile_opts: ops::CompileOptions {
env: "test",
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
dev_deps: true,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
lib_only: false,
exec_engine: None,
release: false,
mode: ops::CompileMode::Test,
filter: if tests.is_empty() && bins.is_empty() {
ops::CompileFilter::Everything
} else {
ops::CompileFilter::Only {
lib: false, examples: &[], benches: &[],
tests: &tests, bins: &bins,
}
}
},
};

Expand Down
Loading