Skip to content

Commit 0364d60

Browse files
committed
test: Build auxiliary libraries for each test
Closes #2162
1 parent 10236f8 commit 0364d60

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

mk/tests.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ cleantestlibs:
8080
-name '*.def' -o \
8181
-name '*.bc' -o \
8282
-name '*.dSYM' -o \
83+
-name '*.libaux' -o \
8384
-name '*.out' -o \
8485
-name '*.err' \
8586
| xargs rm -rf

src/compiletest/runtest.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ actual:\n\
175175
config, props, testfile, make_typecheck_args, option::some(src))
176176
}
177177

178-
fn make_typecheck_args(config: config, _testfile: str) -> procargs {
178+
fn make_typecheck_args(config: config, testfile: str) -> procargs {
179179
let prog = config.rustc_path;
180-
let mut args = ["-", "--no-trans", "--lib", "-L", config.build_base];
180+
let mut args = ["-", "--no-trans", "--lib", "-L", config.build_base,
181+
"-L", aux_output_dir_name(config, testfile)];
181182
args += split_maybe_args(config.rustcflags);
182183
ret {prog: prog, args: args};
183184
}
@@ -290,8 +291,9 @@ type procres = {status: int, stdout: str, stderr: str, cmdline: str};
290291

291292
fn compile_test(config: config, props: test_props,
292293
testfile: str) -> procres {
294+
let link_args = ["-L", aux_output_dir_name(config, testfile)];
293295
compose_and_run_compiler(config, props, testfile,
294-
make_compile_args(_, props, [],
296+
make_compile_args(_, props, link_args,
295297
make_exe_name, _),
296298
none)
297299
}
@@ -310,11 +312,18 @@ fn compose_and_run_compiler(
310312
mk_args: fn(config: config, _testfile: str) -> procargs,
311313
input: option<str>) -> procres {
312314

315+
if props.aux_builds.is_not_empty() {
316+
ensure_dir(aux_output_dir_name(config, testfile));
317+
}
318+
319+
let extra_link_args = ["-L", aux_output_dir_name(config, testfile)];
320+
313321
vec::iter(props.aux_builds) {|rel_ab|
314322
let abs_ab = path::connect(config.aux_base, rel_ab);
315-
let auxres = compose_and_run(config, abs_ab,
316-
make_compile_args(_, props, ["--lib"],
317-
make_lib_name, _),
323+
let mk_compile_args =
324+
make_compile_args(_, props, ["--lib"] + extra_link_args,
325+
bind make_lib_name(_, _, testfile), _);
326+
let auxres = compose_and_run(config, abs_ab, mk_compile_args,
318327
config.compile_lib_path, option::none);
319328
if auxres.status != 0 {
320329
fatal_procres(
@@ -327,6 +336,13 @@ fn compose_and_run_compiler(
327336
config.compile_lib_path, input)
328337
}
329338

339+
fn ensure_dir(path: path) {
340+
if os::path_is_dir(path) { ret; }
341+
if !os::make_dir(path, 0x1c0i32) {
342+
fail #fmt("can't make dir %s", path);
343+
}
344+
}
345+
330346
fn compose_and_run(config: config, testfile: str,
331347
make_args: fn(config, str) -> procargs, lib_path: str,
332348
input: option<str>) -> procres {
@@ -346,10 +362,11 @@ fn make_compile_args(config: config, props: test_props, extras: [str],
346362
ret {prog: prog, args: args};
347363
}
348364

349-
fn make_lib_name(config: config, testfile: str) -> str {
365+
fn make_lib_name(config: config, auxfile: str, testfile: str) -> str {
350366
// what we return here is not particularly important, as it
351367
// happens; rustc ignores everything except for the directory.
352-
output_base_name(config, testfile)
368+
let auxname = output_testname(auxfile);
369+
path::connect(aux_output_dir_name(config, testfile), auxname)
353370
}
354371

355372
fn make_exe_name(config: config, testfile: str) -> str {
@@ -440,12 +457,18 @@ fn make_out_name(config: config, testfile: str, extension: str) -> str {
440457
output_base_name(config, testfile) + "." + extension
441458
}
442459

460+
fn aux_output_dir_name(config: config, testfile: str) -> str {
461+
output_base_name(config, testfile) + ".libaux"
462+
}
463+
464+
fn output_testname(testfile: str) -> str {
465+
let parts = str::split_char(path::basename(testfile), '.');
466+
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ".")
467+
}
468+
443469
fn output_base_name(config: config, testfile: str) -> str {
444470
let base = config.build_base;
445-
let filename = {
446-
let parts = str::split_char(path::basename(testfile), '.');
447-
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ".")
448-
};
471+
let filename = output_testname(testfile);
449472
#fmt["%s%s.%s", base, filename, config.stage_id]
450473
}
451474

0 commit comments

Comments
 (0)