]> git.lizzy.rs Git - rust.git/commitdiff
rustpkg: Always write a package_id attribute into the link metadata
authorTim Chevalier <chevalier@alum.wellesley.edu>
Sat, 14 Sep 2013 01:04:45 +0000 (18:04 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Sun, 15 Sep 2013 04:42:19 +0000 (21:42 -0700)
For some reason, I thought it wasn't necessary to write the package_id
attribute (which rustc's filesearch checks when searching for a package)
if the package ID had a single component (like "foo") as opposed to multiple
components (like "foo/bar/quux"). This meant that
`extern mod quux = "an-awesome-library";` didn't work, even if an-awesome-library
existed in the RUST_PATH.

Fixed it.

src/librustpkg/tests.rs
src/librustpkg/util.rs

index 30a5e438f345870a5e94b1fb32a4994e9ae2d822..aa663a4b273201058acd69d9ac2bb195af87c34f 100644 (file)
@@ -1111,6 +1111,55 @@ fn test_extern_mod() {
     assert!(os::path_exists(&exec_file) && is_executable(&exec_file));
 }
 
+#[test]
+fn test_extern_mod_simpler() {
+    let dir = mkdtemp(&os::tmpdir(), "test_extern_mod_simpler").expect("test_extern_mod_simpler");
+    let main_file = dir.push("main.rs");
+    let lib_depend_dir = mkdtemp(&os::tmpdir(), "foo").expect("test_extern_mod_simpler");
+    let aux_dir = lib_depend_dir.push_many(["src", "rust-awesomeness"]);
+    assert!(os::mkdir_recursive(&aux_dir, U_RWX));
+    let aux_pkg_file = aux_dir.push("lib.rs");
+
+    writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() {  assert!(true); } }\n");
+    assert!(os::path_exists(&aux_pkg_file));
+
+    writeFile(&main_file,
+              "extern mod test = \"rust-awesomeness\";\nuse test::bar;\
+               fn main() { bar::assert_true(); }\n");
+
+    command_line_test([~"install", ~"rust-awesomeness"], &lib_depend_dir);
+
+    let exec_file = dir.push("out");
+    // Be sure to extend the existing environment
+    let env = Some([(~"RUST_PATH", lib_depend_dir.to_str())] + os::env());
+    let rustpkg_exec = rustpkg_exec();
+    let rustc = rustpkg_exec.with_filename("rustc");
+    debug!("RUST_PATH=%s %s %s \n --sysroot %s -o %s",
+                     lib_depend_dir.to_str(),
+                     rustc.to_str(),
+                     main_file.to_str(),
+                     test_sysroot().to_str(),
+                     exec_file.to_str());
+
+    let mut prog = run::Process::new(rustc.to_str(), [main_file.to_str(),
+                                                      ~"--sysroot", test_sysroot().to_str(),
+                                               ~"-o", exec_file.to_str()],
+                                     run::ProcessOptions {
+        env: env,
+        dir: Some(&dir),
+        in_fd: None,
+        out_fd: None,
+        err_fd: None
+    });
+    let outp = prog.finish_with_output();
+    if outp.status != 0 {
+        fail!("output was %s, error was %s",
+              str::from_utf8(outp.output),
+              str::from_utf8(outp.error));
+    }
+    assert!(os::path_exists(&exec_file) && is_executable(&exec_file));
+}
+
 #[test]
 fn test_import_rustpkg() {
     let p_id = PkgId::new("foo");
index 18928c3f169962821176104c018b497a100a2abc..71c4760f28d9e61dcb71c45e3435018697f84a9c 100644 (file)
@@ -268,10 +268,8 @@ pub fn compile_input(context: &BuildContext,
         let link_options =
             ~[attr::mk_name_value_item_str(@"name", name_to_use),
               attr::mk_name_value_item_str(@"vers", pkg_id.version.to_str().to_managed())] +
-                        if pkg_id.is_complex() {
-                        ~[attr::mk_name_value_item_str(@"package_id",
-                                                       pkg_id.path.to_str().to_managed())]
-                } else { ~[] };
+            ~[attr::mk_name_value_item_str(@"package_id",
+                                           pkg_id.path.to_str().to_managed())];
 
         debug!("link options: %?", link_options);
         crate = @ast::Crate {