Skip to content

Commit e00bebd

Browse files
committed
---
yaml --- r: 140786 b: refs/heads/try2 c: 9f104d4 h: refs/heads/master v: v3
1 parent 59354c3 commit e00bebd

File tree

5 files changed

+99
-106
lines changed

5 files changed

+99
-106
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 27c228fad7d94a500866696f8c48ef1707a2507b
8+
refs/heads/try2: 9f104d4213ae31f4e61b210ef34b223c81c8c3af
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustpkg/path_util.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ pub fn normalize(p: ~Path) -> ~Path {
5555

5656
/// True if there's a directory in <workspace> with
5757
/// pkgid's short name
58-
pub fn workspace_contains_package_id(pkgid: PkgId, workspace: &Path) -> bool {
58+
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
5959
let pkgpath = workspace.push("src").push(pkgid.path.to_str());
6060
os::path_is_dir(&pkgpath)
6161
}
6262

6363
/// Return the directory for <pkgid>'s source files in <workspace>.
6464
/// Doesn't check that it exists.
65-
pub fn pkgid_src_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
65+
pub fn pkgid_src_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
6666
let result = workspace.push("src");
6767
result.push(pkgid.path.to_str())
6868
}
6969

7070
/// Figure out what the executable name for <pkgid> in <workspace>'s build
7171
/// directory is, and if the file exists, return it.
72-
pub fn built_executable_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path> {
72+
pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
7373
let mut result = workspace.push("build");
7474
result = result.push_rel(&pkgid.path);
7575
// should use a target-specific subdirectory
@@ -87,7 +87,7 @@ pub fn built_executable_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<P
8787

8888
/// Figure out what the library name for <pkgid> in <workspace>'s build
8989
/// directory is, and if the file exists, return it.
90-
pub fn built_library_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path> {
90+
pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
9191
let mut result = workspace.push("build");
9292
result = result.push_rel(&pkgid.path);
9393
// should use a target-specific subdirectory
@@ -159,31 +159,31 @@ pub fn built_library_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path
159159
/// Returns the executable that would be installed for <pkgid>
160160
/// in <workspace>
161161
/// As a side effect, creates the bin-dir if it doesn't exist
162-
pub fn target_executable_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
162+
pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
163163
target_file_in_workspace(pkgid, workspace, Main)
164164
}
165165

166166

167167
/// Returns the executable that would be installed for <pkgid>
168168
/// in <workspace>
169169
/// As a side effect, creates the bin-dir if it doesn't exist
170-
pub fn target_library_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
170+
pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
171171
target_file_in_workspace(pkgid, workspace, Lib)
172172
}
173173

174174
/// Returns the test executable that would be installed for <pkgid>
175175
/// in <workspace>
176-
pub fn target_test_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
176+
pub fn target_test_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
177177
target_file_in_workspace(pkgid, workspace, Test)
178178
}
179179

180180
/// Returns the bench executable that would be installed for <pkgid>
181181
/// in <workspace>
182-
pub fn target_bench_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
182+
pub fn target_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
183183
target_file_in_workspace(pkgid, workspace, Bench)
184184
}
185185

