about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-27 13:11:58 -0700
committerbors <bors@rust-lang.org>2014-03-27 13:11:58 -0700
commit8eaada5d3922e5e39c402493a37c384699ef1756 (patch)
tree9165f26c35bfa943b6997e8c18edd3fe5ce55621 /src
parent3b04fba529860a30494a5acfbc8749bbb4fd414f (diff)
parent0f4f786b6220968a7b29ad2e587f8d7ef70cebcb (diff)
auto merge of #13151 : brson/rust/dist, r=alexcrichton,brson
A variety of stuff here, mostly aimed at making `make install` work correctly with `--libdir` and `--mandir`. `make install` again goes through `install.sh`.
Diffstat (limited to 'src')
-rw-r--r--src/etc/install.sh93
-rw-r--r--src/librustc/back/rpath.rs17
-rw-r--r--src/librustc/driver/driver.rs2
-rw-r--r--src/librustc/metadata/filesearch.rs46
4 files changed, 118 insertions, 40 deletions
diff --git a/src/etc/install.sh b/src/etc/install.sh
index 8dfc1903094..3a1ba91d01f 100644
--- a/src/etc/install.sh
+++ b/src/etc/install.sh
@@ -213,6 +213,10 @@ VAL_OPTIONS=""
 
 flag uninstall "only uninstall from the installation prefix"
 valopt prefix "/usr/local" "set installation prefix"
+# NB This isn't quite the same definition as in `configure`.
+# just using 'lib' instead of CFG_LIBDIR_RELATIVE
+valopt libdir "${CFG_PREFIX}/lib" "install libraries"
+valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
 
 if [ $HELP -eq 1 ]
 then
@@ -223,49 +227,63 @@ fi
 step_msg "validating $CFG_SELF args"
 validate_opt
 
+
+# OK, let's get installing ...
+
 # Sanity check: can we can write to the destination?
-umask 022 && mkdir -p "${CFG_PREFIX}/lib"
-need_ok "directory creation failed"
-touch "${CFG_PREFIX}/lib/rust-install-probe" 2> /dev/null
+umask 022 && mkdir -p "${CFG_LIBDIR}"
+need_ok "can't write to destination. consider 'sudo'."
+touch "${CFG_LIBDIR}/rust-install-probe" 2> /dev/null
 if [ $? -ne 0 ]
 then
-    err "can't write to destination. try again with 'sudo'."
+    err "can't write to destination. consider 'sudo'."
 fi
-rm "${CFG_PREFIX}/lib/rust-install-probe"
+rm "${CFG_LIBDIR}/rust-install-probe"
 need_ok "failed to remove install probe"
 
+# Sanity check: don't install to the directory containing the installer.
+# That would surely cause chaos.
+INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
+PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
+if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
+then
+    err "can't install to same directory as installer"
+fi
+
+# The file name of the manifest we're going to create during install
+INSTALLED_MANIFEST="${CFG_LIBDIR}/rustlib/manifest"
 
 # First, uninstall from the installation prefix.
 # Errors are warnings - try to rm everything in the manifest even if some fail.
-# FIXME: Hardcoded 'rustlib' ignores CFG_RUSTLIBDIR
-if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ]
+if [ -f "${INSTALLED_MANIFEST}" ]
 then
     # Iterate through installed manifest and remove files
     while read p; do
-        msg "removing ${CFG_PREFIX}/$p"
-        if [ -f "${CFG_PREFIX}/$p" ]
+        # The installed manifest contains absolute paths
+        msg "removing $p"
+        if [ -f "$p" ]
         then
-            rm "${CFG_PREFIX}/$p"
+            rm "$p"
             if [ $? -ne 0 ]
             then
-                warn "failed to remove ${CFG_PREFIX}/$p"
+                warn "failed to remove $p"
             fi
         else
-            warn "supposedly installed file ${CFG_PREFIX}/$p does not exist!"
+            warn "supposedly installed file $p does not exist!"
         fi
-    done < "${CFG_PREFIX}/lib/rustlib/manifest"
+    done < "${INSTALLED_MANIFEST}"
 
     # Remove 'rustlib' directory
