Skip to content

Commit 5286535

Browse files
committed
---
yaml --- r: 145020 b: refs/heads/try2 c: 24fdb1d h: refs/heads/master v: v3
1 parent 2ea9d3e commit 5286535

File tree

8 files changed

+298
-244
lines changed

8 files changed

+298
-244
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: 05bbb480a22d1f752f95591b41b584018966b136
8+
refs/heads/try2: 24fdb1d102eaa062a8a6213ec28803885192a694
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rustpkg.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ A valid workspace must contain each of the following subdirectories:
5252
rustpkg will install libraries for bar to `foo/lib/x86_64-apple-darwin/`.
5353
The libraries will have names of the form `foo/lib/x86_64-apple-darwin/libbar-[hash].dylib`,
5454
where [hash] is a hash of the package ID.
55-
* 'bin/': `rustpkg install` installs executable binaries into a target-specific subdirectory of this directory.
55+
* 'bin/': `rustpkg install` installs executable binaries into this directory.
5656

57-
For example, on a 64-bit machine running Mac OS X,
58-
if `foo` is a workspace, containing the package `bar`,
59-
rustpkg will install executables for `bar` to
60-
`foo/bin/x86_64-apple-darwin/`.
61-
The executables will have names of the form `foo/bin/x86_64-apple-darwin/bar`.
57+
For example, rustpkg will install executables for `bar` to
58+
`foo/bin`.
59+
The executables will have names of the form `foo/bin/bar`.
6260
* 'build/': `rustpkg build` stores temporary build artifacts in a target-specific subdirectory of this directory.
6361

6462
For example, on a 64-bit machine running Mac OS X,
@@ -85,6 +83,12 @@ rustpkg also interprets any dependencies on such a package ID literally
8583
Thus, `github.com/mozilla/rust#5c4cd30f80` is also a valid package ID,
8684
since git can deduce that 5c4cd30f80 refers to a revision of the desired repository.
8785

86+
A package identifier can name a subdirectory of another package.
87+
For example, if `foo` is a workspace, and `foo/src/bar/lib.rs` exists,
88+
as well as `foo/src/bar/extras/baz/lib.rs`,
89+
then both `bar` and `bar/extras/baz` are valid package identifiers
90+
in the workspace `foo`.
91+
8892
## Source files
8993

9094
rustpkg searches for four different fixed filenames in order to determine the crates to build:
@@ -140,9 +144,11 @@ but not in their `lib` or `bin` directories.
140144

141145
## install
142146

143-
`rustpkg install foo` builds the libraries and/or executables that are targets for `foo`,
144-
and then installs them either into `foo`'s `lib` and `bin` directories,
145-
or into the `lib` and `bin` subdirectories of the first entry in `RUST_PATH`.
147+
`rustpkg install foo` builds the libraries and/or executables that are targets for `foo`.
148+
If `RUST_PATH` is declared as an environment variable, then rustpkg installs the
149+
libraries and executables into the `lib` and `bin` subdirectories
150+
of the first entry in `RUST_PATH`.
151+
Otherwise, it installs them into `foo`'s `lib` and `bin` directories.
146152

147153
## test
148154

