Skip to content

Commit 375c5b8

Browse files
committed
Fix --disable-rpath and tests
This involved a few changes to the local build system: * Makefiles now prefer our own LD_LIBRARY_PATH over the user's LD_LIBRARY_PATH in order to support building rust with rust already installed. * The compiletest program was taught to correctly pass through the aux dir as a component of LD_LIBRARY_PATH in more situations. This change was spliced out of #14832 to consist of just the fixes to running tests without an rpath setting embedded in executables.
1 parent 56d7bbe commit 375c5b8

File tree

9 files changed

+59
-38
lines changed

9 files changed

+59
-38
lines changed

mk/main.mk

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,10 @@ endef
360360
# contains spaces which confuse make.
361361
# * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
362362
# * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
363-
#
363+
#
364364
# Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
365365
# above settings.
366-
#
366+
#
367367
define SREQ_CMDS
368368

369369
ifeq ($$(OSTYPE_$(3)),apple-darwin)
@@ -382,9 +382,9 @@ LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
382382
$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
383383

384384
HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
385-
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)):$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))
385+
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3)):$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))
386386
TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
387-
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)):$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))
387+
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3)):$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))
388388

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

mk/tests.mk

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ endif
9191
define DEF_TARGET_COMMANDS
9292

9393
ifdef CFG_UNIXY_$(1)
94-
CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
94+
CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
95+
$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
9596
endif
9697

9798
ifdef CFG_WINDOWSY_$(1)
@@ -105,13 +106,13 @@ ifdef CFG_WINDOWSY_$(1)
105106
$$(if $$(findstring stage3,$$(1)), \
106107
stage3/$$(CFG_LIBDIR_RELATIVE), \
107108
)))))/rustlib/$$(CFG_BUILD)/lib
108-
CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1))
109+
CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
109110
endif
110111

111112
# Run the compiletest runner itself under valgrind
112113
ifdef CTEST_VALGRIND
113114
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
114-
$$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(2),$$(3))
115+
$$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
115116
else
116117
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
117118
$$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
@@ -391,7 +392,7 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4
391392
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
392393
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
393394
@$$(call E, run: $$<)
394-
$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS) \
395+
$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
395396
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
396397
$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
397398
&& touch $$@

src/compiletest/procsrv.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,41 @@ use std::str;
1313
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
1414
use std::dynamic_lib::DynamicLibrary;
1515

16-
fn target_env(lib_path: &str, prog: &str) -> Vec<(String, String)> {
17-
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
18-
let mut aux_path = prog.to_string();
19-
aux_path.push_str(".libaux");
20-
16+
fn target_env(lib_path: &str, aux_path: Option<&str>) -> Vec<(String, String)> {
2117
// Need to be sure to put both the lib_path and the aux path in the dylib
2218
// search path for the child.
2319
let mut path = DynamicLibrary::search_path();
24-
path.insert(0, Path::new(aux_path));
20+
match aux_path {
21+
Some(p) => path.insert(0, Path::new(p)),
22+
None => {}
23+
}
2524
path.insert(0, Path::new(lib_path));
2625

2726
// Remove the previous dylib search path var
2827
let var = DynamicLibrary::envvar();
29-
let mut env: Vec<(String,String)> =
30-
os::env().move_iter().map(|(a,b)|(a.to_string(), b.to_string())).collect();
28+
let mut env: Vec<(String,String)> = os::env();
3129
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
3230
Some(i) => { env.remove(i); }
3331
None => {}
3432
}
3533

3634
// Add the new dylib search path var
3735
let newpath = DynamicLibrary::create_path(path.as_slice());
38-
env.push((var.to_string(),
39-
str::from_utf8(newpath.as_slice()).unwrap().to_string()));
36+
let newpath = str::from_utf8(newpath.as_slice()).unwrap().to_string();
37+
env.push((var.to_string(), newpath));
4038
return env;
4139
}
4240

4341
pub struct Result {pub status: ProcessExit, pub out: String, pub err: String}
4442

