Skip to content

Commit 021e636

Browse files
graydoncatamorphism
authored andcommitted
---
yaml --- r: 71801 b: refs/heads/dist-snap c: e0f72e2 h: refs/heads/master i: 71799: 413b9d0 v: v3
1 parent aec3c0c commit 021e636

File tree

3 files changed

+201
-69
lines changed

3 files changed

+201
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: d6f455ebca79b6a3d374158a047b1cdd744ebc5e
10+
refs/heads/dist-snap: e0f72e22985d0d39707f7741c0b63002889c457a
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustpkg/rustpkg.rc

Lines changed: 174 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,13 @@ impl Ctx {
281281

282282
match cmd {
283283
~"build" => {
284-
self.build(&os::getcwd(), true, false, false);
284+
if args.len() < 1 {
285+
return usage::build();
286+
}
287+
let pkgid = PkgId::new(args[0]);
288+
let mut src = PkgSrc::new(&Path("."), &pkgid);
289+
src.find_crates();
290+
src.build(&Path("."));
285291
}
286292
~"clean" => {
287293
self.clean();
@@ -927,7 +933,7 @@ pub fn main() {
927933

928934
/// A crate is a unit of Rust code to be compiled into a binary or library
929935
pub struct Crate {
930-
file: ~str,
936+
file: Path,
931937
flags: ~[~str],
932938
cfgs: ~[~str]
933939
}
@@ -959,44 +965,44 @@ pub fn run(listeners: ~[Listener]) {
959965
}
960966

961967
pub impl Crate {
962-
pub fn flag(&self, flag: ~str) -> Crate {
968+
969+
static fn new(p: &Path) -> Crate {
970+
Crate {
971+
file: copy *p,
972+
flags: ~[],
973+
cfgs: ~[]
974+
}
975+
}
976+
977+
fn flag(&self, flag: ~str) -> Crate {
963978
Crate {
964979
flags: vec::append(copy self.flags, ~[flag]),
965980
.. copy *self
966981
}
967982
}
968983

969-
pub fn flags(&self, flags: ~[~str]) -> Crate {
984+
fn flags(&self, flags: ~[~str]) -> Crate {
970985
Crate {
971986
flags: vec::append(copy self.flags, flags),
972987
.. copy *self
973988
}
974989
}
975990

976-
pub fn cfg(&self, cfg: ~str) -> Crate {
991+
fn cfg(&self, cfg: ~str) -> Crate {
977992
Crate {
978993
cfgs: vec::append(copy self.cfgs, ~[cfg]),
979994
.. copy *self
980995
}
981996
}
982997

983-
pub fn cfgs(&self, cfgs: ~[~str]) -> Crate {
998+
fn cfgs(&self, cfgs: ~[~str]) -> Crate {
984999
Crate {
9851000
cfgs: vec::append(copy self.cfgs, cfgs),
9861001
.. copy *self
9871002
}
9881003
}
9891004
}
9901005

991-
/// Create a crate target from a source file
992-
pub fn Crate(file: ~str) -> Crate {
993-
Crate {
994-
file: file,
995-
flags: ~[],
996-
cfgs: ~[]
997-
}
998-
}
999-
10001006
/**
10011007
* Get the working directory of the package script.
10021008
* Assumes that the package script has been compiled
@@ -1026,7 +1032,7 @@ pub fn build(crates: ~[Crate]) -> bool {
10261032
let test = args[3] == ~"true";
10271033

10281034
for crates.each |&crate| {
1029-
let path = &dir.push_rel(&Path(crate.file)).normalize();
1035+
let path = &dir.push_rel(&crate.file).normalize();
10301036

10311037
util::note(fmt!("compiling %s", path.to_str()));
10321038

@@ -1043,3 +1049,155 @@ pub fn build(crates: ~[Crate]) -> bool {
10431049

10441050
success
10451051
}
1052+
1053+
1054+
// Path-fragment identifier of a package such as
1055+
// 'github.com/graydon/test'; must be a relative
1056+
// path with >=1 component.
1057+
struct PkgId {
1058+
path: Path
1059+
}
1060+
1061+
condition! {
1062+
bad_pkg_id: (::core::path::Path, ~str) -> ::PkgId;
1063+
}
1064+
1065+
impl PkgId {
1066+
static fn new(s: &str) -> PkgId {
1067+
use bad_pkg_id::cond;
1068+
1069+
let p = Path(s);
1070+
if p.is_absolute {
1071+
return cond.raise((p, ~"absolute pkgid"));
1072+
}
1073+
if p.components.len() < 1 {
1074+
return cond.raise((p, ~"0-length pkgid"));
1075+
}
1076+
PkgId {
1077+
path: p
1078+
}
1079+
}
1080+
}
1081+
1082+
1083+
// An enumeration of the unpacked source of a package workspace.
1084+
// This contains a list of files found in the source workspace.
1085+
pub struct PkgSrc {
1086+
root: Path,
1087+
id: PkgId,
1088+
libs: ~[Crate],
1089+
mains: ~[Crate],
1090+
tests: ~[Crate],
1091+
benchs: ~[Crate],
1092+
}
1093+
1094+
condition! {
1095+
bad_path: (::core::path::Path, ~str) -> ::core::path::Path;
1096+
}
1097+
1098+
condition! {
1099+
build_err: (~str) -> ();
1100+
}
1101+
1102+
impl PkgSrc {
1103+
1104+
1105+
static fn new(fs_root: &Path, id: &PkgId) -> PkgSrc {
1106+
PkgSrc {
1107+
root: copy *fs_root,
1108+
id: copy *id,
1109+
libs: ~[],
1110+
mains: ~[],
1111+
tests: ~[],
1112+
benchs: ~[]
1113+
}
1114+
}
1115+
1116+
1117+
fn check_dir(&self) -> Path {
1118+
use bad_path::cond;
1119+
1120+
let dir = self.root.push_rel(&self.id.path).normalize();
1121+
1122+
if ! os::path_exists(&dir) {
1123+
return cond.raise((dir, ~"missing package dir"));
1124+
}
1125+
1126+
if ! os::path_is_dir(&dir) {
1127+
return cond.raise((dir, ~"missing package dir"));
1128+
}
1129+
1130+
dir
1131+
}
1132+
1133+
1134+
fn has_pkg_file(&self) -> bool {
1135+
let dir = self.check_dir();
1136+
dir.push("pkg.rs").exists()
1137+
}
1138+
1139+
1140+
static fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
1141+
assert p.components.len() > prefix;
1142+
let mut sub = Path("");
1143+
for vec::slice(p.components, prefix,
1144+
p.components.len()).each |c| {
1145+
sub = sub.push(*c);
1146+
}
1147+
debug!("found crate %s", sub.to_str());
1148+
cs.push(Crate::new(&sub));
1149+
}
1150+
1151+
fn find_crates(&mut self) {
1152+
use PkgSrc::push_crate;
1153+
assert ! self.has_pkg_file();
1154+
let dir = self.check_dir();
1155+
let prefix = dir.components.len();
1156+
for os::walk_dir(&dir) |pth| {
1157+
match pth.filename() {
1158+
Some(~"lib.rs") => push_crate(&mut self.libs,
1159+
prefix, pth),
1160+
Some(~"main.rs") => push_crate(&mut self.mains,
1161+
prefix, pth),
1162+
Some(~"test.rs") => push_crate(&mut self.tests,
1163+
prefix, pth),
1164+
Some(~"bench.rs") => push_crate(&mut self.benchs,
1165+
prefix, pth),
1166+
_ => ()
1167+
}
1168+
}
1169+
debug!("found %u libs, %u mains, %u tests, %u benchs",
1170+
self.libs.len(),
1171+
self.mains.len(),
1172+
self.tests.len(),
1173+
self.benchs.len())
1174+
}
1175+
1176+
1177+
static fn build_crates(dst_dir: &Path,
1178+
src_dir: &Path,
1179+
crates: &[Crate],
1180+
test: bool) {
1181+
1182+
for crates.each |&crate| {
1183+
let path = &src_dir.push_rel(&crate.file).normalize();
1184+
util::note(fmt!("compiling %s", path.to_str()));
1185+
if ! util::compile_crate(None, path,
1186+
dst_dir,
1187+
crate.flags,
1188+
crate.cfgs,
1189+
false, test) {
1190+
build_err::cond.raise(fmt!("build failure on %s",
1191+
path.to_str()));
1192+
}
1193+
}
1194+
}
1195+
1196+
fn build(&self, dst_dir: &Path) {
1197+
let dir = self.check_dir();
1198+
PkgSrc::build_crates(dst_dir, &dir, self.libs, false);
1199+
PkgSrc::build_crates(dst_dir, &dir, self.mains, false);
1200+
PkgSrc::build_crates(dst_dir, &dir, self.tests, true);
1201+
PkgSrc::build_crates(dst_dir, &dir, self.benchs, true);
1202+
}
1203+
}

0 commit comments

Comments
 (0)