branches/try2/src/libextra/glob.rs

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,194 @@ mod test {
516516
use super::*;
517517
use tempfile;
518518
519+
#[test]
520+
fn test_relative_pattern() {
521+
522+
fn change_then_remove(p: &Path, f: &fn()) {
523+
do (|| {
524+
unstable::change_dir_locked(p, || f());
525+
}).finally {
526+
os::remove_dir_recursive(p);
527+
}
528+
}
529+
530+
fn mk_file(path: &str, directory: bool) {
531+
if directory {
532+
os::make_dir(&Path(path), 0xFFFF);
533+
} else {
534+
io::mk_file_writer(&Path(path), [io::Create]);
535+
}
536+
}
537+
538+
fn abs_path(path: &str) -> Path {
539+
os::getcwd().push_many(Path(path).components)
540+
}
541+
542+
fn glob_vec(pattern: &str) -> ~[Path] {
543+
glob(pattern).collect()
544+
}
545+
546+
let root = tempfile::mkdtemp(&os::tmpdir(), "glob-tests");
547+
let root = root.expect("Should have created a temp directory");
548+
549+
do change_then_remove(&root) {
550+
551+
mk_file("aaa", true);
552+
mk_file("aaa/apple", true);
553+
mk_file("aaa/orange", true);
554+
mk_file("aaa/tomato", true);
555+
mk_file("aaa/tomato/tomato.txt", false);
556+
mk_file("aaa/tomato/tomoto.txt", false);
557+
mk_file("bbb", true);
558+
mk_file("bbb/specials", true);
559+
mk_file("bbb/specials/!", false);
560+
561+
// windows does not allow `*` or `?` characters to exist in filenames
562+
if os::consts::FAMILY != os::consts::windows::FAMILY {
563+
mk_file("bbb/specials/*", false);
564+
mk_file("bbb/specials/?", false);
565+
}
566+
567+
mk_file("bbb/specials/[", false);
568+
mk_file("bbb/specials/]", false);
569+
mk_file("ccc", true);
570+
mk_file("xyz", true);
571+
mk_file("xyz/x", false);
572+
mk_file("xyz/y", false);
573+
mk_file("xyz/z", false);
574+
575+
assert_eq!(glob_vec(""), ~[]);
576+
assert_eq!(glob_vec("."), ~[]);
577+
assert_eq!(glob_vec(".."), ~[]);
578+
579+
assert_eq!(glob_vec("aaa"), ~[abs_path("aaa")]);
580+
assert_eq!(glob_vec("aaa/"), ~[abs_path("aaa")]);
581+
assert_eq!(glob_vec("a"), ~[]);
582+
assert_eq!(glob_vec("aa"), ~[]);
583+
assert_eq!(glob_vec("aaaa"), ~[]);
584+
585+
assert_eq!(glob_vec("aaa/apple"), ~[abs_path("aaa/apple")]);
586+
assert_eq!(glob_vec("aaa/apple/nope"), ~[]);
587+
588+
// windows should support both / and \ as directory separators
589+
if os::consts::FAMILY == os::consts::windows::FAMILY {
590+
assert_eq!(glob_vec("aaa\\apple"), ~[abs_path("aaa/apple")]);
591+
}
592+
593+
assert_eq!(glob_vec("???/"), ~[
594+
abs_path("aaa"),
595+
abs_path("bbb"),
596+
abs_path("ccc"),
597+
abs_path("xyz")]);
598+
599+
assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), ~[
600+
abs_path("aaa/tomato/tomato.txt"),
601+
abs_path("aaa/tomato/tomoto.txt")]);
602+
603+
assert_eq!(glob_vec("xyz/?"), ~[
604+
abs_path("xyz/x"),
605+
abs_path("xyz/y"),
606+
abs_path("xyz/z")]);
607+
608+
assert_eq!(glob_vec("a*"), ~[abs_path("aaa")]);
609+
assert_eq!(glob_vec("*a*"), ~[abs_path("aaa")]);
610+
assert_eq!(glob_vec("a*a"), ~[abs_path("aaa")]);
611+
assert_eq!(glob_vec("aaa*"), ~[abs_path("aaa")]);
612+
assert_eq!(glob_vec("*aaa"), ~[abs_path("aaa")]);
613+
assert_eq!(glob_vec("*aaa*"), ~[abs_path("aaa")]);
614+
assert_eq!(glob_vec("*a*a*a*"), ~[abs_path("aaa")]);
615+
assert_eq!(glob_vec("aaa*/"), ~[abs_path("aaa")]);
616+
617+
assert_eq!(glob_vec("aaa/*"), ~[
618+
abs_path("aaa/apple"),
619+
abs_path("aaa/orange"),
620+
abs_path("aaa/tomato")]);
621+
622+
assert_eq!(glob_vec("aaa/*a*"), ~[
623+
abs_path("aaa/apple"),
624+
abs_path("aaa/orange"),
625+
abs_path("aaa/tomato")]);
626+
627+
assert_eq!(glob_vec("*/*/*.txt"), ~[
628+
abs_path("aaa/tomato/tomato.txt"),
629+
abs_path("aaa/tomato/tomoto.txt")]);
630+
631+
assert_eq!(glob_vec("*/*/t[aob]m?to[.]t[!y]t"), ~[
632+
abs_path("aaa/tomato/tomato.txt"),
633+
abs_path("aaa/tomato/tomoto.txt")]);
634+
635+
assert_eq!(glob_vec("aa[a]"), ~[abs_path("aaa")]);
636+
assert_eq!(glob_vec("aa[abc]"), ~[abs_path("aaa")]);
637+
assert_eq!(glob_vec("a[bca]a"), ~[abs_path("aaa")]);
638+
assert_eq!(glob_vec("aa[b]"), ~[]);
639+
assert_eq!(glob_vec("aa[xyz]"), ~[]);
640+
assert_eq!(glob_vec("aa[]]"), ~[]);
641+
642+
assert_eq!(glob_vec("aa[!b]"), ~[abs_path("aaa")]);
643+
assert_eq!(glob_vec("aa[!bcd]"), ~[abs_path("aaa")]);
644+
assert_eq!(glob_vec("a[!bcd]a"), ~[abs_path("aaa")]);
645+
assert_eq!(glob_vec("aa[!a]"), ~[]);
646+
assert_eq!(glob_vec("aa[!abc]"), ~[]);
647+
648+
assert_eq!(glob_vec("bbb/specials/[[]"), ~[abs_path("bbb/specials/[")]);
649+
assert_eq!(glob_vec("bbb/specials/!"), ~[abs_path("bbb/specials/!")]);
650+
assert_eq!(glob_vec("bbb/specials/[]]"), ~[abs_path("bbb/specials/]")]);
651+
652+
if os::consts::FAMILY != os::consts::windows::FAMILY {
653+
assert_eq!(glob_vec("bbb/specials/[*]"), ~[abs_path("bbb/specials/*")]);
654+
assert_eq!(glob_vec("bbb/specials/[?]"), ~[abs_path("bbb/specials/?")]);
655+
}
656+
657+
if os::consts::FAMILY == os::consts::windows::FAMILY {
658+
659+
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
660+
abs_path("bbb/specials/!"),
661+
abs_path("bbb/specials/]")]);
662+
663+
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
664+
abs_path("bbb/specials/!"),
665+
abs_path("bbb/specials/[")]);
666+
667+
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
668+
abs_path("bbb/specials/["),
669+
abs_path("bbb/specials/]")]);
670+
671+
} else {
672+
673+
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
674+
abs_path("bbb/specials/!"),
675+
abs_path("bbb/specials/*"),
676+
abs_path("bbb/specials/?"),
677+
abs_path("bbb/specials/]")]);
678+
679+
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
680+
abs_path("bbb/specials/!"),
681+
abs_path("bbb/specials/*"),
682+
abs_path("bbb/specials/?"),
683+
abs_path("bbb/specials/[")]);
684+
685+
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
686+
abs_path("bbb/specials/*"),
687+
abs_path("bbb/specials/?"),
688+
abs_path("bbb/specials/["),
689+
abs_path("bbb/specials/]")]);
690+
691+
assert_eq!(glob_vec("bbb/specials/[!*]"), ~[
692+
abs_path("bbb/specials/!"),
693+
abs_path("bbb/specials/?"),
694+
abs_path("bbb/specials/["),
695+
abs_path("bbb/specials/]")]);
696+
697+
assert_eq!(glob_vec("bbb/specials/[!?]"), ~[
698+
abs_path("bbb/specials/!"),
699+
abs_path("bbb/specials/*"),
700+
abs_path("bbb/specials/["),
701+
abs_path("bbb/specials/]")]);
702+
703+
}
704+
};
705+
}
706+
519707
#[test]
520708
fn test_absolute_pattern() {
521709
// assume that the filesystem is not empty!

branches/try2/src/librustc/metadata/filesearch.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
7777
if !found {
7878
let rustpath = rust_path();
7979
for path in rustpath.iter() {
80-
debug!("is %s in visited_dirs? %?",
81-
path.push("lib").to_str(),
82-
visited_dirs.contains(&path.push("lib").to_str()));
80+
let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
81+
debug!("is %s in visited_dirs? %?", tlib_path.to_str(),
82+
visited_dirs.contains(&tlib_path.to_str()));
8383

84-
if !visited_dirs.contains(&path.push("lib").to_str()) {
85-
visited_dirs.insert(path.push("lib").to_str());
84+
if !visited_dirs.contains(&tlib_path.to_str()) {
85+
visited_dirs.insert(tlib_path.to_str());
8686
// Don't keep searching the RUST_PATH if one match turns up --
8787
// if we did, we'd get a "multiple matching crates" error
88-
match f(&path.push("lib")) {
88+
match f(&tlib_path) {
8989
FileMatches => {
9090
break;
9191
}
@@ -145,6 +145,11 @@ fn make_target_lib_path(sysroot: &Path,
145145
sysroot.push_rel(&relative_target_lib_path(target_triple))
146146
}
147147

148+
fn make_rustpkg_target_lib_path(dir: &Path,
149+
target_triple: &str) -> Path {
150+
dir.push_rel(&Path(libdir()).push(target_triple.to_owned()))
151+
}
152+
148153
fn get_or_default_sysroot() -> Path {
149154
match os::self_exe_path() {
150155
option::Some(ref p) => (*p).pop(),

branches/try2/src/librustpkg/path_util.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use package_id::PkgId;
1414
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
1515
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
1616
pub use rustc::metadata::filesearch::rust_path;
17+
use rustc::driver::driver::host_triple;
1718

1819
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
1920
use std::os::mkdir_recursive;
@@ -94,10 +95,29 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
9495
found
9596
}
9697

98+
/// Return the target-specific build subdirectory, pushed onto `base`;
99+
/// doesn't check that it exists or create it
100+
pub fn target_build_dir(workspace: &Path) -> Path {
101+
workspace.push("build").push(host_triple())
102+
}
103+
104+
/// Return the target-specific lib subdirectory, pushed onto `base`;
105+
/// doesn't check that it exists or create it
106+
fn target_lib_dir(workspace: &Path) -> Path {
107+
workspace.push("lib").push(host_triple())
108+
}
109+
110+
/// Return the bin subdirectory, pushed onto `base`;
111+
/// doesn't check that it exists or create it
112+
/// note: this isn't target-specific
113+
fn target_bin_dir(workspace: &Path) -> Path {
114+
workspace.push("bin")
115+
}
116+
97117
/// Figure out what the executable name for <pkgid> in <workspace>'s build
98118
/// directory is, and if the file exists, return it.
99119
pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
100-
let mut result = workspace.push("build");
120+
let mut result = target_build_dir(workspace);
101121
// should use a target-specific subdirectory
102122
result = mk_output_path(Main, Build, pkgid, result);
103123
debug!("built_executable_in_workspace: checking whether %s exists",
@@ -124,7 +144,7 @@ pub fn built_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path>
124144
}
125145

126146
fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Option<Path> {
127-
let mut result = workspace.push("build");
147+
let mut result = target_build_dir(workspace);
128148
// should use a target-specific subdirectory
129149
result = mk_output_path(what, Build, pkgid, result);
130150
debug!("output_in_workspace: checking whether %s exists",
@@ -172,11 +192,21 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
172192
prefix = %s", short_name, where, workspace.to_str(), prefix);
173193

174194
let dir_to_search = match where {
175-
Build => workspace.push(prefix).push_rel(path),
176-
Install => workspace.push(prefix)
195+
Build => target_build_dir(workspace).push_rel(path),
196+
Install => target_lib_dir(workspace)
177197
};
198+
199+
library_in(short_name, version, &dir_to_search)
200+
}
201+
202+
// rustc doesn't use target-specific subdirectories
203+
pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
204+
library_in(lib_name, &NoVersion, &sysroot.push("lib"))
205+
}
206+
207+
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
178208
debug!("Listing directory %s", dir_to_search.to_str());
179-
let dir_contents = os::list_dir(&dir_to_search);
209+
let dir_contents = os::list_dir(dir_to_search);
180210
debug!("dir has %? entries", dir_contents.len());
181211

182212
let lib_prefix = fmt!("%s%s", os::consts::DLL_PREFIX, short_name);
@@ -298,9 +328,10 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
298328
};
299329
// Artifacts in the build directory live in a package-ID-specific subdirectory,
300330
// but installed ones don't.
301-
let result = match where {
302-
Build => workspace.push(subdir).push_rel(&pkgid.path),
303-
_ => workspace.push(subdir)
331+
let result = match (where, what) {
332+
(Build, _) => target_build_dir(workspace).push_rel(&pkgid.path),
333+
(Install, Lib) => target_lib_dir(workspace),
334+
(Install, _) => target_bin_dir(workspace)
304335
};
305336
if !os::path_exists(&result) && !mkdir_recursive(&result, U_RWX) {
306337
cond.raise((result.clone(), fmt!("target_file_in_workspace couldn't \
@@ -315,10 +346,10 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
315346
pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
316347
use conditions::bad_path::cond;
317348

318-
let mut result = workspace.push("build");
319-
// n.b. Should actually use a target-specific
320-
// subdirectory of build/
349+
let mut result = target_build_dir(workspace);
321350
result = result.push_rel(&pkgid.path);
351+
debug!("Creating build dir %s for package id %s", result.to_str(),
352+
pkgid.to_str());
322353
if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) {
323354
result
324355
}

0 commit comments

Comments
 (0)