-    msg "removing ${CFG_PREFIX}/lib/rustlib"
-    rm -r "${CFG_PREFIX}/lib/rustlib"
+    rm -r "${CFG_LIBDIR}/rustlib"
     if [ $? -ne 0 ]
     then
         warn "failed to remove rustlib"
     fi
 else
+    # There's no manifest. If we were asked to uninstall, then that's a problem.
     if [ -n "${CFG_UNINSTALL}" ]
     then
-        err "unable to find installation manifest at ${CFG_PREFIX}/lib/rustlib"
+        err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib"
     fi
 fi
 
@@ -278,24 +296,55 @@ then
     exit 0
 fi
 
+# Create the installed manifest, which we will fill in with absolute file paths
+mkdir -p "${CFG_LIBDIR}/rustlib"
+touch "${INSTALLED_MANIFEST}"
 
 # Now install, iterate through the new manifest and copy files
 while read p; do
 
-    umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)"
+    # Decide the destination of the file
+    FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
+
+    if echo "$p" | grep "^lib/" > /dev/null
+    then
+        pp=`echo $p | sed 's/^lib\///'`
+        FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
+    fi
+
+    if echo "$p" | grep "^share/man/" > /dev/null
+    then
+        pp=`echo $p | sed 's/^share\/man\///'`
+        FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
+    fi
+
+    # Make sure there's a directory for it
+    umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
     need_ok "directory creation failed"
 
-    msg "${CFG_PREFIX}/$p"
-    if echo "$p" | grep "/bin/" > /dev/null
+    # Make the path absolute so we can uninstall it later without
+    # starting from the installation cwd
+    FILE_INSTALL_PATH_DIRNAME="$(dirname ${FILE_INSTALL_PATH})"
+    FILE_INSTALL_PATH_BASENAME="$(basename ${FILE_INSTALL_PATH})"
+    FILE_INSTALL_ABS_PATH="$(cd ${FILE_INSTALL_PATH_DIRNAME} && pwd)"
+    FILE_INSTALL_PATH="${FILE_INSTALL_ABS_PATH}/${FILE_INSTALL_PATH_BASENAME}"
+
+    # Install the file
+    msg "${FILE_INSTALL_PATH}"
+    if echo "$p" | grep "^bin/" > /dev/null
     then
-        install -m755 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p"
+        install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
     else
-        install -m644 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p"
+        install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
     fi
     need_ok "file creation failed"
 
+    # Update the manifest
+    echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
+    need_ok "failed to update manifest"
+
 # The manifest lists all files to install
-done < "${CFG_SRC_DIR}/lib/rustlib/manifest"
+done < "${CFG_SRC_DIR}/lib/rustlib/manifest.in"
 
 echo
 echo "    Rust is ready to roll."
diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs
index 08e96ec9215..c47f9893cd2 100644
--- a/src/librustc/back/rpath.rs
+++ b/src/librustc/back/rpath.rs
@@ -54,8 +54,9 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
 }
 
 fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path {
-    let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
-    let mut p = sess.filesearch().sysroot.join(&r);
+    let sysroot = sess.filesearch().sysroot;
+    let r = filesearch::relative_target_lib_path(sysroot, sess.opts.target_triple);
+    let mut p = sysroot.join(&r);
     p.push(os::dll_filename("rustrt"));
     p
 }
