Skip to content

Commit 36cc414

Browse files
committed
auto merge of #9263 : catamorphism/rust/rustpkg-issue-7879, r=brson
r? @brson Treating a package as the thing that can have other packages depend on it, and depends on other packages, was wrong if a package has more than one crate. Now, rustpkg knows about dependencies between crates in the same package. This solves the problem reported in #7879 where rustpkg wrongly discovered a circular dependency between thhe package and itself, and recursed infinitely. Closes #7879
2 parents 8f65529 + e199790 commit 36cc414

File tree

9 files changed

+409
-249
lines changed

9 files changed

+409
-249
lines changed

src/librustpkg/api.rs

+21-36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use context::*;
1212
use crate::*;
1313
use package_id::*;
1414
use package_source::*;
15+
use target::*;
1516
use version::Version;
1617
use workcache_support::*;
1718

@@ -63,56 +64,40 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
6364
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
6465
lib: Path) {
6566
let cx = default_context(sysroot);
66-
let subroot = root.clone();
67-
let subversion = version.clone();
68-
let sublib = lib.clone();
69-
do cx.workcache_context.with_prep(name) |prep| {
70-
let pkg_src = PkgSrc {
71-
workspace: subroot.clone(),
72-
start_dir: subroot.push("src").push(name),
73-
id: PkgId{ version: subversion.clone(), ..PkgId::new(name)},
74-
libs: ~[mk_crate(sublib.clone())],
67+
let pkg_src = PkgSrc {
68+
workspace: root.clone(),
69+
start_dir: root.push("src").push(name),
70+
id: PkgId{ version: version, ..PkgId::new(name)},
71+
// n.b. This assumes the package only has one crate
72+
libs: ~[mk_crate(lib)],
7573
mains: ~[],
7674
tests: ~[],
7775
benchs: ~[]
7876
};
79-
pkg_src.declare_inputs(prep);
80-
let subcx = cx.clone();
81-
let subsrc = pkg_src.clone();
82-
do prep.exec |exec| {
83-
subsrc.build(exec, &subcx.clone(), ~[]);
84-
}
85-
};
77+
pkg_src.build(&cx, ~[]);
8678
}
8779

8880
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
8981
main: Path) {
9082
let cx = default_context(sysroot);
91-
let subroot = root.clone();
92-
let submain = main.clone();
93-
do cx.workcache_context.with_prep(name) |prep| {
94-
let pkg_src = PkgSrc {
95-
workspace: subroot.clone(),
96-
start_dir: subroot.push("src").push(name),
97-
id: PkgId{ version: version.clone(), ..PkgId::new(name)},
98-
libs: ~[],
99-
mains: ~[mk_crate(submain.clone())],
100-
tests: ~[],
101-
benchs: ~[]
102-
};
103-
pkg_src.declare_inputs(prep);
104-
let subsrc = pkg_src.clone();
105-
let subcx = cx.clone();
106-
do prep.exec |exec| {
107-
subsrc.clone().build(exec, &subcx.clone(), ~[]);
108-
}
109-
}
83+
let pkg_src = PkgSrc {
84+
workspace: root.clone(),
85+
start_dir: root.push("src").push(name),
86+
id: PkgId{ version: version, ..PkgId::new(name)},
87+
libs: ~[],
88+
// n.b. This assumes the package only has one crate
89+
mains: ~[mk_crate(main)],
90+
tests: ~[],
91+
benchs: ~[]
92+
};
93+
94+
pkg_src.build(&cx, ~[]);
11095
}
11196

11297
pub fn install_pkg(sysroot: Path, workspace: Path, name: ~str, version: Version) {
11398
let cx = default_context(sysroot);
11499
let pkgid = PkgId{ version: version, ..PkgId::new(name)};
115-
cx.install(PkgSrc::new(workspace, false, pkgid));
100+
cx.install(PkgSrc::new(workspace, false, pkgid), &Everything);
116101
}
117102

118103
fn mk_crate(p: Path) -> Crate {

src/librustpkg/exit_codes.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub static copy_failed_code: int = 65;

src/librustpkg/package_id.rs

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ impl PkgId {
108108
}
109109
}
110110

111+
// This is the workcache function name for the *installed*
112+
// binaries for this package (as opposed to the built ones,
113+
// which are per-crate).
114+
pub fn install_tag(&self) -> ~str {
115+
fmt!("install(%s)", self.to_str())
116+
}
111117
}
112118

