Skip to content

Commit

Permalink
rustbuild: make libdir_relative a method
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 20, 2018
1 parent 80970e6 commit 8174c0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,11 @@ impl<'a> Builder<'a> {

fn run(self, builder: &Builder) -> Interned<PathBuf> {
let compiler = self.compiler;
let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() {
builder.build.config.libdir_relative.clone().unwrap()
let config = &builder.build.config;
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
builder.build.config.libdir_relative().unwrap()
} else {
PathBuf::from("lib")
Path::new("lib")
};
let sysroot = builder.sysroot(self.compiler).join(lib)
.join("rustlib").join(self.target).join("lib");
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
.env("CFG_VERSION", build.rust_version())
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());

let libdir_relative =
build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib"));
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);

// If we're not building a compiler with debugging information then remove
Expand Down
30 changes: 12 additions & 18 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process;
use std::cmp;

Expand Down Expand Up @@ -126,7 +126,6 @@ pub struct Config {
pub docdir: Option<PathBuf>,
pub bindir: Option<PathBuf>,
pub libdir: Option<PathBuf>,
pub libdir_relative: Option<PathBuf>,
pub mandir: Option<PathBuf>,
pub codegen_tests: bool,
pub nodejs: Option<PathBuf>,
Expand Down Expand Up @@ -418,22 +417,6 @@ impl Config {
config.mandir = install.mandir.clone().map(PathBuf::from);
}

// Try to infer `libdir_relative` from `libdir`.
if let Some(ref libdir) = config.libdir {
let mut libdir = libdir.as_path();
if !libdir.is_relative() {
// Try to make it relative to the prefix.
if let Some(ref prefix) = config.prefix {
if let Ok(suffix) = libdir.strip_prefix(prefix) {
libdir = suffix;
}
}
}
if libdir.is_relative() {
config.libdir_relative = Some(libdir.to_path_buf());
}
}

// Store off these values as options because if they're not provided
// we'll infer default values for them later
let mut thinlto = None;
Expand Down Expand Up @@ -581,6 +564,17 @@ impl Config {
config
}

/// Try to find the relative path of `libdir`.
pub fn libdir_relative(&self) -> Option<&Path> {
let libdir = self.libdir.as_ref()?;
if libdir.is_relative() {
Some(libdir)
} else {
// Try to make it relative to the prefix.
libdir.strip_prefix(self.prefix.as_ref()?).ok()
}
}

pub fn verbose(&self) -> bool {
self.verbose > 0
}
Expand Down

0 comments on commit 8174c0d

Please sign in to comment.