186-
fn target_file_in_workspace(pkgid: PkgId, workspace: &Path,
186+
fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
187187
what: OutputType) -> Path {
188188
use conditions::bad_path::cond;
189189

@@ -193,7 +193,8 @@ fn target_file_in_workspace(pkgid: PkgId, workspace: &Path,
193193
let result = workspace.push(subdir);
194194
if create_dir {
195195
if !os::path_exists(&result) && !mkdir_recursive(&result, u_rwx) {
196-
cond.raise((result, fmt!("I couldn't create the %s dir", subdir)));
196+
cond.raise((copy result,
197+
fmt!("I couldn't create the %s dir", subdir)));
197198
}
198199
}
199200
mk_output_path(what, pkgid.path.to_str(), result)
@@ -202,13 +203,13 @@ fn target_file_in_workspace(pkgid: PkgId, workspace: &Path,
202203

203204
/// Return the directory for <pkgid>'s build artifacts in <workspace>.
204205
/// Creates it if it doesn't exist.
205-
pub fn build_pkg_id_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
206+
pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
206207
use conditions::bad_path::cond;
207208

208209
let mut result = workspace.push("build");
209210
// n.b. Should actually use a target-specific
210211
// subdirectory of build/
211-
result = result.push(normalize(~pkgid.path).to_str());
212+
result = result.push(normalize(~copy pkgid.path).to_str());
212213
if os::path_exists(&result) || os::mkdir_recursive(&result, u_rwx) {
213214
result
214215
}

branches/try2/src/librustpkg/rustpkg.rc

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#[license = "MIT/ASL2"];
1919
#[crate_type = "lib"];
20-
#[allow(vecs_implicitly_copyable,
21-
non_implicitly_copyable_typarams)];
2220

2321
extern mod std(vers = "0.7-pre");
2422
extern mod rustc(vers = "0.7-pre");
@@ -52,9 +50,9 @@ pub mod usage;
5250
/// A PkgScript represents user-supplied custom logic for
5351
/// special build hooks. This only exists for packages with
5452
/// an explicit package script.
55-
struct PkgScript {
53+
struct PkgScript<'self> {
5654
/// Uniquely identifies this package
57-
id: PkgId,
55+
id: &'self PkgId,
5856
// Used to have this field: deps: ~[(~str, Option<~str>)]
5957
// but I think it shouldn't be stored here
6058
/// The contents of the package script: either a file path,
@@ -71,24 +69,24 @@ struct PkgScript {
7169
build_dir: Path
7270
}
7371

74-
impl PkgScript {
72+
impl<'self> PkgScript<'self> {
7573
/// Given the path name for a package script
7674
/// and a package ID, parse the package script into
7775
/// 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> {
7977
// Get the executable name that was invoked
80-
let binary = os::args()[0];
78+
let binary = @copy os::args()[0];
8179
// Build the rustc session data structures to pass
8280
// to the compiler
8381
let options = @session::options {
84-
binary: @binary,
82+
binary: binary,
8583
crate_type: session::bin_crate,
86-
.. *session::basic_options()
84+
.. copy *session::basic_options()
8785
};
8886
let input = driver::file_input(script);
8987
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,
9290
driver::cu_parse, None);
9391
let work_dir = build_pkg_id_in_workspace(id, workspace);
9492

@@ -123,10 +121,10 @@ impl PkgScript {
123121
let root = r.pop().pop().pop().pop(); // :-\
124122
debug!("Root is %s, calling compile_rest", root.to_str());
125123
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),
128126
sess, Some(crate),
129-
exe, os::args()[0],
127+
&exe, @copy os::args()[0],
130128
driver::cu_everything);
131129
debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what);
132130
let status = run::run_program(exe.to_str(), ~[root.to_str(), what]);
@@ -188,9 +186,9 @@ impl Ctx {
188186
}
189187
// The package id is presumed to be the first command-line
190188
// 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);
194192
}
195193
}
196194
~"clean" => {
@@ -199,16 +197,16 @@ impl Ctx {
199197
}
200198
// The package id is presumed to be the first command-line
201199
// argument
202-
let pkgid = PkgId::new(args[0]);
200+
let pkgid = PkgId::new(copy args[0]);
203201
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
205203
}
206204
~"do" => {
207205
if args.len() < 2 {
208206
return usage::do_cmd();
209207
}
210208

211-
self.do_cmd(args[0], args[1]);
209+
self.do_cmd(copy args[0], copy args[1]);
212210
}
213211
~"info" => {
214212
self.info();
@@ -221,16 +219,16 @@ impl Ctx {
221219
// The package id is presumed to be the first command-line
222220
// argument
223221
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);
226224
}
227225
}
228226
~"prefer" => {
229227
if args.len() < 1 {
230228
return usage::uninstall();
231229
}
232230

233-
let (name, vers) = sep_name_vers(args[0]);
231+
let (name, vers) = sep_name_vers(copy args[0]);
234232

235233
self.prefer(name.get(), vers);
236234
}
@@ -242,7 +240,7 @@ impl Ctx {
242240
return usage::uninstall();
243241
}
244242

245-
let (name, vers) = sep_name_vers(args[0]);
243+
let (name, vers) = sep_name_vers(copy args[0]);
246244

247245
self.uninstall(name.get(), vers);
248246
}
@@ -251,26 +249,26 @@ impl Ctx {
251249
return usage::uninstall();
252250
}
253251

254-
let (name, vers) = sep_name_vers(args[0]);
252+
let (name, vers) = sep_name_vers(copy args[0]);
255253

256254
self.unprefer(name.get(), vers);
257255
}
258256
_ => fail!("reached an unhandled command")
259257
}
260258
}
261259

