91319e80f8
To allow for multiple versions in the future we need to include the version info for the patches.
108 lines
4.0 KiB
Diff
108 lines
4.0 KiB
Diff
From 0535c75086a9c170d8d4d99b3030d9136ea6e2c7 Mon Sep 17 00:00:00 2001
|
|
From: Cody P Schafer <dev@codyps.com>
|
|
Date: Tue, 18 Nov 2014 01:40:21 -0500
|
|
Subject: [PATCH 02/11] Target: add default target.json path:
|
|
$libdir/rust/targets
|
|
|
|
---
|
|
src/librustc/session/config.rs | 6 +++---
|
|
src/librustc/session/mod.rs | 8 ++++++--
|
|
src/librustc_back/target/mod.rs | 13 +++++++++++--
|
|
3 files changed, 20 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
|
|
index da5555d..6cd0ea9 100644
|
|
--- a/src/librustc/session/config.rs
|
|
+++ b/src/librustc/session/config.rs
|
|
@@ -35,7 +35,7 @@ use getopts;
|
|
use std::collections::HashMap;
|
|
use std::env;
|
|
use std::fmt;
|
|
-use std::path::PathBuf;
|
|
+use std::path::{Path, PathBuf};
|
|
|
|
pub struct Config {
|
|
pub target: Target,
|
|
@@ -787,8 +787,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
|
v
|
|
}
|
|
|
|
-pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
|
- let target = match Target::search(&opts.target_triple) {
|
|
+pub fn build_target_config(sysroot: &Path, opts: &Options, sp: &Handler) -> Config {
|
|
+ let target = match Target::search(sysroot, &opts.target_triple[..]) {
|
|
Ok(t) => t,
|
|
Err(e) => {
|
|
panic!(sp.fatal(&format!("Error loading target specification: {}", e)));
|
|
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
|
|
index 907241d..d0e3743 100644
|
|
--- a/src/librustc/session/mod.rs
|
|
+++ b/src/librustc/session/mod.rs
|
|
@@ -470,13 +470,17 @@ pub fn build_session_(sopts: config::Options,
|
|
codemap: Rc<codemap::CodeMap>,
|
|
cstore: Rc<for<'a> CrateStore<'a>>)
|
|
-> Session {
|
|
- let host = match Target::search(config::host_triple()) {
|
|
+ let sysroot = match sopts.maybe_sysroot {
|
|
+ Some(ref x) => PathBuf::from(x),
|
|
+ None => filesearch::get_or_default_sysroot()
|
|
+ };
|
|
+ let host = match Target::search(&sysroot, config::host_triple()) {
|
|
Ok(t) => t,
|
|
Err(e) => {
|
|
panic!(span_diagnostic.fatal(&format!("Error loading host specification: {}", e)));
|
|
}
|
|
};
|
|
- let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
|
+ let target_cfg = config::build_target_config(&sysroot, &sopts, &span_diagnostic);
|
|
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, codemap);
|
|
let default_sysroot = match sopts.maybe_sysroot {
|
|
Some(_) => None,
|
|
diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs
|
|
index 2163a8a..38607f0 100644
|
|
--- a/src/librustc_back/target/mod.rs
|
|
+++ b/src/librustc_back/target/mod.rs
|
|
@@ -48,6 +48,8 @@ use serialize::json::Json;
|
|
use std::default::Default;
|
|
use std::io::prelude::*;
|
|
use syntax::abi::Abi;
|
|
+use std::borrow::ToOwned;
|
|
+use std::path::Path;
|
|
|
|
mod android_base;
|
|
mod apple_base;
|
|
@@ -477,12 +479,13 @@ impl Target {
|
|
///
|
|
/// The error string could come from any of the APIs called, including
|
|
/// filesystem access and JSON decoding.
|
|
- pub fn search(target: &str) -> Result<Target, String> {
|
|
+ pub fn search(sysroot: &Path, target: &str) -> Result<Target, String> {
|
|
use std::env;
|
|
use std::ffi::OsString;
|
|
use std::fs::File;
|
|
use std::path::{Path, PathBuf};
|
|
use serialize::json;
|
|
+ use std::iter::IntoIterator;
|
|
|
|
fn load_file(path: &Path) -> Result<Target, String> {
|
|
let mut f = File::open(path).map_err(|e| e.to_string())?;
|
|
@@ -513,8 +516,14 @@ impl Target {
|
|
.unwrap_or(OsString::new());
|
|
|
|
// FIXME 16351: add a sane default search path?
|
|
+ let mut default_path = sysroot.to_owned();
|
|
+ default_path.push(env!("CFG_LIBDIR_RELATIVE"));
|
|
+ default_path.push("rustlib");
|
|
|
|
- for dir in env::split_paths(&target_path) {
|
|
+ let paths = env::split_paths(&target_path)
|
|
+ .chain(Some(default_path).into_iter());
|
|
+
|
|
+ for dir in paths {
|
|
let p = dir.join(&path);
|
|
if p.is_file() {
|
|
return load_file(&p);
|
|
--
|
|
2.7.4
|
|
|