113119
struct Prefixes {

src/librustpkg/package_source.rs

+43-19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use path_util::{find_dir_using_rust_path_hack, default_workspace, make_dir_rwx_r
2222
use util::compile_crate;
2323
use workspace::is_workspace;
2424
use workcache_support;
25+
use workcache_support::crate_tag;
2526
use extra::workcache;
2627

2728
// An enumeration of the unpacked source of a package workspace.
@@ -231,7 +232,7 @@ impl PkgSrc {
231232
p.filestem().map_default(false, |p| { p == &self.id.short_name.as_slice() })
232233
}
233234

234-
fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
235+
pub fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
235236
assert!(p.components.len() > prefix);
236237
let mut sub = Path("");
237238
for c in p.components.slice(prefix, p.components.len()).iter() {
@@ -286,7 +287,6 @@ impl PkgSrc {
286287

287288
fn build_crates(&self,
288289
ctx: &BuildContext,
289-
exec: &mut workcache::Exec,
290290
destination_dir: &Path,
291291
crates: &[Crate],
292292
cfgs: &[~str],
@@ -297,25 +297,40 @@ impl PkgSrc {
297297
let path_str = path.to_str();
298298
let cfgs = crate.cfgs + cfgs;
299299

300-
let result =
301-
// compile_crate should return the path of the output artifact
302-
compile_crate(ctx,
303-
exec,
304-
&self.id,
305-
&path,
306-
destination_dir,
307-
crate.flags,
308-
cfgs,
309-
false,
310-
what).to_str();
311-
debug!("Result of compiling %s was %s", path_str, result);
300+
do ctx.workcache_context.with_prep(crate_tag(&path)) |prep| {
301+
debug!("Building crate %s, declaring it as an input", path.to_str());
302+
prep.declare_input("file", path.to_str(),
303+
workcache_support::digest_file_with_date(&path));
304+
let subpath = path.clone();
305+
let subcfgs = cfgs.clone();
306+
let subpath_str = path_str.clone();
307+
let subcx = ctx.clone();
308+
let id = self.id.clone();
309+
let sub_dir = destination_dir.clone();
310+
let sub_flags = crate.flags.clone();
311+
do prep.exec |exec| {
312+
let result = compile_crate(&subcx,
313+
exec,
314+
&id,
315+
&subpath,
316+
&sub_dir,
317+
sub_flags,
318+
subcfgs,
319+
false,
320+
what).to_str();
321+
debug!("Result of compiling %s was %s", subpath_str, result);
322+
result
323+
}
324+
};
312325
}
313326
}
314327

315328
/// Declare all the crate files in the package source as inputs
329+
/// (to the package)
316330
pub fn declare_inputs(&self, prep: &mut workcache::Prep) {
317331
let to_do = ~[self.libs.clone(), self.mains.clone(),
318332
self.tests.clone(), self.benchs.clone()];
333+
debug!("In declare inputs, self = %s", self.to_str());
319334
for cs in to_do.iter() {
320335
for c in cs.iter() {
321336
let path = self.start_dir.push_rel(&c.file).normalize();
@@ -330,7 +345,6 @@ impl PkgSrc {
330345
// It would be better if build returned a Path, but then Path would have to derive
331346
// Encodable.
332347
pub fn build(&self,
333-
exec: &mut workcache::Exec,
334348
build_context: &BuildContext,
335349
cfgs: ~[~str]) -> ~str {
336350
use conditions::not_a_workspace::cond;
@@ -360,13 +374,23 @@ impl PkgSrc {
360374
let benchs = self.benchs.clone();
361375
debug!("Building libs in %s, destination = %s",
362376
destination_workspace.to_str(), destination_workspace.to_str());
363-
self.build_crates(build_context, exec, &destination_workspace, libs, cfgs, Lib);
377+
self.build_crates(build_context, &destination_workspace, libs, cfgs, Lib);
364378
debug!("Building mains");
365-
self.build_crates(build_context, exec, &destination_workspace, mains, cfgs, Main);
379+
self.build_crates(build_context, &destination_workspace, mains, cfgs, Main);
366380
debug!("Building tests");
367-
self.build_crates(build_context, exec, &destination_workspace, tests, cfgs, Test);
381+
self.build_crates(build_context, &destination_workspace, tests, cfgs, Test);
368382
debug!("Building benches");
369-
self.build_crates(build_context, exec, &destination_workspace, benchs, cfgs, Bench);
383+
self.build_crates(build_context, &destination_workspace, benchs, cfgs, Bench);
370384
destination_workspace.to_str()
371385
}
386+
387+
/// Debugging
388+
pub fn dump_crates(&self) {
389+
let crate_sets = [&self.libs, &self.mains, &self.tests, &self.benchs];
390+
for crate_set in crate_sets.iter() {
391+
for c in crate_set.iter() {
392+
debug!("Built crate: %s", c.file.to_str())
393+
}
394+
}
395+
}
372396
}

0 commit comments

Comments
 (0)