262-
fn do_cmd(&self, _cmd: ~str, _pkgname: ~str) {
260+
fn do_cmd(&self, _cmd: &str, _pkgname: &str) {
263261
// stub
264262
fail!("`do` not yet implemented");
265263
}
266264

267-
fn build(&self, workspace: &Path, pkgid: PkgId) {
265+
fn build(&self, workspace: &Path, pkgid: &PkgId) {
268266
let src_dir = pkgid_src_in_workspace(pkgid, workspace);
269267
let build_dir = build_pkg_id_in_workspace(pkgid, workspace);
270268
debug!("Destination dir = %s", build_dir.to_str());
271269

272270
// 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);
274272
debug!("Package src = %?", src);
275273

276274
// Is there custom build logic? If so, use it
@@ -311,7 +309,7 @@ impl Ctx {
311309

312310
}
313311

314-
fn clean(&self, workspace: &Path, id: PkgId) {
312+
fn clean(&self, workspace: &Path, id: &PkgId) {
315313
// Could also support a custom build hook in the pkg
316314
// script for cleaning files rustpkg doesn't know about.
317315
// Do something reasonable for now
@@ -332,7 +330,7 @@ impl Ctx {
332330
fail!("info not yet implemented");
333331
}
334332

335-
fn install(&self, workspace: &Path, id: PkgId) {
333+
fn install(&self, workspace: &Path, id: &PkgId) {
336334
use conditions::copy_failed::cond;
337335

338336
// Should use RUST_PATH in the future.
@@ -348,13 +346,13 @@ impl Ctx {
348346
for maybe_executable.each |exec| {
349347
debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str());
350348
if !os::copy_file(exec, &target_exec) {
351-
cond.raise((*exec, target_exec));
349+
cond.raise((copy *exec, copy target_exec));
352350
}
353351
}
354352
for maybe_library.each |lib| {
355353
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
356354
if !os::copy_file(lib, &target_lib) {
357-
cond.raise((*lib, target_lib));
355+
cond.raise((copy *lib, copy target_lib));
358356
}
359357
}
360358
}
@@ -387,7 +385,7 @@ impl Ctx {
387385
}
388386
}
389387

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>) {
391389
util::note(fmt!("fetching from %s using git", url));
392390

393391
// Git can't clone into a non-empty directory
@@ -405,7 +403,7 @@ impl Ctx {
405403
do util::temp_change_dir(dir) {
406404
success = run::program_output(~"git",
407405
~[~"checkout",
408-
target.get()]).status != 0
406+
target.swap_unwrap()]).status != 0
409407
}
410408

411409
if !success {
@@ -525,7 +523,7 @@ pub struct Listener {
525523
}
526524

527525
pub fn run(listeners: ~[Listener]) {
528-
let rcmd = os::args()[2];
526+
let rcmd = copy os::args()[2];
529527
let mut found = false;
530528

531529
for listeners.each |listener| {
@@ -652,12 +650,12 @@ impl PkgSrc {
652650
// tjc: Rather than erroring out, need to try downloading the
653651
// contents of the path to a local directory (#5679)
654652
if !os::path_exists(&dir) {
655-
cond.raise((self.id, ~"missing package dir"));
653+
cond.raise((copy self.id, ~"missing package dir"));
656654
}
657655

658656
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"));
661659
}
662660

663661
dir
@@ -681,7 +679,7 @@ impl PkgSrc {
681679
/// Requires that dashes in p have already been normalized to
682680
/// underscores
683681
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();
685683
if self_id == p.filestem() {
686684
return true;
687685
}
@@ -737,7 +735,7 @@ impl PkgSrc {
737735
util::note(~"Couldn't infer any crates to build.\n\
738736
Try naming a crate `main.rs`, `lib.rs`, \
739737
`test.rs`, or `bench.rs`.");
740-
cond.raise(self.id);
738+
cond.raise(copy self.id);
741739
}
742740

743741
debug!("found %u libs, %u mains, %u tests, %u benchs",
@@ -752,15 +750,15 @@ impl PkgSrc {
752750
dst_dir: &Path,
753751
src_dir: &Path,
754752
crates: &[Crate],
755-
cfgs: ~[~str],
753+
cfgs: &[~str],
756754
test: bool, crate_type: crate_type) {
757755

758756
for crates.each |&crate| {
759757
let path = &src_dir.push_rel(&crate.file).normalize();
760758
util::note(fmt!("build_crates: compiling %s", path.to_str()));
761759
util::note(fmt!("build_crates: destination dir is %s", dst_dir.to_str()));
762760

763-
let result = util::compile_crate(maybe_sysroot, self.id, path,
761+
let result = util::compile_crate(maybe_sysroot, &self.id, path,
764762
dst_dir,
765763
crate.flags,
766764
crate.cfgs + cfgs,

0 commit comments

Comments
 (0)