Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various modifications to debug and/or fix make check-stage1 #13753

Closed
wants to merge 9 commits into from
20 changes: 10 additions & 10 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ endif
# worry about the distribution of one file (with its native dynamic
# dependencies)
RUSTFLAGS_STAGE0 += -C prefer-dynamic
RUSTFLAGS_STAGE1 += -C prefer-dynamic
RUSTFLAGS_STAGE1 += -C prefer-dynamic --install-prefix $(CFG_BUILD_DIR)/$(CFG_HOST)/stage1

# platform-specific auto-configuration
include $(CFG_SRC_DIR)mk/platform.mk
Expand Down Expand Up @@ -357,13 +357,19 @@ endef
define SREQ_CMDS

ifeq ($$(OSTYPE_$(3)),apple-darwin)
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
else
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
endif

RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))

# Pass --cfg stage0 only for the build->host part of stage0;
# if you're building a cross config, the host->* parts are
# effectively stage1, since it uses the just-built stage0.
Expand All @@ -379,13 +385,7 @@ ifeq ($(1),0)
ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1

ifeq ($$(OSTYPE_$(3)),apple-darwin)
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
else
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
endif
RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
endif
endif

Expand Down
4 changes: 3 additions & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
"$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
"$$(TESTNAME)" \
"$$(RPATH_VAR$(1)_T_$(2)_H_$(3))"
"$$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))" \
"$$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))" \
RUST_BUILD_STAGE=$(1)
@touch $$@
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
Expand Down
11 changes: 8 additions & 3 deletions src/etc/maketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
os.putenv('CC', sys.argv[5])
os.putenv('RUSTDOC', os.path.abspath(sys.argv[6]))
filt = sys.argv[7]
ldpath = sys.argv[8]
if ldpath != '':
os.putenv(ldpath.split('=')[0], ldpath.split('=')[1])
os.putenv('HOST_RPATH_ENV', sys.argv[8]);
host_ldpath = sys.argv[8]
#if host_ldpath != '':
# os.putenv(host_ldpath.split('=')[0], host_ldpath.split('=')[1])
os.putenv('TARGET_RPATH_ENV', sys.argv[9]);
rust_build_stage = sys.argv[10];
if rust_build_stage != '':
os.putenv('RUST_BUILD_STAGE', rust_build_stage.split('=')[1])

if not filt in sys.argv[1]:
sys.exit(0)
Expand Down
25 changes: 12 additions & 13 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
l.map(|p| p.clone())
}).collect::<~[_]>();

let rpaths = get_rpaths(os, sysroot, output, libs,
sess.opts.target_triple);
let rpaths = get_rpaths(sess, os, sysroot, output, libs);
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
flags
}
Expand All @@ -61,11 +60,12 @@ pub fn rpaths_to_flags(rpaths: &[~str]) -> Vec<~str> {
return ret;
}