@@ -91,7 +92,7 @@ fn get_rpaths(os: abi::Os,
     let abs_rpaths = get_absolute_rpaths(libs);
 
     // And a final backup rpath to the global library location.
-    let fallback_rpaths = vec!(get_install_prefix_rpath(target_triple));
+    let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
 
     fn log_rpaths(desc: &str, rpaths: &[~str]) {
         debug!("{} rpaths:", desc);
@@ -156,10 +157,10 @@ pub fn get_absolute_rpath(lib: &Path) -> ~str {
     p.as_str().expect("non-utf8 component in rpath").to_owned()
 }
 
-pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
+pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
     let install_prefix = env!("CFG_PREFIX");
 
-    let tlib = filesearch::relative_target_lib_path(target_triple);
+    let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
     let mut path = Path::new(install_prefix);
     path.push(&tlib);
     let path = os::make_absolute(&path);
@@ -195,7 +196,8 @@ mod test {
 
     #[test]
     fn test_prefix_rpath() {
-        let res = get_install_prefix_rpath("triple");
+        let sysroot = filesearch::get_or_default_sysroot();
+        let res = get_install_prefix_rpath(&sysroot, "triple");
         let mut d = Path::new(env!("CFG_PREFIX"));
         d.push("lib");
         d.push(filesearch::rustlibdir());
@@ -208,7 +210,8 @@ mod test {
 
     #[test]
     fn test_prefix_rpath_abs() {
-        let res = get_install_prefix_rpath("triple");
+        let sysroot = filesearch::get_or_default_sysroot();
+        let res = get_install_prefix_rpath(&sysroot, "triple");
         assert!(Path::new(res).is_absolute());
     }
 
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index fb0de959489..9ee0bb4a107 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -800,7 +800,7 @@ pub fn host_triple() -> ~str {
     // Instead of grabbing the host triple (for the current host), we grab (at
     // compile time) the target triple that this rustc is built with and
     // calling that (at runtime) the host triple.
-    (env!("CFG_COMPILER")).to_owned()
+    (env!("CFG_COMPILER_HOST_TRIPLE")).to_owned()
 }
 
 pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index fa794c88345..7aed0e5b7f4 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -60,7 +60,8 @@ impl<'a> FileSearch<'a> {
         if !found {
             let rustpath = rust_path();
             for path in rustpath.iter() {
-                let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
+                let tlib_path = make_rustpkg_target_lib_path(
+                    self.sysroot, path, self.target_triple);
                 debug!("is {} in visited_dirs? {:?}", tlib_path.display(),
                         visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
 
@@ -136,8 +137,8 @@ impl<'a> FileSearch<'a> {
     }
 }
 
-pub fn relative_target_lib_path(target_triple: &str) -> Path {
-    let mut p = Path::new(libdir());
+pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
+    let mut p = Path::new(find_libdir(sysroot));
     assert!(p.is_relative());
     p.push(rustlibdir());
     p.push(target_triple);
@@ -147,12 +148,13 @@ pub fn relative_target_lib_path(target_triple: &str) -> Path {
 
 fn make_target_lib_path(sysroot: &Path,
                         target_triple: &str) -> Path {
-    sysroot.join(&relative_target_lib_path(target_triple))
+    sysroot.join(&relative_target_lib_path(sysroot, target_triple))
 }
 
-fn make_rustpkg_target_lib_path(dir: &Path,
-                        target_triple: &str) -> Path {
-    let mut p = dir.join(libdir());
+fn make_rustpkg_target_lib_path(sysroot: &Path,
+                                dir: &Path,
+                                target_triple: &str) -> Path {
+    let mut p = dir.join(find_libdir(sysroot));
     p.push(target_triple);
     p
 }
@@ -235,12 +237,36 @@ pub fn rust_path() -> Vec<Path> {
 
 // The name of the directory rustc expects libraries to be located.
 // On Unix should be "lib", on windows "bin"
-pub fn libdir() -> ~str {
-    (env!("CFG_LIBDIR_RELATIVE")).to_owned()
+#[cfg(unix)]
+fn find_libdir(sysroot: &Path) -> ~str {
+    // FIXME: This is a quick hack to make the rustc binary able to locate
+    // Rust libraries in Linux environments where libraries might be installed
+    // to lib64/lib32. This would be more foolproof by basing the sysroot off
+    // of the directory where librustc is located, rather than where the rustc
+    // binary is.
+
+    if sysroot.join(primary_libdir_name()).join(rustlibdir()).exists() {
+        return primary_libdir_name();
+    } else {
+        return secondary_libdir_name();
+    }
+
+    #[cfg(target_word_size = "64")]
+    fn primary_libdir_name() -> ~str { ~"lib64" }
+
+    #[cfg(target_word_size = "32")]
+    fn primary_libdir_name() -> ~str { ~"lib32" }
+
+    fn secondary_libdir_name() -> ~str { ~"lib" }
+}
+
+#[cfg(windows)]
+fn find_libdir(_sysroot: &Path) -> ~str {
+    ~"bin"
 }
 
 // The name of rustc's own place to organize libraries.
 // Used to be "rustc", now the default is "rustlib"
 pub fn rustlibdir() -> ~str {
-    (env!("CFG_RUSTLIBDIR")).to_owned()
+    ~"rustlib"
 }