17
17
18
18
#[license = "MIT/ASL2"];
19
19
#[crate_type = "lib"];
20
- #[allow(vecs_implicitly_copyable,
21
- non_implicitly_copyable_typarams)];
22
20
23
21
extern mod std(vers = "0.7-pre");
24
22
extern mod rustc(vers = "0.7-pre");
@@ -52,9 +50,9 @@ pub mod usage;
52
50
/// A PkgScript represents user-supplied custom logic for
53
51
/// special build hooks. This only exists for packages with
54
52
/// an explicit package script.
55
- struct PkgScript {
53
+ struct PkgScript<'self> {
56
54
/// Uniquely identifies this package
57
- id: PkgId,
55
+ id: &'self PkgId,
58
56
// Used to have this field: deps: ~[(~str, Option<~str>)]
59
57
// but I think it shouldn't be stored here
60
58
/// The contents of the package script: either a file path,
@@ -71,24 +69,24 @@ struct PkgScript {
71
69
build_dir: Path
72
70
}
73
71
74
- impl PkgScript {
72
+ impl<'self> PkgScript<'self> {
75
73
/// Given the path name for a package script
76
74
/// and a package ID, parse the package script into
77
75
/// a PkgScript that we can then execute
78
- fn parse(script: Path, workspace: &Path, id: PkgId) -> PkgScript {
76
+ fn parse<'a> (script: Path, workspace: &Path, id: &'a PkgId) -> PkgScript<'a> {
79
77
// Get the executable name that was invoked
80
- let binary = os::args()[0];
78
+ let binary = @copy os::args()[0];
81
79
// Build the rustc session data structures to pass
82
80
// to the compiler
83
81
let options = @session::options {
84
- binary: @ binary,
82
+ binary: binary,
85
83
crate_type: session::bin_crate,
86
- .. *session::basic_options()
84
+ .. copy *session::basic_options()
87
85
};
88
86
let input = driver::file_input(script);
89
87
let sess = driver::build_session(options, diagnostic::emit);
90
- let cfg = driver::build_configuration(sess, @ binary, &input);
91
- let (crate, _) = driver::compile_upto(sess, cfg, &input,
88
+ let cfg = driver::build_configuration(sess, binary, &input);
89
+ let (crate, _) = driver::compile_upto(sess, copy cfg, &input,
92
90
driver::cu_parse, None);
93
91
let work_dir = build_pkg_id_in_workspace(id, workspace);
94
92
@@ -123,10 +121,10 @@ impl PkgScript {
123
121
let root = r.pop().pop().pop().pop(); // :-\
124
122
debug!("Root is %s, calling compile_rest", root.to_str());
125
123
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
126
- util::compile_crate_from_input(self.input, self.id,
127
- Some(self.build_dir),
124
+ util::compile_crate_from_input(& self.input, self.id,
125
+ Some(copy self.build_dir),
128
126
sess, Some(crate),
129
- exe, os::args()[0],
127
+ & exe, @copy os::args()[0],
130
128
driver::cu_everything);
131
129
debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what);
132
130
let status = run::run_program(exe.to_str(), ~[root.to_str(), what]);
@@ -188,9 +186,9 @@ impl Ctx {
188
186
}
189
187
// The package id is presumed to be the first command-line
190
188
// argument
191
- let pkgid = PkgId::new(args[0]);
192
- for pkg_parent_workspaces(pkgid) |workspace| {
193
- self.build(workspace, pkgid);
189
+ let pkgid = PkgId::new(copy args[0]);
190
+ for pkg_parent_workspaces(& pkgid) |workspace| {
191
+ self.build(workspace, & pkgid);
194
192
}
195
193
}
196
194
~"clean" => {
@@ -199,16 +197,16 @@ impl Ctx {
199
197
}
200
198
// The package id is presumed to be the first command-line
201
199
// argument
202
- let pkgid = PkgId::new(args[0]);
200
+ let pkgid = PkgId::new(copy args[0]);
203
201
let cwd = os::getcwd();
204
- self.clean(&cwd, pkgid); // tjc: should use workspace, not cwd
202
+ self.clean(&cwd, & pkgid); // tjc: should use workspace, not cwd
205
203
}
206
204
~"do" => {
207
205
if args.len() < 2 {
208
206
return usage::do_cmd();
209
207
}
210
208
211
- self.do_cmd(args[0], args[1]);
209
+ self.do_cmd(copy args[0], copy args[1]);
212
210
}
213
211
~"info" => {
214
212
self.info();
@@ -221,16 +219,16 @@ impl Ctx {
221
219
// The package id is presumed to be the first command-line
222
220
// argument
223
221
let pkgid = PkgId::new(args[0]);
224
- for pkg_parent_workspaces(pkgid) |workspace| {
225
- self.install(workspace, pkgid);
222
+ for pkg_parent_workspaces(& pkgid) |workspace| {
223
+ self.install(workspace, & pkgid);
226
224
}
227
225
}
228
226
~"prefer" => {
229
227
if args.len() < 1 {
230
228
return usage::uninstall();
231
229
}
232
230
233
- let (name, vers) = sep_name_vers(args[0]);
231
+ let (name, vers) = sep_name_vers(copy args[0]);
234
232
235
233
self.prefer(name.get(), vers);
236
234
}
@@ -242,7 +240,7 @@ impl Ctx {
242
240
return usage::uninstall();
243
241
}
244
242
245
- let (name, vers) = sep_name_vers(args[0]);
243
+ let (name, vers) = sep_name_vers(copy args[0]);
246
244
247
245
self.uninstall(name.get(), vers);
248
246
}
@@ -251,26 +249,26 @@ impl Ctx {
251
249
return usage::uninstall();
252
250
}
253
251
254
- let (name, vers) = sep_name_vers(args[0]);
252
+ let (name, vers) = sep_name_vers(copy args[0]);
255
253
256
254
self.unprefer(name.get(), vers);
257
255
}
258
256
_ => fail!("reached an unhandled command")
259
257
}
260
258
}
261
259
262
- fn do_cmd(&self, _cmd: ~ str, _pkgname: ~ str) {
260
+ fn do_cmd(&self, _cmd: & str, _pkgname: & str) {
263
261
// stub
264
262
fail!("`do` not yet implemented");
265
263
}
266
264
267
- fn build(&self, workspace: &Path, pkgid: PkgId) {
265
+ fn build(&self, workspace: &Path, pkgid: & PkgId) {
268
266
let src_dir = pkgid_src_in_workspace(pkgid, workspace);
269
267
let build_dir = build_pkg_id_in_workspace(pkgid, workspace);
270
268
debug!("Destination dir = %s", build_dir.to_str());
271
269
272
270
// Create the package source
273
- let mut src = PkgSrc::new(&workspace.push("src"), &build_dir, & pkgid);
271
+ let mut src = PkgSrc::new(&workspace.push("src"), &build_dir, pkgid);
274
272
debug!("Package src = %?", src);
275
273
276
274
// Is there custom build logic? If so, use it
@@ -311,7 +309,7 @@ impl Ctx {
311
309
312
310
}
313
311
314
- fn clean(&self, workspace: &Path, id: PkgId) {
312
+ fn clean(&self, workspace: &Path, id: & PkgId) {
315
313
// Could also support a custom build hook in the pkg
316
314
// script for cleaning files rustpkg doesn't know about.
317
315
// Do something reasonable for now
@@ -332,7 +330,7 @@ impl Ctx {
332
330
fail!("info not yet implemented");
333
331
}
334
332
335
- fn install(&self, workspace: &Path, id: PkgId) {
333
+ fn install(&self, workspace: &Path, id: & PkgId) {
336
334
use conditions::copy_failed::cond;
337
335
338
336
// Should use RUST_PATH in the future.
@@ -348,13 +346,13 @@ impl Ctx {
348
346
for maybe_executable.each |exec| {
349
347
debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str());
350
348
if !os::copy_file(exec, &target_exec) {
351
- cond.raise((*exec, target_exec));
349
+ cond.raise((copy *exec, copy target_exec));
352
350
}
353
351
}
354
352
for maybe_library.each |lib| {
355
353
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
356
354
if !os::copy_file(lib, &target_lib) {
357
- cond.raise((*lib, target_lib));
355
+ cond.raise((copy *lib, copy target_lib));
358
356
}
359
357
}
360
358
}
@@ -387,7 +385,7 @@ impl Ctx {
387
385
}
388
386
}
389
387
390
- fn fetch_git(&self, dir: &Path, url: ~str, target: Option<~str>) {
388
+ fn fetch_git(&self, dir: &Path, url: ~str, mut target: Option<~str>) {
391
389
util::note(fmt!("fetching from %s using git", url));
392
390
393
391
// Git can't clone into a non-empty directory
@@ -405,7 +403,7 @@ impl Ctx {
405
403
do util::temp_change_dir(dir) {
406
404
success = run::program_output(~"git",
407
405
~[~"checkout",
408
- target.get ()]).status != 0
406
+ target.swap_unwrap ()]).status != 0
409
407
}
410
408
411
409
if !success {
@@ -525,7 +523,7 @@ pub struct Listener {
525
523
}
526
524
527
525
pub fn run(listeners: ~[Listener]) {
528
- let rcmd = os::args()[2];
526
+ let rcmd = copy os::args()[2];
529
527
let mut found = false;
530
528
531
529
for listeners.each |listener| {
@@ -652,12 +650,12 @@ impl PkgSrc {
652
650
// tjc: Rather than erroring out, need to try downloading the
653
651
// contents of the path to a local directory (#5679)
654
652
if !os::path_exists(&dir) {
655
- cond.raise((self.id, ~"missing package dir"));
653
+ cond.raise((copy self.id, ~"missing package dir"));
656
654
}
657
655
658
656
if !os::path_is_dir(&dir) {
659
- cond.raise((self.id, ~"supplied path for package dir is a \
660
- non-directory"));
657
+ cond.raise((copy self.id, ~"supplied path for package dir is a \
658
+ non-directory"));
661
659
}
662
660
663
661
dir
@@ -681,7 +679,7 @@ impl PkgSrc {
681
679
/// Requires that dashes in p have already been normalized to
682
680
/// underscores
683
681
fn stem_matches(&self, p: &Path) -> bool {
684
- let self_id = normalize(~self.id.path).filestem();
682
+ let self_id = normalize(~copy self.id.path).filestem();
685
683
if self_id == p.filestem() {
686
684
return true;
687
685
}
@@ -737,7 +735,7 @@ impl PkgSrc {
737
735
util::note(~"Couldn't infer any crates to build.\n\
738
736
Try naming a crate `main.rs`, `lib.rs`, \
739
737
`test.rs`, or `bench.rs`.");
740
- cond.raise(self.id);
738
+ cond.raise(copy self.id);
741
739
}
742
740
743
741
debug!("found %u libs, %u mains, %u tests, %u benchs",
@@ -752,15 +750,15 @@ impl PkgSrc {
752
750
dst_dir: &Path,
753
751
src_dir: &Path,
754
752
crates: &[Crate],
755
- cfgs: ~ [~str],
753
+ cfgs: & [~str],
756
754
test: bool, crate_type: crate_type) {
757
755
758
756
for crates.each |&crate| {
759
757
let path = &src_dir.push_rel(&crate.file).normalize();
760
758
util::note(fmt!("build_crates: compiling %s", path.to_str()));
761
759
util::note(fmt!("build_crates: destination dir is %s", dst_dir.to_str()));
762
760
763
- let result = util::compile_crate(maybe_sysroot, self.id, path,
761
+ let result = util::compile_crate(maybe_sysroot, & self.id, path,
764
762
dst_dir,
765
763
crate.flags,
766
764
crate.cfgs + cfgs,
0 commit comments