Skip to content

Commit b32a48b

Browse files
committed
---
yaml --- r: 28154 b: refs/heads/try c: 8aca44e h: refs/heads/master v: v3
1 parent 9ed2d89 commit b32a48b

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
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: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: fd12188c0765e095e8bed00864f30de15e884c33
5+
refs/heads/try: 8aca44ee0cdde30e8eb7c826f685e35a797e00e4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/src/libcore/path.rs

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ trait GenericPath {
3232
pure fn push_rel((&self)) -> self;
3333
pure fn push_many((&[~str])) -> self;
3434
pure fn pop() -> self;
35+
36+
pure fn normalize() -> self;
3537
}
3638

3739
#[cfg(windows)]
@@ -68,7 +70,7 @@ impl PosixPath : GenericPath {
6870
let mut components = str::split_nonempty(s, |c| c == '/');
6971
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
7072
return PosixPath { is_absolute: is_absolute,
71-
components: normalize(components) }
73+
components: components }
7274
}
7375

7476
pure fn dirname() -> ~str {
@@ -175,14 +177,13 @@ impl PosixPath : GenericPath {
175177
}
176178

177179
pure fn push_many(cs: &[~str]) -> PosixPath {
178-
return PosixPath { components: normalize(self.components + cs),
180+
return PosixPath { components: self.components + cs,
179181
..self }
180182
}
181183

182184
pure fn push(s: &str) -> PosixPath {
183185
let mut cs = self.components;
184186
unchecked { vec::push(cs, move str::from_slice(s)); }
185-
cs = normalize(cs);
186187
return PosixPath { components: move cs,
187188
..self }
188189
}
@@ -194,6 +195,13 @@ impl PosixPath : GenericPath {
194195
}
195196
return PosixPath { components: move cs, ..self }
196197
}
198+
199+
pure fn normalize() -> PosixPath {
200+
return PosixPath {
201+
components: normalize(self.components),
202+
..self
203+
}
204+
}
197205
}
198206

199207

@@ -251,7 +259,7 @@ impl WindowsPath : GenericPath {
251259
return WindowsPath { host: host,
252260
device: device,
253261
is_absolute: is_absolute,
254-
components: normalize(components) }
262+
components: components }
255263
}
256264

257265
pure fn dirname() -> ~str {
@@ -358,14 +366,13 @@ impl WindowsPath : GenericPath {
358366
}
359367

360368
pure fn push_many(cs: &[~str]) -> WindowsPath {
361-
return WindowsPath { components: normalize(self.components + cs),
369+
return WindowsPath { components: self.components + cs,
362370
..self }
363371
}
364372

365373
pure fn push(s: &str) -> WindowsPath {
366374
let mut cs = self.components;
367375
unchecked { vec::push(cs, move str::from_slice(s)); }
368-
cs = normalize(cs);
369376
return WindowsPath { components: move cs,
370377
..self }
371378
}
@@ -377,6 +384,13 @@ impl WindowsPath : GenericPath {
377384
}
378385
return WindowsPath { components: move cs, ..self }
379386
}
387+
388+
pure fn normalize() -> WindowsPath {
389+
return WindowsPath {
390+
components: normalize(self.components),
391+
..self
392+
}
393+
}
380394
}
381395

382396

@@ -399,19 +413,22 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
399413
400414
mod posix {
401415
402-
#[test]
403-
fn test_posix_paths() {
404-
fn mk(s: &str) -> PosixPath { from_str::<PosixPath>(s) }
405-
fn t(wp: &PosixPath, s: &str) {
406-
let ss = wp.to_str();
407-
let sss = str::from_slice(s);
408-
if (ss != sss) {
409-
debug!("got %s", ss);
410-
debug!("expected %s", sss);
411-
assert ss == sss;
412-
}
416+
#[cfg(test)]
417+
fn mk(s: &str) -> PosixPath { from_str::<PosixPath>(s) }
418+
419+
#[cfg(test)]
420+
fn t(wp: &PosixPath, s: &str) {
421+
let ss = wp.to_str();
422+
let sss = str::from_slice(s);
423+
if (ss != sss) {
424+
debug!("got %s", ss);
425+
debug!("expected %s", sss);
426+
assert ss == sss;
413427
}
428+
}
414429

430+
#[test]
431+
fn test_posix_paths() {
415432
t(&(mk("hi")), "hi");
416433
t(&(mk("/lib")), "/lib");
417434
t(&(mk("hi/there")), "hi/there");
@@ -425,13 +442,10 @@ mod posix {
425442
.with_dirname("hi")), "hi/there.txt");
426443

427444
t(&(mk("hi/there.txt")
428-
.with_dirname(".")), "there.txt");
429-
430-
t(&(mk("a/b/../c/././/../foo.txt/")),
431-
"a/foo.txt");
445+
.with_dirname(".")), "./there.txt");
432446

433447
t(&(mk("a/b/c")
434-
.push("..")), "a/b");
448+
.push("..")), "a/b/c/..");
435449

436450
t(&(mk("there.txt")
437451
.with_filetype("o")), "there.o");
@@ -461,6 +475,17 @@ mod posix {
461475

462476
}
463477

478+
#[test]
479+
fn test_normalize() {
480+
t(&(mk("hi/there.txt")
481+
.with_dirname(".").normalize()), "there.txt");
482+
483+
t(&(mk("a/b/../c/././/../foo.txt/").normalize()),
484+
"a/foo.txt");
485+
486+
t(&(mk("a/b/c")
487+
.push("..").normalize()), "a/b");
488+
}
464489
}
465490

466491
// Various windows helpers, and tests for the impl.

branches/try/src/rustc/back/rpath.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ fn get_rpath_relative_to_output(os: session::os,
117117
fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
118118
assert abs1.is_absolute;
119119
assert abs2.is_absolute;
120+
let abs1 = abs1.normalize();
121+
let abs2 = abs2.normalize();
120122
debug!("finding relative path from %s to %s",
121123
abs1.to_str(), abs2.to_str());
122124
let split1 = abs1.components;
@@ -295,7 +297,7 @@ mod test {
295297
let o = session::os_linux;
296298
let res = get_rpath_relative_to_output(o,
297299
&Path("bin/rustc"), &Path("lib/libstd.so"));
298-
assert res == Path("$ORIGIN/../lib");
300+
assert res.to_str() == ~"$ORIGIN/../lib";
299301
}
300302

301303
#[test]
@@ -304,7 +306,7 @@ mod test {
304306
let o = session::os_freebsd;
305307
let res = get_rpath_relative_to_output(o,
306308
&Path("bin/rustc"), &Path("lib/libstd.so"));
307-
assert res == Path("$ORIGIN/../lib");
309+
assert res.to_str() == ~"$ORIGIN/../lib";
308310
}
309311

310312
#[test]
@@ -315,7 +317,7 @@ mod test {
315317
let res = get_rpath_relative_to_output(o,
316318
&Path("bin/rustc"),
317319
&Path("lib/libstd.so"));
318-
assert res == Path("@executable_path/../lib");
320+
assert res.to_str() == ~"@executable_path/../lib";
319321
}
320322

321323
#[test]

0 commit comments

Comments
 (0)