Skip to content

Commit 48cf742

Browse files
z0w0graydon
authored andcommitted
---
yaml --- r: 47015 b: refs/heads/try c: 220144b h: refs/heads/master i: 47013: ba6d297 47011: 7efb714 47007: 2737d6b v: v3
1 parent 4a8e6f7 commit 48cf742

File tree

3 files changed

+285
-29
lines changed

3 files changed

+285
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
5-
refs/heads/try: 226b61ba5f30e0ecb0799626a010161f3ce0b72d
5+
refs/heads/try: 220144b93cdb057cc43fa7bdcfdfbdd42bbf7cf1
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustpkg/rustpkg.rc

Lines changed: 243 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ mod util;
3939
struct PackageScript {
4040
id: ~str,
4141
name: ~str,
42-
vers: Version
42+
vers: Version,
43+
crates: ~[~str],
44+
deps: ~[(~str, Option<~str>)]
4345
}
4446

4547
impl PackageScript {
@@ -54,6 +56,8 @@ impl PackageScript {
5456
let crate = parse::parse_crate_from_file(&script, ~[], sess);
5557
let mut id = None;
5658
let mut vers = None;
59+
let mut crates = ~[];
60+
let mut deps = ~[];
5761

5862
fn load_pkg_attr(mis: ~[@ast::meta_item]) -> (Option<~str>,
5963
Option<~str>) {
@@ -78,6 +82,49 @@ impl PackageScript {
7882
(id, vers)
7983
}
8084

85+
fn load_pkg_dep_attr(mis: ~[@ast::meta_item]) -> (Option<~str>,
86+
Option<~str>) {
87+
let mut url = None;
88+
let mut target = None;
89+
90+
for mis.each |a| {
91+
match a.node {
92+
ast::meta_name_value(v, ast::spanned {
93+
node: ast::lit_str(s),
94+
span: _}) => {
95+
match v {
96+
~"url" => url = Some(*s),
97+
~"target" => target = Some(*s),
98+
_ => ()
99+
}
100+
}
101+
_ => {}
102+
}
103+
}
104+
105+
(url, target)
106+
}
107+
108+
fn load_pkg_crate_attr(mis: ~[@ast::meta_item]) -> Option<~str> {
109+
let mut file = None;
110+
111+
for mis.each |a| {
112+
match a.node {
113+
ast::meta_name_value(v, ast::spanned {
114+
node: ast::lit_str(s),
115+
span: _}) => {
116+
match v {
117+
~"file" => file = Some(*s),
118+
_ => ()
119+
}
120+
}
121+
_ => {}
122+
}
123+
}
124+
125+
file
126+
}
127+
81128
for crate.node.attrs.each |a| {
82129
match a.node.value.node {
83130
ast::meta_list(v, mis) => {
@@ -88,6 +135,24 @@ impl PackageScript {
88135
id = i;
89136
vers = v;
90137
}
138+
~"pkg_dep" => {
139+
let (u, t) = load_pkg_dep_attr(mis);
140+
141+
if u.is_none() {
142+
fail ~"pkg_dep attr without a url value";
143+
}
144+
145+
deps.push((u.get(), t));
146+
}
147+
~"pkg_crate" => {
148+
let f = load_pkg_crate_attr(mis);
149+
150+
if f.is_none() {
151+
fail ~"pkg_file attr without a file value";
152+
}
153+
154+
crates.push(f.get());
155+
}
91156
_ => {}
92157
}
93158
}
@@ -105,7 +170,9 @@ impl PackageScript {
105170
PackageScript {
106171
id: id,
107172
name: util::parse_id(id),
108-
vers: util::parse_vers(vers)
173+
vers: util::parse_vers(vers),
174+
crates: crates,
175+
deps: deps
109176
}
110177
}
111178

@@ -114,63 +181,214 @@ impl PackageScript {
114181

115182
hasher.write_str(self.id + self.vers.to_str());
116183

117-
self.name + hasher.result_str() + self.vers.to_str()
184+
fmt!("%s-%s-%s", self.name, hasher.result_str(), self.vers.to_str())
118185
}
119186

120187
fn work_dir() -> Path {
121-
util::root().push(self.hash())
188+
util::root().push(~"work").push(self.hash())
122189
}
123190
}
124191

125192
struct Ctx {
126-
cmd: ~str,
127-
args: ~[~str],
128193
cfgs: ~[~str],
129194
prefer: bool
130195
}
131196

132197
impl Ctx {
133-
fn run() {
134-
match self.cmd {
135-
~"build" => self.build(),
136-
~"clean" => self.clean(),
137-
~"install" => self.install(),
138-
~"prefer" => self.prefer(),
139-
~"test" => self.test(),
140-
~"uninstall" => self.uninstall(),
141-
~"unprefer" => self.unprefer(),
198+
fn run(cmd: ~str, args: ~[~str]) {
199+
let root = util::root();
200+
201+
util::need_dir(&root);
202+
util::need_dir(&root.push(~"work"));
203+
util::need_dir(&root.push(~"lib"));
204+
util::need_dir(&root.push(~"bin"));
205+
util::need_dir(&root.push(~"tmp"));
206+
207+
match cmd {
208+
~"build" => self.build(args),
209+
~"clean" => self.clean(args),
210+
~"install" => self.install(args),
211+
~"prefer" => self.prefer(args),
212+
~"test" => self.test(args),
213+
~"uninstall" => self.uninstall(args),
214+
~"unprefer" => self.unprefer(args),
142215
_ => fail ~"reached an unhandled command"
143-
}
216+
};
144217
}
145218

146-
fn build() {
219+
fn build(_args: ~[~str]) -> bool {
147220
let script = PackageScript::parse(os::getcwd());
221+
let dir = script.work_dir();
222+
let mut success = true;
223+
224+
util::need_dir(&dir);
225+
util::info(fmt!("building %s v%s (%s)", script.name, script.vers.to_str(),
226+
script.id));
227+
228+
if script.deps.len() >= 1 {
229+
util::info(~"installing dependencies..");
230+
231+
for script.deps.each |&dep| {
232+
let (url, target) = dep;
233+
234+
success = self.install(if target.is_none() { ~[url] }
235+
else { ~[url, target.get()] });
236+
237+
if !success { break; }
238+
}
239+
240+
if !success {
241+
util::error(fmt!("building %s v%s failed: a dep wasn't installed",
242+
script.name, script.vers.to_str()));
243+
244+
return false;
245+
}
246+
247+
util::info(~"installed dependencies");
248+
}
249+
250+
for script.crates.each |&crate| {
251+
success = self.compile(&dir, crate, ~[]);
252+
253+
if !success { break; }
254+
}
255+
256+
if !success {
257+
util::error(fmt!("building %s v%s failed: a crate failed to compile",
258+
script.name, script.vers.to_str()));
259+
260+
return false;
261+
}
148262

149-
io::println(fmt!("build: %s (v%s)", script.id, script.vers.to_str()));
263+
util::info(fmt!("built %s v%s", script.name, script.vers.to_str()));
264+
265+
true
150266
}
151267

152-
fn clean() {
268+
fn compile(dir: &Path, crate: ~str, flags: ~[~str]) -> bool {
269+
util::info(~"compiling " + crate);
153270

271+
true
154272
}
155273

156-
fn install() {
274+
fn clean(_args: ~[~str]) -> bool {
275+
let script = PackageScript::parse(os::getcwd());
276+
let dir = script.work_dir();
277+
278+
util::info(fmt!("cleaning %s v%s (%s)", script.name, script.vers.to_str(),
279+
script.id));
280+
281+
if os::path_is_dir(&dir) {
282+
if os::remove_dir(&dir) {
283+
util::info(fmt!("cleaned %s v%s", script.name,
284+
script.vers.to_str()));
285+
} else {
286+
util::error(fmt!("cleaning %s v%s failed",
287+
script.name, script.vers.to_str()));
288+
}
289+
} else {
290+
util::info(fmt!("cleaned %s v%s", script.name,
291+
script.vers.to_str()));
292+
}
157293

294+
true
158295
}
159296

160-
fn prefer() {
297+
fn install(args: ~[~str]) -> bool {
298+
let mut success;
299+
let mut dir;
300+
301+
if args.len() < 1 {
302+
util::info(~"installing from the cwd");
303+
304+
dir = os::getcwd();
305+
306+
return true;
307+
} else {
308+
let url = args[0];
309+
let target = if args.len() >= 2 { Some(args[1]) }
310+
else { None };
311+
let hasher = hash::default_state();
312+
313+
hasher.write_str(url);
314+
315+
if !target.is_none() {
316+
hasher.write_str(target.get());
317+
}
318+
319+
dir = util::root().push(~"tmp").push(hasher.result_str());
320+
success = self.fetch(&dir, url, target);
161321

322+
if !success {
323+
return false;
324+
}
325+
}
326+
327+
let script = PackageScript::parse(dir);
328+
dir = script.work_dir();
329+
330+
util::info(fmt!("installing %s v%s (%s)", script.name, script.vers.to_str(),
331+
script.id));
332+
333+
if script.deps.len() >= 1 {
334+
util::info(~"installing dependencies..");
335+
336+
for script.deps.each |&dep| {
337+
let (url, target) = dep;
338+
339+
success = self.install(if target.is_none() { ~[url] }
340+
else { ~[url, target.get()] });
341+
342+
if !success { break; }
343+
}
344+
345+
if !success {
346+
util::error(fmt!("installing %s v%s failed: a dep wasn't installed",
347+
script.name, script.vers.to_str()));
348+
return false;
349+
}
350+
351+
util::info(~"installed dependencies");
352+
}
353+
354+
for script.crates.each |&crate| {
355+
success = self.compile(&dir, crate, ~[]);
356+
357+
if !success { break; }
358+
}
359+
360+
if !success {
361+
util::error(fmt!("installing %s v%s failed: a crate failed to compile",
362+
script.name, script.vers.to_str()));
363+
return false;
364+
}
365+
366+
util::info(fmt!("installed %s v%s", script.name,
367+
script.vers.to_str()));
368+
369+
true
162370
}
163371

164-
fn test() {
372+
fn fetch(dir: &Path, url: ~str, target: Option<~str>) -> bool {
373+
util::info(fmt!("installing from %s", url));
165374

375+
true
166376
}
167377

168-
fn uninstall() {
378+
fn prefer(_args: ~[~str]) -> bool {
379+
true
380+
}
169381

382+
fn test(_args: ~[~str]) -> bool {
383+
true
170384
}
171385

172-
fn unprefer() {
386+
fn uninstall(_args: ~[~str]) -> bool {
387+
true
388+
}
173389

390+
fn unprefer(_args: ~[~str]) -> bool {
391+
true
174392
}
175393
}
176394

@@ -217,11 +435,9 @@ pub fn main() {
217435
}
218436

219437
Ctx {
220-
cmd: cmd,
221-
args: args,
222438
cfgs: cfgs,
223439
prefer: prefer
224-
}.run();
440+
}.run(cmd, args);
225441
}
226442

227443
pub use Crate = api::Crate;

0 commit comments

Comments
 (0)