Skip to content

Commit 0040b2e

Browse files
z0w0graydon
authored andcommitted
---
yaml --- r: 44515 b: refs/heads/master c: 7079441 h: refs/heads/master i: 44513: 623732b 44511: 10cce4a v: v3
1 parent c880ed3 commit 0040b2e

File tree

6 files changed

+812
-282
lines changed

6 files changed

+812
-282
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bd28fa4af5b5200b274b8e965a422174fb7ad354
2+
refs/heads/master: 707944184304acbd81c026156a04b98570c6ef9c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/librustc/driver/driver.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ pub enum compile_upto {
184184
cu_everything,
185185
}
186186

187-
pub fn compile_upto(sess: Session, cfg: ast::crate_cfg,
188-
input: input, upto: compile_upto,
189-
outputs: Option<output_filenames>)
190-
-> {crate: @ast::crate, tcx: Option<ty::ctxt>} {
187+
// For continuing compilation after a parsed crate has been
188+
// modified
189+
pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
190+
upto: compile_upto, outputs: Option<output_filenames>,
191+
curr: Option<@ast::crate>)
192+
-> {crate: @ast::crate, tcx: Option<ty::ctxt>} {
191193
let time_passes = sess.time_passes();
192-
let mut crate = time(time_passes, ~"parsing",
193-
|| parse_input(sess, copy cfg, input) );
194-
if upto == cu_parse { return {crate: crate, tcx: None}; }
194+
let mut crate = curr.get();
195195

196196
*sess.building_library = session::building_library(
197197
sess.opts.crate_type, crate, sess.opts.test);
@@ -322,7 +322,6 @@ pub fn compile_upto(sess: Session, cfg: ast::crate_cfg,
322322

323323
};
324324

325-
326325
time(time_passes, ~"LLVM passes", ||
327326
link::write::run_passes(sess, llmod,
328327
&outputs.obj_filename));
@@ -342,9 +341,20 @@ pub fn compile_upto(sess: Session, cfg: ast::crate_cfg,
342341
return {crate: crate, tcx: None};
343342
}
344343

344+
pub fn compile_upto(sess: Session, +cfg: ast::crate_cfg,
345+
input: input, upto: compile_upto,
346+
outputs: Option<output_filenames>)
347+
-> {crate: @ast::crate, tcx: Option<ty::ctxt>} {
348+
let time_passes = sess.time_passes();
349+
let mut crate = time(time_passes, ~"parsing",
350+
|| parse_input(sess, copy cfg, input) );
351+
if upto == cu_parse { return {crate: crate, tcx: None}; }
352+
353+
compile_rest(sess, cfg, upto, outputs, Some(crate))
354+
}
355+
345356
pub fn compile_input(sess: Session, +cfg: ast::crate_cfg, input: input,
346357
outdir: &Option<Path>, output: &Option<Path>) {
347-
348358
let upto = if sess.opts.parse_only { cu_parse }
349359
else if sess.opts.no_trans { cu_no_trans }
350360
else { cu_everything };

trunk/src/librustpkg/api.rs

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,130 @@
1+
// Copyright 2012 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+
111
use core::*;
12+
use util::{compile_crate, note};
213

14+
/// A crate is a unit of Rust code to be compiled into a binary or library
315
pub struct Crate {
416
file: ~str,
517
flags: ~[~str],
6-
cfg: ~[~str]
18+
cfgs: ~[~str]
19+
}
20+
21+
pub struct Listener {
22+
cmd: ~str,
23+
cb: fn~()
24+
}
25+
26+
pub fn run(listeners: ~[Listener]) {
27+
io::println(src_dir().to_str());
28+
io::println(work_dir().to_str());
29+
30+
let cmd = os::args()[1];
31+
32+
for listeners.each |listener| {
33+
if listener.cmd == cmd {
34+
(listener.cb)();
35+
}
36+
}
737
}
838

939
pub impl Crate {
10-
fn flag(flag: ~str) -> Crate {
40+
fn flag(flag: ~str) -> Crate {
1141
Crate {
1242
flags: vec::append(copy self.flags, ~[flag]),
1343
.. copy self
1444
}
1545
}
46+
47+
fn flags(flags: ~[~str]) -> Crate {
48+
Crate {
49+
flags: vec::append(copy self.flags, flags),
50+
.. copy self
51+
}
52+
}
53+
54+
fn cfg(cfg: ~str) -> Crate {
55+
Crate {
56+
cfgs: vec::append(copy self.cfgs, ~[cfg]),
57+
.. copy self
58+
}
59+
}
60+
61+
fn cfgs(cfgs: ~[~str]) -> Crate {
62+
Crate {
63+
cfgs: vec::append(copy self.cfgs, cfgs),
64+
.. copy self
65+
}
66+
}
67+
}
68+
69+
/// Create a crate target from a source file
70+
pub fn Crate(file: ~str) -> Crate {
71+
Crate {
72+
file: file,
73+
flags: ~[],
74+
cfgs: ~[]
75+
}
1676
}
1777

18-
pub fn build(_targets: ~[Crate]) {
19-
// TODO: magic
78+
/**
79+
* Get the working directory of the package script.
80+
* Assumes that the package script has been compiled
81+
* in is the working directory.
82+
*/
83+
fn work_dir() -> Path {
84+
os::self_exe_path().get()
85+
}
86+
87+
/**
88+
* Get the source directory of the package (i.e.
89+
* where the crates are located). Assumes
90+
* that the cwd is changed to it before
91+
* running this executable.
92+
*/
93+
fn src_dir() -> Path {
94+
os::getcwd()
95+
}
96+
97+
pub fn args() -> ~[~str] {
98+
let mut args = os::args();
99+
100+
args.shift();
101+
args.shift();
102+
103+
args
104+
}
105+
106+
/// Build a set of crates, should be called once
107+
pub fn build(crates: ~[Crate]) -> bool {
108+
let dir = src_dir();
109+
let work_dir = work_dir();
110+
let mut success = true;
111+
112+
for crates.each |&crate| {
113+
let path = &dir.push_rel(&Path(crate.file)).normalize();
114+
115+
note(fmt!("compiling %s", path.to_str()));
116+
117+
success = compile_crate(path, &work_dir, crate.flags, crate.cfgs,
118+
false, false);
119+
120+
if !success { break; }
121+
}
122+
123+
os::set_exit_status(101);
124+
125+
success
20126
}
21127

22128
pub mod util {
23-
129+
// TODO: utilities for working with things like autotools
24130
}

0 commit comments

Comments
 (0)