mirror of https://github.com/rust-lang/cargo
Explicitly pass root package to ops::package_compile
This commit is contained in:
parent
7ed3bd8b9c
commit
5a59414edb
4
Makefile
4
Makefile
|
@ -14,7 +14,7 @@ SRC = $(shell find src -name '*.rs')
|
|||
DEPS = -L libs/hammer.rs/target -L libs/rust-toml/lib
|
||||
TOML = libs/rust-toml/lib/$(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs)
|
||||
HAMMER = libs/hammer.rs/target/$(shell rustc --crate-type=lib --crate-file-name libs/hammer.rs/src/hammer.rs)
|
||||
HAMCREST = libs/hamcrest-rust/target/timestamp
|
||||
HAMCREST = libs/hamcrest-rust/target/libhamcrest.timestamp
|
||||
LIBCARGO = target/libcargo.timestamp
|
||||
BIN_TARGETS = $(patsubst %,target/%,$(BINS))
|
||||
|
||||
|
@ -61,7 +61,7 @@ test-unit: target/tests/test-unit
|
|||
target/tests/test-unit $(only)
|
||||
|
||||
test-integration: target/tests/test-integration
|
||||
RUST_TEST_TASKS=1 CARGO_BIN_PATH=$(PWD)/target/ $<
|
||||
RUST_TEST_TASKS=1 CARGO_BIN_PATH=$(PWD)/target/ $< $(only)
|
||||
|
||||
test: test-unit test-integration
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e9d78bcff974668475752d553f3813df2cc018b2
|
||||
Subproject commit e68c3610068f446304f88e08a57a9e7e3693fa59
|
|
@ -17,12 +17,13 @@
|
|||
use std::os;
|
||||
use util::config;
|
||||
use util::config::{ConfigValue};
|
||||
use core::{PackageSet,Source};
|
||||
use core::{Package,PackageSet,Source};
|
||||
use core::resolver::resolve;
|
||||
use sources::path::PathSource;
|
||||
use ops;
|
||||
use util::{other_error, CargoResult, Wrap};
|
||||
|
||||
// TODO: manifest_path should be Path
|
||||
pub fn compile(manifest_path: &str) -> CargoResult<()> {
|
||||
log!(4, "compile; manifest-path={}", manifest_path);
|
||||
|
||||
|
@ -30,8 +31,6 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
|
|||
|
||||
debug!("loaded manifest; manifest={}", manifest);
|
||||
|
||||
let root_dep = manifest.to_dependency();
|
||||
|
||||
let configs = try!(config::all_configs(os::getcwd()));
|
||||
|
||||
debug!("loaded config; configs={}", configs);
|
||||
|
@ -47,7 +46,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
|
|||
|
||||
let source = PathSource::new(paths);
|
||||
let summaries = try!(source.list().wrap("unable to list packages from source"));
|
||||
let resolved = try!(resolve([root_dep], &summaries).wrap("unable to resolve dependencies"));
|
||||
let resolved = try!(resolve(manifest.get_dependencies(), &summaries).wrap("unable to resolve dependencies"));
|
||||
|
||||
try!(source.download(resolved.as_slice()).wrap("unable to download packages"));
|
||||
|
||||
|
@ -55,7 +54,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
|
|||
|
||||
let package_set = PackageSet::new(packages.as_slice());
|
||||
|
||||
try!(ops::compile_packages(&package_set));
|
||||
try!(ops::compile_packages(&manifest, &package_set));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -2,35 +2,29 @@ use std::os::args;
|
|||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::str;
|
||||
use core;
|
||||
use core::{Package,PackageSet,Target};
|
||||
use util;
|
||||
use util::{other_error,human_error,CargoResult,CargoError,ProcessBuilder};
|
||||
use util::result::ProcessError;
|
||||
|
||||
type Args = Vec<String>;
|
||||
|
||||
pub fn compile_packages(pkgs: &core::PackageSet) -> CargoResult<()> {
|
||||
debug!("compiling; pkgs={}", pkgs);
|
||||
pub fn compile_packages(pkg: &Package, deps: &PackageSet) -> CargoResult<()> {
|
||||
debug!("compiling; pkg={}; deps={}", pkg, deps);
|
||||
|
||||
let mut sorted = match pkgs.sort() {
|
||||
Some(pkgs) => pkgs,
|
||||
None => return Err(other_error("circular dependency detected"))
|
||||
};
|
||||
|
||||
let root = sorted.pop();
|
||||
|
||||
for pkg in sorted.iter() {
|
||||
// Traverse the dependencies in topological order
|
||||
for dep in try!(topsort(deps)).iter() {
|
||||
println!("Compiling {}", pkg);
|
||||
try!(compile_pkg(pkg, pkgs, |rustc| rustc.exec_with_output()));
|
||||
try!(compile_pkg(dep, deps, false));
|
||||
}
|
||||
|
||||
println!("Compiling {}", root);
|
||||
try!(compile_pkg(&root, pkgs, |rustc| rustc.exec()));
|
||||
println!("Compiling {}", pkg);
|
||||
try!(compile_pkg(pkg, deps, true));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_pkg<T>(pkg: &core::Package, pkgs: &core::PackageSet, exec: |&ProcessBuilder| -> CargoResult<T>) -> CargoResult<()> {
|
||||
fn compile_pkg(pkg: &Package, pkgs: &PackageSet, verbose: bool) -> CargoResult<()> {
|
||||
debug!("compiling; pkg={}; targets={}; deps={}", pkg, pkg.get_targets(), pkg.get_dependencies());
|
||||
// Build up the destination
|
||||
// let src = pkg.get_root().join(Path::new(pkg.get_source().path.as_slice()));
|
||||
|
@ -43,7 +37,7 @@ fn compile_pkg<T>(pkg: &core::Package, pkgs: &core::PackageSet, exec: |&ProcessB
|
|||
|
||||
// compile
|
||||
for target in pkg.get_targets().iter() {
|
||||
try!(rustc(pkg.get_root(), target, &target_dir, pkgs.get_packages(), |rustc| exec(rustc)))
|
||||
try!(rustc(pkg.get_root(), target, &target_dir, pkgs.get_packages(), verbose))
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -53,16 +47,19 @@ fn mk_target(target: &Path) -> io::IoResult<()> {
|
|||
io::fs::mkdir_recursive(target, io::UserRWX)
|
||||
}
|
||||
|
||||
fn rustc<T>(root: &Path, target: &core::Target, dest: &Path, deps: &[core::Package], exec: |&ProcessBuilder| -> CargoResult<T>) -> CargoResult<()> {
|
||||
fn rustc(root: &Path, target: &Target, dest: &Path, deps: &[Package], verbose: bool) -> CargoResult<()> {
|
||||
let rustc = prepare_rustc(root, target, dest, deps);
|
||||
|
||||
try!(exec(&rustc)
|
||||
.map_err(|err| rustc_to_cargo_err(rustc.get_args().as_slice(), root, err)));
|
||||
try!((if verbose {
|
||||
rustc.exec()
|
||||
} else {
|
||||
rustc.exec_with_output().and(Ok(()))
|
||||
}).map_err(|e| rustc_to_cargo_err(rustc.get_args().as_slice(), root, e)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepare_rustc(root: &Path, target: &core::Target, dest: &Path, deps: &[core::Package]) -> ProcessBuilder {
|
||||
fn prepare_rustc(root: &Path, target: &Target, dest: &Path, deps: &[Package]) -> ProcessBuilder {
|
||||
let mut args = Vec::new();
|
||||
|
||||
build_base_args(&mut args, target, dest);
|
||||
|
@ -74,7 +71,7 @@ fn prepare_rustc(root: &Path, target: &core::Target, dest: &Path, deps: &[core::
|
|||
.env("RUST_LOG", None) // rustc is way too noisy
|
||||
}
|
||||
|
||||
fn build_base_args(into: &mut Args, target: &core::Target, dest: &Path) {
|
||||
fn build_base_args(into: &mut Args, target: &Target, dest: &Path) {
|
||||
// TODO: Handle errors in converting paths into args
|
||||
into.push(target.get_path().display().to_str());
|
||||
into.push("--crate-type".to_str());
|
||||
|
@ -83,7 +80,7 @@ fn build_base_args(into: &mut Args, target: &core::Target, dest: &Path) {
|
|||
into.push(dest.display().to_str());
|
||||
}
|
||||
|
||||
fn build_deps_args(dst: &mut Args, deps: &[core::Package]) {
|
||||
fn build_deps_args(dst: &mut Args, deps: &[Package]) {
|
||||
for dep in deps.iter() {
|
||||
let dir = dep.get_absolute_target_dir();
|
||||
|
||||
|
@ -111,3 +108,10 @@ fn rustc_to_cargo_err(args: &[String], cwd: &Path, err: CargoError) -> CargoErro
|
|||
|
||||
human_error(msg, format!("root={}", cwd.display()), err)
|
||||
}
|
||||
|
||||
fn topsort(deps: &PackageSet) -> CargoResult<PackageSet> {
|
||||
match deps.sort() {
|
||||
Some(deps) => Ok(deps),
|
||||
None => return Err(other_error("circular dependency detected"))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue