-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
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 26cf004
Fix cargo test filtering for binaries
alexcrichton 5408fd7
Remove an extraneous is_test condition
alexcrichton 1a452fb
Fix test for `--test` filtering
alexcrichton 07b53ec
Fix cargo test --no-run
alexcrichton 0a187e7
Fix configuring lib targets with profile options
alexcrichton eb2b6f0
Only doctest libs by default
alexcrichton a54d240
Fix a subtesting test
alexcrichton 48a5d75
Don't fail `cargo run` with bins + examples
alexcrichton fb8a3e3
List examples in binaries built
alexcrichton 8989d82
Fix test for bins/examples
alexcrichton c18158b
Update error message for missing examples
alexcrichton fc9212c
Fix `cargo run` with no binaries
alexcrichton 891da62
Don't compile build scripts if they aren't run
alexcrichton a83a50f
Update some error messages in tests
alexcrichton 9adbdef
Fix fingerprints of build scripts that aren't compiled
alexcrichton 201aa61
Don't factor bins into fingerprint calculations
alexcrichton 7d1419d
Update tests for tweaked error messages
alexcrichton 8350cd1
Fix `cargo doc`
alexcrichton 1273003
Fix documenting binaries with libraries
alexcrichton 8bebb3e
Fix trying to document build scripts
alexcrichton 23d3def
Fix printing `Fresh` for crates
alexcrichton 3ce79da
len() == 0 => is_empty()
alexcrichton 0c28783
Fix tests for windows
alexcrichton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>, | ||
|
@@ -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 | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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...