Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCompile tests for multiple packages #1828
Conversation
rust-highfive
assigned
alexcrichton
Jul 24, 2015
This comment has been minimized.
This comment has been minimized.
rust-highfive
commented
Jul 24, 2015
|
(rust_highfive has picked a reviewer for you, use r? to override) |
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
8b8df3e
to
64a8cb0
Jul 24, 2015
alexcrichton
reviewed
Jul 24, 2015
| @@ -26,7 +26,7 @@ pub const USAGE: &'static str = " | |||
| Execute all unit and integration tests of a local package | |||
| Usage: | |||
| cargo test [options] [--] [<args>...] | |||
| cargo test [options] [-p SPEC --package SPEC]... [--] [<args>...] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 24, 2015
Member
cc @BurntSushi, you mentioned on docopt/docopt#275 that you were thinking of proposing the ability to do this in the options section instead of up here in the usage section, do you know if there's been progress on that? I wouldn't mind proposing an idea or two on that thread to see if I can get discussion rolling again, it'd be great to fix :)
This comment has been minimized.
This comment has been minimized.
BurntSushi
Jul 28, 2015
Member
@alexcrichton Thanks for the reminder! I have a candidate implementation working in 0.6.69. See my proposal for details: docopt/docopt#275 (Even though it's working in the Rust implementation, I probably wouldn't add it into Cargo quite yet in case the proposal changes. If it's ultimately rejected, I might still leave it in because I think it's really really useful.)
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
Jul 24, 2015
| fn resolve_dependencies<'a>(options: &CompileOptions<'a>, | ||
| package: &Package, | ||
| source: Option<Box<Source + 'a>> | ||
| ) -> (Vec<Package>, Resolve, SourceMap<'a>) { |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 24, 2015
Member
Stylistically these kinds of functions are formatted as this in cargo:
fn foo(a: A,
b: B)
-> Ret {
// ...
alexcrichton
reviewed
Jul 24, 2015
| package: &Package, | ||
| source: Option<Box<Source + 'a>> | ||
| ) -> (Vec<Package>, Resolve, SourceMap<'a>) { | ||
| let override_ids = source_ids_from_config(options.config, package.root()).unwrap(); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 24, 2015
Member
All the unwrap() calls in this function should be converted to try!
alexcrichton
reviewed
Jul 24, 2015
| }; | ||
| let pkgid = pkgids.first().unwrap(); | ||
| let to_build = packages.iter().find(|p| p.package_id() == *pkgid).unwrap(); | ||
| let to_builds = packages.iter().filter(|p| pkgids.iter().find(|&op| *op == p.package_id()).is_some()).collect::<Vec<&Package>>(); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 24, 2015
Member
Can you be sure that lines are word-wrapped to 80 characters in Cargo?
alexcrichton
reviewed
Jul 24, 2015
| build_config, profiles)); | ||
|
|
||
| let mut queue = JobQueue::new(cx.resolve, deps, cx.jobs()); | ||
|
|
||
| let _p = profile::start("preparing build directories"); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 24, 2015
Member
This ends up finishing the profiling when it's dropped, which is now at the end of the function (which is why this wanted an explicit scope)
alexcrichton
reviewed
Jul 24, 2015
| try!(cx.prepare(pkg, targets)); | ||
| prepare_init(&mut cx, pkg, &mut queue, &mut HashSet::new()); | ||
| custom_build::build_map(&mut cx, pkg, targets); | ||
| try!(compile(targets, pkg, &mut cx, &mut queue)); | ||
| } | ||
|
|
||
| // Build up a list of pending jobs, each of which represent compiling a | ||
| // particular package. No actual work is executed as part of this, that's | ||
| // all done next as part of the `execute` function which will run | ||
| // everything in order with proper parallelism. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Yeah this all looks like a pretty good approach to me! |
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
64a8cb0
to
44957f6
Jul 24, 2015
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
a56fd80
to
38335d8
Aug 2, 2015
This comment has been minimized.
This comment has been minimized.
|
|
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
3 times, most recently
from
35c6833
to
4f7f409
Sep 6, 2015
This comment has been minimized.
This comment has been minimized.
|
I finally had time to work on this PR again. I have started adding tests, but I am not sure how to test |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
The nondeterminism may be solved by |
alexcrichton
reviewed
Sep 9, 2015
| @@ -26,7 +26,7 @@ pub const USAGE: &'static str = " | |||
| Execute all benchmarks of a local package | |||
| Usage: | |||
| cargo bench [options] [--] [<args>...] | |||
| cargo bench [options] [-p SPEC --package SPEC]... [--] [<args>...] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
I think that new syntax in docopt may actually allow for nicer definitions of this, something like:
Options:
-p, --package=SPEC ... Description ...
I believe it's still somewhat experimental, but this may be a good place to get a good start on it?
alexcrichton
reviewed
Sep 9, 2015
| @@ -48,7 +48,7 @@ pub struct CompileOptions<'a> { | |||
| /// Flag if the default feature should be built for the root package | |||
| pub no_default_features: bool, | |||
| /// Root package to build (if None it's the current one) | |||
| pub spec: Option<&'a str>, | |||
| pub spec: Vec<&'a str>, | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
This may be much easier to take if it's a &'a [String], that way all the commands above can avoid casting and collection (e.g. they're just &options.flag_package
alexcrichton
reviewed
Sep 9, 2015
| if let Some(source) = source { | ||
| registry.preload(package.package_id().source_id(), source); | ||
| } else { | ||
| try!(registry.add_sources(&[package.package_id().source_id() | ||
| .clone()])); | ||
| try!(registry.add_sources(&[package.package_id().source_id().clone()])); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
Were the changes around here necessary? (looks to be pretty similar)
alexcrichton
reviewed
Sep 9, 2015
| dev_deps: true, // TODO: remove this option? | ||
| features: &features, | ||
| uses_default_features: !no_default_features, | ||
| uses_default_features: !options.no_default_features, |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
Same as above, probably good to cut down to as few changes as possible.
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
Sep 9, 2015
| id | ||
| }).filter(|id| | ||
| id.is_ok() | ||
| ).map(|id| id.unwrap()).collect::<Vec<&PackageId>>() |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
This may be better expressed as:
spec.iter().filter_map(|p| {
match resolved_with_overrides.query(p) {
Ok(p) => Some(p),
Err(..) => { invalid_spec.push(p); None }
}
}).collect::<Vec<_>>();I'm also a little hesitant about throwing away the error information, I think invalid specifications will want to retain the error information about why they were invalid
alexcrichton
reviewed
Sep 9, 2015
| invalid_spec.join(", ")))); | ||
| } | ||
|
|
||
| let pkgid = pkgids[0]; | ||
| let to_build = packages.iter().find(|p| p.package_id() == pkgid).unwrap(); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
Isn't this variable obsolete now? There could be more than one package being built?
alexcrichton
reviewed
Sep 9, 2015
| @@ -54,8 +54,9 @@ pub struct TargetConfig { | |||
|
|
|||
| // Returns a mapping of the root package plus its immediate dependencies to | |||
| // where the compiled libraries are all located. | |||
| pub fn compile_targets<'a, 'cfg: 'a>(targets: &[(&'a Target, &'a Profile)], | |||
| pkg: &'a Package, | |||
| pub fn compile_targets<'a, 'cfg: 'a>(pkg_targets: &'a Vec<(&Package, | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
&'a Vec<T> should basically always be avoided in favor of &'a [T] explicitly.
alexcrichton
reviewed
Sep 9, 2015
| if targets.is_empty() { | ||
|
|
||
| let &(pkg, _) = pkg_targets.first().unwrap(); | ||
| if pkg_targets.iter().any(|&(_, ref targets)| targets.is_empty()) { |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
This isn't quite right any more I think because singling out the first package isn't really possible any more. This entire if may actually just be able to go away.
alexcrichton
reviewed
Sep 9, 2015
| } else { | ||
| deps.iter().find(|p| p.package_id() == resolve.root()).unwrap() | ||
| }; | ||
| let root = deps.iter().find(|p| p.package_id() == resolve.root()).unwrap(); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
I think this logic will need to be updated, the notion of a "root" package doesn't really exist any more, so those which are depending on it probably need to be updated.
This comment has been minimized.
This comment has been minimized.
fhahn
Sep 15, 2015
Author
Contributor
At the moment -p SPEC only builds packages that are dependencies of the "root" package, and all generated binaries are stored relative to that root package. I think this root package is mostly used to get a base path for the build output and I think this notation should still be valid?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 16, 2015
Member
Hm the placement of the output directory should be relatively independent from the root package (e.g. it's just a default), as in once the output directory is chosen the root package is never needed after that.
I'll try to audit for usage of this regardless, though, to see what's up.
alexcrichton
reviewed
Sep 9, 2015
| build_config, profiles)); | ||
|
|
||
| let mut queue = JobQueue::new(cx.resolve, deps, cx.jobs()); | ||
|
|
||
| // Prep the context's build requirements and see the job graph for all | ||
| // packages initially. | ||
| { | ||
| let _p = profile::start("preparing build directories"); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 9, 2015
Member
This profile marker isn't quite profiling the same thing any more, could you be sure to keep the scope the same as it was before?
alexcrichton
reviewed
Sep 9, 2015
| cx.compilation.libraries.insert(pkgid.clone(), v); | ||
|
|
||
| // Include immediate lib deps as well | ||
| for dep in cx.dep_targets(pkg, target, kind, profile).iter() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Ok, I think those failures on CI are spurious (only seen 1/3 before...), but could you also squash these commits down? It's ok to have a few, but I'd prefer to avoid "Address @alexcrichton's feedback" commits if possible :) |
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
a4e53be
to
2ebf892
Sep 30, 2015
sfackler
and others
added some commits
Sep 27, 2015
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
2ebf892
to
016e971
Sep 30, 2015
This comment has been minimized.
This comment has been minimized.
|
I've squashed the commits down to 6, but I could reduce the number even further if necessary. |
fhahn
added some commits
Sep 15, 2015
fhahn
force-pushed the
fhahn:multiple-package-parameters
branch
from
016e971
to
d9615d7
Sep 30, 2015
This comment has been minimized.
This comment has been minimized.
|
Looks like this may have accidentally picked up some other commits, perhaps a rebase is in order? I'll give this one last look-through but I'll probably just send it to bors. |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Sep 30, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit d9615d7
into
rust-lang:master
Sep 30, 2015
bors
referenced this pull request
Sep 30, 2015
Closed
Add `cargo rustdoc` for passing arbitrary flags to rustdoc #1977
fhahn
deleted the
fhahn:multiple-package-parameters
branch
Oct 1, 2015
This comment has been minimized.
This comment has been minimized.
|
Great, thanks @alexcrichton for your patience :) |
fhahn commentedJul 24, 2015
This PR for #1528 is still pretty rough (and so far only added multiple package support for tests), but I wanted to make sure the overall approach is fine.
I have made some progress and cargo is now able to compile and execute tests for multiple packages.
In order to execute the doc tests for multiple packages as well, I added
to_doc_testtoCompilation(used here). Previously it only executed the doc tests forCompilation.package. Another option would be to changeCompilation.packageto be aVec<Package>, because in order to execute the tests of multiple packages, multiple packages are compiled as "top level package". But this would require a changes at a couple of other places.