fn get_rpaths(os: abi::Os,
fn get_rpaths(sess: &Session,
os: abi::Os,
sysroot: &Path,
output: &Path,
libs: &[Path],
target_triple: &str) -> Vec<~str> {
libs: &[Path]) -> Vec<~str> {
let target_triple = sess.opts.target_triple.as_slice();
debug!("sysroot: {}", sysroot.display());
debug!("output: {}", output.display());
debug!("libs:");
Expand All @@ -80,7 +80,8 @@ fn get_rpaths(os: abi::Os,
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);

// And a final backup rpath to the global library location.
let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
let fallback_rpaths = vec!(install_prefix_to_rpath(sess.install_prefix(),
sysroot, target_triple));

fn log_rpaths(desc: &str, rpaths: &[~str]) {
debug!("{} rpaths:", desc);
Expand Down Expand Up @@ -132,11 +133,9 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
}

pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
let install_prefix = env!("CFG_PREFIX");

fn install_prefix_to_rpath(install_prefix: Path, sysroot: &Path, target_triple: &str) -> ~str {
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
let mut path = Path::new(install_prefix);
let mut path = install_prefix;
path.push(&tlib);
let path = os::make_absolute(&path);
// FIXME (#9639): This needs to handle non-utf8 paths
Expand All @@ -156,7 +155,7 @@ pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {

#[cfg(unix, test)]
mod test {
use back::rpath::get_install_prefix_rpath;
use back::rpath::install_prefix_to_rpath;
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
use syntax::abi;
use metadata::filesearch;
Expand All @@ -170,8 +169,8 @@ mod test {
#[test]
fn test_prefix_rpath() {
let sysroot = filesearch::get_or_default_sysroot();
let res = get_install_prefix_rpath(&sysroot, "triple");
let mut d = Path::new(env!("CFG_PREFIX"));
let res = install_prefix_to_rpath(d.clone(), &sysroot, "triple");
d.push("lib");
d.push(filesearch::rustlibdir());
d.push("triple/lib");
Expand All @@ -184,7 +183,7 @@ mod test {
#[test]
fn test_prefix_rpath_abs() {
let sysroot = filesearch::get_or_default_sysroot();
let res = get_install_prefix_rpath(&sysroot, "triple");
let res = install_prefix_to_rpath(env!("CFG_PREFIX"), &sysroot, "triple");
assert!(Path::new(res).is_absolute());
}

Expand Down
5 changes: 5 additions & 0 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
}

let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
let install_prefix_opt = matches.opt_str("install-prefix").map(|m| Path::new(m));
let target = matches.opt_str("target").unwrap_or(host_triple().to_owned());
let opt_level = {
if (debugging_opts & session::NO_OPT) != 0 {
Expand Down Expand Up @@ -978,6 +979,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
write_dependency_info: write_dependency_info,
print_metas: print_metas,
cg: cg,
maybe_install_prefix_override: install_prefix_opt,
}
}

Expand Down Expand Up @@ -1118,6 +1120,9 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
"Output dependency info to <filename> after compiling, \
in a format suitable for use by Makefiles", "FILENAME"),
optopt("", "sysroot", "Override the system root", "PATH"),
optopt("", "install-prefix", format!("Override the install prefix ({:s})",
option_env!("CFG_PREFIX").unwrap_or(
"unset")), "PATH"),
optflag("", "test", "Build a test harness"),
optopt("", "target", "Target triple cpu-manufacturer-kernel[-os]
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pub struct Options {
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
pub print_metas: (bool, bool, bool),
pub cg: CodegenOptions,
/// If set, use path as install prefix; otherwise use `env!("CFG_PREFIX")`
pub maybe_install_prefix_override: Option<Path>,
}

// The type of entry function, so
Expand Down Expand Up @@ -338,6 +340,15 @@ impl Session {
host_triple(),
&self.opts.addl_lib_search_paths)
}

pub fn install_prefix<'a>(&'a self) -> Path {
Path::new(self.opts.maybe_install_prefix_override.clone()
.or(option_env!("CFG_PREFIX").map(Path::new))
.unwrap_or_else(|| {
fail!("built without CFG_PREFIX set; \
set install prefix via command line.")
}))
}
}

/// Some reasonable defaults
Expand All @@ -361,6 +372,7 @@ pub fn basic_options() -> Options {
write_dependency_info: (false, None),
print_metas: (false, false, false),
cg: basic_codegen_options(),
maybe_install_prefix_override: None,
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use back::svh::Svh;
use driver::session::Session;
use driver::{driver, session};
use metadata::cstore;
use metadata::cstore::CStore;
use metadata::cstore::{CStore, CrateSource};
use metadata::decoder;
use metadata::loader;
use metadata::loader::CratePaths;
Expand Down Expand Up @@ -68,10 +68,15 @@ impl<'a> visit::Visitor<()> for Env<'a> {

fn dump_crates(cstore: &CStore) {
debug!("resolved crates:");
cstore.iter_crate_data(|_, data| {
cstore.iter_crate_data_origins(|_, data, opt_source| {
debug!("crate_id: {}", data.crate_id());
debug!(" cnum: {}", data.cnum);
debug!(" hash: {}", data.hash());
opt_source.map(|cs| {
let CrateSource { dylib, rlib, cnum: _ } = cs;
dylib.map(|dl| debug!(" dylib: {}", dl.display()));
rlib.map(|rl| debug!(" rlib: {}", rl.display()));
});
})
}

Expand Down
11 changes: 11 additions & 0 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ impl CStore {
}
}

/// Like `iter_crate_data`, but passes source paths (if available) as well.
pub fn iter_crate_data_origins(&self, i: |ast::CrateNum,
&crate_metadata,
Option<CrateSource>|) {
for (&k, v) in self.metas.borrow().iter() {
let origin = self.get_used_crate_source(k);
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
i(k, &**v, origin);
}
}

pub fn add_used_crate_source(&self, src: CrateSource) {
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
if !used_crate_sources.contains(&src) {
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) {
None => return
};

debug!("load_extern_macros: mapped crate {} to path {} and registrar {:s}",
crate_name, path.display(), registrar);

let lib = match DynamicLibrary::open(Some(&path)) {
Ok(lib) => lib,
// this is fatal: there are almost certainly macros we need
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/bootstrap-from-c-with-green/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
all:
$(RUSTC) lib.rs
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
$(CC) main.c -o $(call RUN,main) -lboot
$(CC) main.c -o $(call RUN_BINFILE,main) -lboot
$(call RUN,main)
rm $(call DYLIB,boot)
$(call FAIL,main)
2 changes: 1 addition & 1 deletion src/test/run-make/bootstrap-from-c-with-native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
all:
$(RUSTC) lib.rs
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
$(CC) main.c -o $(call RUN,main) -lboot
$(CC) main.c -o $(call RUN_BINFILE,main) -lboot
$(call RUN,main)
rm $(call DYLIB,boot)
$(call FAIL,main)
2 changes: 1 addition & 1 deletion src/test/run-make/c-link-to-rust-dylib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
all:
$(RUSTC) foo.rs
ln -s $(call DYLIB,foo-*) $(call DYLIB,foo)
$(CC) bar.c -lfoo -o $(call RUN,bar) -Wl,-rpath,$(TMPDIR)
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -Wl,-rpath,$(TMPDIR)
$(call RUN,bar)
rm $(call DYLIB,foo)
$(call FAIL,bar)
2 changes: 1 addition & 1 deletion src/test/run-make/c-link-to-rust-staticlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifneq ($(shell uname),FreeBSD)
all:
$(RUSTC) foo.rs
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
$(call RUN,bar)
rm $(call STATICLIB,foo*)
$(call RUN,bar)
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/lto-smoke-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ CC := $(CC:-g=)
all:
$(RUSTC) foo.rs -Z lto
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
$(call RUN,bar)
15 changes: 14 additions & 1 deletion src/test/run-make/lto-syntax-extension/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
-include ../tools.mk

all:
# This test attempts to use syntax extensions, which are known to be
# incompatible with stage1 at the moment.

ifeq ($(RUST_BUILD_STAGE),"1")
DOTEST=
endif
ifeq ($(RUST_BUILD_STAGE),"2")
DOTEST=dotest
endif

all: $(DOTEST)

dotest:
env
$(RUSTC) lib.rs
$(RUSTC) main.rs -Z lto
$(call RUN,main)
9 changes: 7 additions & 2 deletions src/test/run-make/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ export DYLD_LIBRARY_PATH:=$(TMPDIR):$(DYLD_LIBRARY_PATH)
RUSTC := $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
CC := $(CC) -L $(TMPDIR)

RUN = $(TMPDIR)/$(1)
FAILS = $(TMPDIR)/$(1) && exit 1 || exit 0
# This is the name of the binary we will generate and run; use this
# e.g. for `$(CC) -o $(RUN_BINFILE)`.
RUN_BINFILE = $(TMPDIR)/$(1)
# This the basic way we will invoke the generated binary. It sets the
# LD_LIBRARY_PATH environment variable before running the binary.
RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
FAILS = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0

RLIB_GLOB = lib$(1)*.rlib
STATICLIB = $(TMPDIR)/lib$(1).a
Expand Down
15 changes: 14 additions & 1 deletion src/test/run-make/unicode-input/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
-include ../tools.mk

all:
# This test attempts to run rustc itself from the compiled binary; but
# that means that you need to set the LD_LIBRARY_PATH for rustc itself
# while running muliple_files, and that won't work for stage1.

ifeq ($(RUST_BUILD_STAGE),"1")
DOTEST=
endif
ifeq ($(RUST_BUILD_STAGE),"2")
DOTEST=dotest
endif

all: $(DOTEST)

dotest:
# check that we don't ICE on unicode input, issue #11178
$(RUSTC) multiple_files.rs
$(call RUN,multiple_files) "$(RUSTC)" "$(TMPDIR)"
Expand Down