Skip to content

Commit d9293d1

Browse files
committed
rustpkg: Un-ignore most of the remaining tests
This necessitated some cleanup to how we parse library filenames when searching for libraries, since rustpkg may now create filenames that contain '-' characters. Also cleaned up how rustpkg passes the sysroot to a custom build script.
1 parent 4bdceb9 commit d9293d1

File tree

7 files changed

+86
-93
lines changed

7 files changed

+86
-93
lines changed

src/librustpkg/context.rs

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ impl Ctx {
3333
Some(p) => p.to_str()
3434
}
3535
}
36+
37+
// Hack so that rustpkg can run either out of a rustc target dir,
38+
// or the host dir
39+
pub fn sysroot_to_use(&self) -> Option<@Path> {
40+
if !in_target(self.sysroot_opt) {
41+
self.sysroot_opt
42+
}
43+
else {
44+
self.sysroot_opt.map(|p| { @p.pop().pop().pop() })
45+
}
46+
}
3647
}
3748

3849
/// We assume that if ../../rustc exists, then we're running

src/librustpkg/package_source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl PkgSrc {
5454
debug!("Pushing onto root: %s | %s", self.id.path.to_str(), self.root.to_str());
5555

5656
let dirs = pkgid_src_in_workspace(&self.id, &self.root);
57-
debug!("Checking dirs: %?", dirs);
57+
debug!("Checking dirs: %?", dirs.map(|s| s.to_str()).connect(":"));
5858
let path = dirs.iter().find(|&d| os::path_exists(d));
5959

6060
let dir = match path {

src/librustpkg/path_util.rs

+34-35
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
pub use package_id::PkgId;
1414
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
15-
pub use version::{Version, NoVersion, split_version_general};
15+
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
1616
pub use rustc::metadata::filesearch::rust_path;
1717

1818
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
@@ -153,21 +153,19 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
153153
/// Figure out what the library name for <pkgid> in <workspace>'s build
154154
/// directory is, and if the file exists, return it.
155155
pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
156-
library_in_workspace(&pkgid.path, pkgid.short_name, Build, workspace, "build")
156+
library_in_workspace(&pkgid.path, pkgid.short_name, Build, workspace, "build", &pkgid.version)
157157
}
158158

159159
/// Does the actual searching stuff
160160
pub fn installed_library_in_workspace(short_name: &str, workspace: &Path) -> Option<Path> {
161-
library_in_workspace(&Path(short_name), short_name, Install, workspace, "lib")
161+
// NOTE: this could break once we're handling multiple versions better... want a test for it
162+
library_in_workspace(&Path(short_name), short_name, Install, workspace, "lib", &NoVersion)
162163
}
163164

164-
165-
/// This doesn't take a PkgId, so we can use it for `extern mod` inference, where we
166-
/// don't know the entire package ID.
167165
/// `workspace` is used to figure out the directory to search.
168166
/// `short_name` is taken as the link name of the library.
169167
pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
170-
workspace: &Path, prefix: &str) -> Option<Path> {
168+
workspace: &Path, prefix: &str, version: &Version) -> Option<Path> {
171169
debug!("library_in_workspace: checking whether a library named %s exists",
172170
short_name);
173171

@@ -209,36 +207,37 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
209207
for p_path in libraries {
210208
// Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix)
211209
// and remember what the hash was
212-
let f_name = match p_path.filename() {
210+
let mut f_name = match p_path.filestem() {
213211
Some(s) => s, None => loop
214212
};
215-
216-
let mut hash = None;
217-
let mut which = 0;
218-
for piece in f_name.split_iter('-') {
219-
debug!("a piece = %s", piece);
220-
if which == 0 && piece != lib_prefix {
221-
break;
222-
}
223-
else if which == 0 {
224-
which += 1;
225-
}
226-
else if which == 1 {
227-
hash = Some(piece.to_owned());
228-
break;
229-
}
230-
else {
231-
// something went wrong
232-
hash = None;
233-
break;
234-
}
235-
}
236-
237-
if hash.is_some() {
238-
result_filename = Some(p_path);
239-
break;
240-
}
241-
}
213+
// Already checked the filetype above
214+
215+
// This is complicated because library names and versions can both contain dashes
216+
loop {
217+
if f_name.is_empty() { break; }
218+
match f_name.rfind('-') {
219+
Some(i) => {
220+
debug!("Maybe %s is a version", f_name.slice(i + 1, f_name.len()));
221+
match try_parsing_version(f_name.slice(i + 1, f_name.len())) {
222+
Some(ref found_vers) if version == found_vers => {
223+
match f_name.slice(0, i).rfind('-') {
224+
Some(j) => {
225+
debug!("Maybe %s equals %s", f_name.slice(0, j), lib_prefix);
226+
if f_name.slice(0, j) == lib_prefix {
227+
result_filename = Some(p_path);
228+
}
229+
break;
230+
}
231+
None => break
232+
}
233+
}
234+
_ => { f_name = f_name.slice(0, i).to_owned(); }
235+
}
236+
}
237+
None => break
238+
} // match
239+
} // loop
240+
} // for
242241

243242
if result_filename.is_none() {
244243
warn(fmt!("library_in_workspace didn't find a library in %s for %s",

src/librustpkg/rustpkg.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,18 @@ impl<'self> PkgScript<'self> {
9494
/// Given the path name for a package script
9595
/// and a package ID, parse the package script into
9696
/// a PkgScript that we can then execute
97-
fn parse<'a>(script: Path, workspace: &Path, id: &'a PkgId) -> PkgScript<'a> {
97+
fn parse<'a>(sysroot: @Path,
98+
script: Path,
99+
workspace: &Path,
100+
id: &'a PkgId) -> PkgScript<'a> {
98101
// Get the executable name that was invoked
99102
let binary = os::args()[0].to_managed();
100103
// Build the rustc session data structures to pass
101104
// to the compiler
102-
debug!("pkgscript parse: %?", os::self_exe_path());
105+
debug!("pkgscript parse: %s", sysroot.to_str());
103106
let options = @session::options {
104107
binary: binary,
105-
maybe_sysroot: Some(@os::self_exe_path().unwrap().pop()),
108+
maybe_sysroot: Some(sysroot),
106109
crate_type: session::bin_crate,
107110
.. (*session::basic_options()).clone()
108111
};
@@ -113,7 +116,7 @@ impl<'self> PkgScript<'self> {
113116
let crate = driver::phase_2_configure_and_expand(sess, cfg.clone(), crate);
114117
let work_dir = build_pkg_id_in_workspace(id, workspace);
115118

116-
debug!("Returning package script with id %?", id);
119+
debug!("Returning package script with id %s", id.to_str());
117120

118121
PkgScript {
119122
id: id,
@@ -138,24 +141,22 @@ impl<'self> PkgScript<'self> {
138141
let crate = util::ready_crate(sess, self.crate);
139142
debug!("Building output filenames with script name %s",
140143
driver::source_name(&self.input));
141-
let root = filesearch::get_or_default_sysroot().pop().pop(); // :-\
142-
debug!("Root is %s, calling compile_rest", root.to_str());
143144
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
144145
util::compile_crate_from_input(&self.input,
145146
&self.build_dir,
146147
sess,
147148
crate);
148-
debug!("Running program: %s %s %s %s", exe.to_str(),
149-
sysroot.to_str(), root.to_str(), "install");
149+
debug!("Running program: %s %s %s", exe.to_str(),
150+
sysroot.to_str(), "install");
150151
// FIXME #7401 should support commands besides `install`
151152
let status = run::process_status(exe.to_str(), [sysroot.to_str(), ~"install"]);
152153
if status != 0 {
153154
return (~[], status);
154155
}
155156
else {
156157
debug!("Running program (configs): %s %s %s",
157-
exe.to_str(), root.to_str(), "configs");
158-
let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]);
158+
exe.to_str(), sysroot.to_str(), "configs");
159+
let output = run::process_output(exe.to_str(), [sysroot.to_str(), ~"configs"]);
159160
// Run the configs() function to get the configs
160161
let cfgs = str::from_bytes_slice(output.output).word_iter()
161162
.map(|w| w.to_owned()).collect();
@@ -350,10 +351,11 @@ impl CtxMethods for Ctx {
350351
debug!("Package source directory = %?", pkg_src_dir);
351352
let cfgs = match pkg_src_dir.chain_ref(|p| src.package_script_option(p)) {
352353
Some(package_script_path) => {
353-
let pscript = PkgScript::parse(package_script_path,
354+
let sysroot = self.sysroot_to_use().expect("custom build needs a sysroot");
355+
let pscript = PkgScript::parse(sysroot,
356+
package_script_path,
354357
workspace,
355358
pkgid);
356-
let sysroot = self.sysroot_opt.expect("custom build needs a sysroot");
357359
let (cfgs, hook_result) = pscript.run_custom(sysroot);
358360
debug!("Command return code = %?", hook_result);
359361
if hook_result != 0 {

src/librustpkg/tests.rs

+13-35
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
222222
assert!(os::path_is_dir(&*cwd));
223223
let cwd = (*cwd).clone();
224224
let mut prog = run::Process::new(cmd, args, run::ProcessOptions {
225-
env: env,
225+
env: env.map(|e| e + os::env()),
226226
dir: Some(&cwd),
227227
in_fd: None,
228228
out_fd: None,
@@ -358,7 +358,8 @@ fn lib_output_file_name(workspace: &Path, parent: &str, short_name: &str) -> Pat
358358
short_name,
359359
Build,
360360
workspace,
361-
"build").expect("lib_output_file_name")
361+
"build",
362+
&NoVersion).expect("lib_output_file_name")
362363
}
363364

364365
fn output_file_name(workspace: &Path, short_name: &str) -> Path {
@@ -405,10 +406,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId) {
405406
}
406407
}
407408

408-
// FIXME(#7249): these tests fail on multi-platform builds, so for now they're
409-
// only run one x86
410-
411-
#[test] #[ignore(cfg(target_arch = "x86"))]
409+
#[test]
412410
fn test_make_dir_rwx() {
413411
let temp = &os::tmpdir();
414412
let dir = temp.push("quux");
@@ -421,7 +419,7 @@ fn test_make_dir_rwx() {
421419
assert!(os::remove_dir_recursive(&dir));
422420
}
423421

424-
#[test] #[ignore(cfg(target_arch = "x86"))]
422+
#[test]
425423
fn test_install_valid() {
426424
use path_util::installed_library_in_workspace;
427425

@@ -451,7 +449,7 @@ fn test_install_valid() {
451449
assert!(!os::path_exists(&bench));
452450
}
453451

454-
#[test] #[ignore(cfg(target_arch = "x86"))]
452+
#[test]
455453
fn test_install_invalid() {
456454
use conditions::nonexistent_package::cond;
457455
use cond1 = conditions::missing_pkg_files::cond;
@@ -476,8 +474,6 @@ fn test_install_invalid() {
476474

477475
// Tests above should (maybe) be converted to shell out to rustpkg, too
478476

479-
// FIXME: #7956: temporarily disabled
480-
#[ignore(cfg(target_arch = "x86"))]
481477
fn test_install_git() {
482478
let sysroot = test_sysroot();
483479
debug!("sysroot = %s", sysroot.to_str());
@@ -526,7 +522,7 @@ fn test_install_git() {
526522
assert!(!os::path_exists(&bench));
527523
}
528524

529-
#[test] #[ignore(cfg(target_arch = "x86"))]
525+
#[test]
530526
fn test_package_ids_must_be_relative_path_like() {
531527
use conditions::bad_pkg_id::cond;
532528

@@ -567,8 +563,6 @@ fn test_package_ids_must_be_relative_path_like() {
567563
568564
}
569565
570-
// FIXME: #7956: temporarily disabled
571-
#[ignore(cfg(target_arch = "x86"))]
572566
fn test_package_version() {
573567
let local_path = "mockgithub.com/catamorphism/test_pkg_version";
574568
let repo = init_git_repo(&Path(local_path));
@@ -655,7 +649,6 @@ fn rustpkg_install_url_2() {
655649
&temp_dir);
656650
}
657651
658-
// FIXME: #7956: temporarily disabled
659652
#[test]
660653
fn rustpkg_library_target() {
661654
let foo_repo = init_git_repo(&Path("foo"));
@@ -683,23 +676,20 @@ fn rustpkg_local_pkg() {
683676
assert_executable_exists(&dir, "foo");
684677
}
685678
686-
// FIXME: #7956: temporarily disabled
687-
// Failing on dist-linux bot
688679
#[test]
689-
#[ignore]
690680
fn package_script_with_default_build() {
691681
let dir = create_local_package(&PkgId::new("fancy-lib"));
692682
debug!("dir = %s", dir.to_str());
693683
let source = test_sysroot().pop().pop().pop().push("src").push("librustpkg").
694684
push("testsuite").push("pass").push("src").push("fancy-lib").push("pkg.rs");
695685
debug!("package_script_with_default_build: %s", source.to_str());
696686
if !os::copy_file(&source,
697-
& dir.push("src").push("fancy_lib-0.1").push("pkg.rs")) {
687+
& dir.push("src").push("fancy-lib-0.1").push("pkg.rs")) {
698688
fail!("Couldn't copy file");
699689
}
700690
command_line_test([~"install", ~"fancy-lib"], &dir);
701691
assert_lib_exists(&dir, "fancy-lib", NoVersion);
702-
assert!(os::path_exists(&dir.push("build").push("fancy_lib").push("generated.rs")));
692+
assert!(os::path_exists(&dir.push("build").push("fancy-lib").push("generated.rs")));
703693
}
704694
705695
#[test]
@@ -718,7 +708,7 @@ fn rustpkg_build_no_arg() {
718708
#[test]
719709
fn rustpkg_install_no_arg() {
720710
let tmp = mkdtemp(&os::tmpdir(),
721-
"rustpkg_install_no_arg").expect("rustpkg_build_no_arg failed");
711+
"rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed");
722712
let package_dir = tmp.push("src").push("foo");
723713
assert!(os::mkdir_recursive(&package_dir, U_RWX));
724714
writeFile(&package_dir.push("lib.rs"),
@@ -745,7 +735,6 @@ fn rustpkg_clean_no_arg() {
745735
}
746736
747737
#[test]
748-
#[ignore (reason = "Specifying env doesn't work -- see #8028")]
749738
fn rust_path_test() {
750739
let dir_for_path = mkdtemp(&os::tmpdir(), "more_rust").expect("rust_path_test failed");
751740
let dir = mk_workspace(&dir_for_path, &Path("foo"), &NoVersion);
@@ -755,20 +744,9 @@ fn rust_path_test() {
755744
let cwd = os::getcwd();
756745
debug!("cwd = %s", cwd.to_str());
757746
// use command_line_test_with_env
758-
let mut prog = run::Process::new("rustpkg",
759-
[~"install", ~"foo"],
760-
// This should actually extend the environment; then we can probably
761-
// un-ignore it
762-
run::ProcessOptions { env: Some(~[(~"RUST_LOG",
763-
~"rustpkg"),
764-
(~"RUST_PATH",
765-
dir_for_path.to_str())]),
766-
dir: Some(&cwd),
767-
in_fd: None,
768-
out_fd: None,
769-
err_fd: None
770-
});
771-
prog.finish_with_output();
747+
command_line_test_with_env([~"install", ~"foo"],
748+
&cwd,
749+
Some(~[(~"RUST_PATH", dir_for_path.to_str())]));
772750
assert_executable_exists(&dir_for_path, "foo");
773751
}
774752

src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn main() {
3838
return;
3939
}
4040

41-
let out_path = Path("build/fancy_lib");
41+
let out_path = Path("build/fancy-lib");
4242
if !os::path_exists(&out_path) {
4343
assert!(os::make_dir(&out_path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
4444
}

0 commit comments

Comments
 (0)