4543
pub fn run(lib_path: &str,
4644
prog: &str,
45+
aux_path: Option<&str>,
4746
args: &[String],
4847
env: Vec<(String, String)> ,
4948
input: Option<String>) -> Option<Result> {
5049

51-
let env = env.clone().append(target_env(lib_path, prog).as_slice());
50+
let env = env.clone().append(target_env(lib_path, aux_path).as_slice());
5251
match Command::new(prog).args(args).env(env.as_slice()).spawn() {
5352
Ok(mut process) => {
5453
for input in input.iter() {
@@ -69,11 +68,12 @@ pub fn run(lib_path: &str,
6968

7069
pub fn run_background(lib_path: &str,
7170
prog: &str,
71+
aux_path: Option<&str>,
7272
args: &[String],
7373
env: Vec<(String, String)> ,
7474
input: Option<String>) -> Option<Process> {
7575

76-
let env = env.clone().append(target_env(lib_path, prog).as_slice());
76+
let env = env.clone().append(target_env(lib_path, aux_path).as_slice());
7777
match Command::new(prog).args(args).env(env.as_slice()).spawn() {
7878
Ok(mut process) => {
7979
for input in input.iter() {

src/compiletest/runtest.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
230230
testfile: &Path,
231231
src: String,
232232
pretty_type: &str) -> ProcRes {
233+
let aux_dir = aux_output_dir_name(config, testfile);
233234
compose_and_run(config,
234235
testfile,
235236
make_pp_args(config,
@@ -238,6 +239,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
238239
pretty_type.to_string()),
239240
props.exec_env.clone(),
240241
config.compile_lib_path.as_slice(),
242+
Some(aux_dir.as_str().unwrap()),
241243
Some(src))
242244
}
243245

@@ -354,6 +356,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
354356

355357
procsrv::run("",
356358
config.adb_path.as_slice(),
359+
None,
357360
[
358361
"push".to_string(),
359362
exe_file.as_str().unwrap().to_string(),
@@ -365,6 +368,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
365368

366369
procsrv::run("",
367370
config.adb_path.as_slice(),
371+
None,
368372
[
369373
"forward".to_string(),
370374
"tcp:5039".to_string(),
@@ -385,6 +389,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
385389
let mut process = procsrv::run_background("",
386390
config.adb_path
387391
.as_slice(),
392+
None,
388393
[
389394
"shell".to_string(),
390395
adb_arg.clone()
@@ -425,6 +430,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
425430
status
426431
} = procsrv::run("",
427432
gdb_path.as_slice(),
433+
None,
428434
debugger_opts.as_slice(),
429435
vec!(("".to_string(), "".to_string())),
430436
None)
@@ -486,7 +492,8 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
486492
testfile,
487493
proc_args,
488494
Vec::new(),
489-
"",
495+
config.run_lib_path.as_slice(),
496+
None,
490497
None);
491498
}
492499
}
@@ -994,11 +1001,13 @@ fn exec_compiled_test(config: &Config, props: &TestProps,
9941001
}
9951002

9961003
_=> {
1004+
let aux_dir = aux_output_dir_name(config, testfile);
9971005
compose_and_run(config,
9981006
testfile,
9991007
make_run_args(config, props, testfile),
10001008
env,
10011009
config.run_lib_path.as_slice(),
1010+
Some(aux_dir.as_str().unwrap()),
10021011
None)
10031012
}
10041013
}
@@ -1045,6 +1054,7 @@ fn compose_and_run_compiler(
10451054
aux_args,
10461055
Vec::new(),
10471056
config.compile_lib_path.as_slice(),
1057+
Some(aux_dir.as_str().unwrap()),
10481058
None);
10491059
if !auxres.status.success() {
10501060
fatal_proc_rec(
@@ -1066,6 +1076,7 @@ fn compose_and_run_compiler(
10661076
args,
10671077
Vec::new(),
10681078
config.compile_lib_path.as_slice(),
1079+
Some(aux_dir.as_str().unwrap()),
10691080
input)
10701081
}
10711082

@@ -1078,9 +1089,10 @@ fn compose_and_run(config: &Config, testfile: &Path,
10781089
ProcArgs{ args, prog }: ProcArgs,
10791090
procenv: Vec<(String, String)> ,
10801091
lib_path: &str,
1092+
aux_path: Option<&str>,
10811093
input: Option<String>) -> ProcRes {
10821094
return program_output(config, testfile, lib_path,
1083-
prog, args, procenv, input);
1095+
prog, aux_path, args, procenv, input);
10841096
}
10851097

10861098
enum TargetLocation {
@@ -1189,7 +1201,8 @@ fn split_maybe_args(argstr: &Option<String>) -> Vec<String> {
11891201
}
11901202

11911203
fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String,
1192-
args: Vec<String> , env: Vec<(String, String)> ,
1204+
aux_path: Option<&str>, args: Vec<String>,
1205+
env: Vec<(String, String)>,
11931206
input: Option<String>) -> ProcRes {
11941207
let cmdline =
11951208
{
@@ -1205,6 +1218,7 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
12051218
status
12061219
} = procsrv::run(lib_path,
12071220
prog.as_slice(),
1221+
aux_path,
12081222
args.as_slice(),
12091223
env,
12101224
input).expect(format!("failed to exec `{}`", prog).as_slice());
@@ -1326,6 +1340,7 @@ fn _arm_exec_compiled_test(config: &Config,
13261340
// copy to target
13271341
let copy_result = procsrv::run("",
13281342
config.adb_path.as_slice(),
1343+
None,
13291344
[
13301345
"push".to_string(),
13311346
args.prog.clone(),
@@ -1361,6 +1376,7 @@ fn _arm_exec_compiled_test(config: &Config,
13611376
}
13621377
procsrv::run("",
13631378
config.adb_path.as_slice(),
1379+
None,
13641380
runargs.as_slice(),
13651381
vec!(("".to_string(), "".to_string())), Some("".to_string()))
13661382
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
@@ -1374,6 +1390,7 @@ fn _arm_exec_compiled_test(config: &Config,
13741390
let procsrv::Result{ out: exitcode_out, err: _, status: _ } =
13751391
procsrv::run("",
13761392
config.adb_path.as_slice(),
1393+
None,
13771394
runargs.as_slice(),
13781395
vec!(("".to_string(), "".to_string())),
13791396
Some("".to_string()))
@@ -1397,6 +1414,7 @@ fn _arm_exec_compiled_test(config: &Config,
13971414
let procsrv::Result{ out: stdout_out, err: _, status: _ } =
13981415
procsrv::run("",
13991416
config.adb_path.as_slice(),
1417+
None,
14001418
runargs.as_slice(),
14011419
vec!(("".to_string(), "".to_string())),
14021420
Some("".to_string()))
@@ -1411,6 +1429,7 @@ fn _arm_exec_compiled_test(config: &Config,
14111429
let procsrv::Result{ out: stderr_out, err: _, status: _ } =
14121430
procsrv::run("",
14131431
config.adb_path.as_slice(),
1432+
None,
14141433
runargs.as_slice(),
14151434
vec!(("".to_string(), "".to_string())),
14161435
Some("".to_string()))
@@ -1438,6 +1457,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
14381457
// FIXME (#9639): This needs to handle non-utf8 paths
14391458
let copy_result = procsrv::run("",
14401459
config.adb_path.as_slice(),
1460+
None,
14411461
[
14421462
"push".to_string(),
14431463
file.as_str()
@@ -1505,7 +1525,7 @@ fn compile_cc_with_clang_and_save_bitcode(config: &Config, _props: &TestProps,
15051525
bitcodefile.as_str().unwrap().to_string(),
15061526
testcc.as_str().unwrap().to_string())
15071527
};
1508-
compose_and_run(config, testfile, proc_args, Vec::new(), "", None)
1528+
compose_and_run(config, testfile, proc_args, Vec::new(), "", None, None)
15091529
}
15101530

15111531
fn extract_function_from_bitcode(config: &Config, _props: &TestProps,
@@ -1522,7 +1542,7 @@ fn extract_function_from_bitcode(config: &Config, _props: &TestProps,
15221542
format!("-o={}", extracted_bc.as_str().unwrap()),
15231543
bitcodefile.as_str().unwrap().to_string())
15241544
};
1525-
compose_and_run(config, testfile, proc_args, Vec::new(), "", None)
1545+
compose_and_run(config, testfile, proc_args, Vec::new(), "", None, None)
15261546
}
15271547

15281548
fn disassemble_extract(config: &Config, _props: &TestProps,
@@ -1538,7 +1558,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,
15381558
args: vec!(format!("-o={}", extracted_ll.as_str().unwrap()),
15391559
extracted_bc.as_str().unwrap().to_string())
15401560
};
1541-
compose_and_run(config, testfile, proc_args, Vec::new(), "", None)
1561+
compose_and_run(config, testfile, proc_args, Vec::new(), "", None, None)
15421562
}
15431563

15441564

src/test/run-make/rustdoc-hidden-line/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
ifndef IS_WINDOWS
55

66
all:
7-
$(RUSTDOC) --test foo.rs
8-
$(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
7+
$(HOST_RPATH_ENV) $(RUSTDOC) --test foo.rs
8+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
99
cp verify.sh $(TMPDIR)
1010
$(call RUN,verify.sh) $(TMPDIR)
1111

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-include ../tools.mk
22
all:
3-
$(RUSTDOC) -w json -o $(TMPDIR)/doc.json foo.rs
4-
$(RUSTDOC) -o $(TMPDIR)/doc $(TMPDIR)/doc.json
3+
$(HOST_RPATH_ENV) $(RUSTDOC) -w json -o $(TMPDIR)/doc.json foo.rs
4+
$(HOST_RPATH_ENV) $(RUSTDOC) -o $(TMPDIR)/doc $(TMPDIR)/doc.json
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-include ../tools.mk
22
all:
3-
$(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
3+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
44
cp verify.sh $(TMPDIR)
55
$(call RUN,verify.sh) $(TMPDIR)

src/test/run-make/tools.mk

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export LD_LIBRARY_PATH:=$(TMPDIR):$(LD_LIBRARY_PATH)
22
export DYLD_LIBRARY_PATH:=$(TMPDIR):$(DYLD_LIBRARY_PATH)
33

4-
RUSTC := $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
5-
CC := $(CC) -L $(TMPDIR)
6-
74
# These deliberately use `=` and not `:=` so that client makefiles can
85
# augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
96
HOST_RPATH_ENV = \
10-
$(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(HOST_RPATH_DIR)
7+
$(LD_LIB_PATH_ENVVAR)=$(HOST_RPATH_DIR):$$$(LD_LIB_PATH_ENVVAR)
118
TARGET_RPATH_ENV = \
12-
$(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(TARGET_RPATH_DIR)
9+
$(LD_LIB_PATH_ENVVAR)=$(TARGET_RPATH_DIR):$$$(LD_LIB_PATH_ENVVAR)
10+
11+
RUSTC := $(HOST_RPATH_ENV) $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
12+
CC := $(CC) -L $(TMPDIR)
1313

1414
# This is the name of the binary we will generate and run; use this
1515
# e.g. for `$(CC) -o $(RUN_BINFILE)`.

src/test/run-pass/logging-separate-lines.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// ignore-android
1212
// ignore-win32
13+
// exec-env:RUST_LOG=debug
1314

1415
#![feature(phase)]
1516

@@ -29,9 +30,8 @@ fn main() {
2930
return
3031
}
3132

32-
let env = [("RUST_LOG".to_string(), "debug".to_string())];
3333
let p = Command::new(args[0].as_slice())
34-
.arg("child").env(env.as_slice())
34+
.arg("child")
3535
.spawn().unwrap().wait_with_output().unwrap();
3636
assert!(p.status.success());
3737
let mut lines = str::from_utf8(p.error.as_slice()).unwrap().lines();

0 commit comments

Comments
 (0)