Skip to content

Commit

Permalink
Fix passing CC to maketest.py when CC has arguments.
Browse files Browse the repository at this point in the history
rmake: Get all tests passing on MSVC (thanks Alex!).

For example, I configure with CC="ccache /usr/lib/icecc/bin/gcc".
  • Loading branch information
DiamondLovesYou committed Sep 1, 2015
1 parent c443b27 commit 43cc6d4
Show file tree
Hide file tree
Showing 34 changed files with 149 additions and 77 deletions.
9 changes: 7 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,10 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
@touch $$@

$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(3)))
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(3)))
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
$(S)src/test/run-make/%/Makefile \
$$(CSREQ$(1)_T_$(2)_H_$(3))
Expand All @@ -1056,15 +1060,16 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
$$(MAKE) \
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
$(3)/test/run-make/$$* \
"$$(CC_$(3))" \
'$$(CC_$(3))' \
"$$(CFG_GCCISH_CFLAGS_$(3))" \
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
"$$(TESTNAME)" \
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
"$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
"$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
$(1) \
$$(S)
$$(S) \
$(3)
@touch -r $$@.start_time $$@ && rm $$@.start_time
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
Expand Down
12 changes: 10 additions & 2 deletions src/etc/maketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import sys

target_triple = sys.argv[14]

def normalize_path(v):
"""msys1/msys2 automatically converts `/abs/path1:/abs/path2` into
Expand All @@ -22,8 +23,11 @@ def normalize_path(v):
windows paths so it is really error-prone. revert it for peace."""
v = v.replace('\\', '/')
# c:/path -> /c/path
if ':/' in v:
v = '/' + v.replace(':/', '/')
# "c:/path" -> "/c/path"
start = v.find(':/')
while start != -1:
v = v[:start - 1] + '/' + v[start - 1:start] + v[start + 1:]
start = v.find(':/')
return v


Expand All @@ -50,6 +54,10 @@ def convert_path_spec(name, value):
putenv('RUST_BUILD_STAGE', sys.argv[12])
putenv('S', os.path.abspath(sys.argv[13]))
putenv('PYTHON', sys.executable)
os.putenv('TARGET', target_triple)

if 'msvc' in target_triple:
os.putenv('IS_MSVC', '1')

if filt not in sys.argv[1]:
sys.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make/archive-duplicate-names/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
all:
mkdir $(TMPDIR)/a
mkdir $(TMPDIR)/b
$(CC) -c -o $(TMPDIR)/a/foo.o foo.c
$(CC) -c -o $(TMPDIR)/b/foo.o bar.c
$(call COMPILE_OBJ,$(TMPDIR)/a/foo.o,foo.c)
$(call COMPILE_OBJ,$(TMPDIR)/b/foo.o,bar.c)
ar crus $(TMPDIR)/libfoo.a $(TMPDIR)/a/foo.o $(TMPDIR)/b/foo.o
$(RUSTC) foo.rs
$(RUSTC) bar.rs
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make/c-dynamic-dylib/cfoo.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// ignore-license
#ifdef _WIN32
__declspec(dllexport)
#endif
int foo() { return 0; }
4 changes: 4 additions & 0 deletions src/test/run-make/c-dynamic-rlib/cfoo.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// ignore-license

#ifdef _WIN32
__declspec(dllexport)
#endif
int foo() { return 0; }
17 changes: 12 additions & 5 deletions src/test/run-make/c-link-to-rust-dylib/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
-include ../tools.mk

HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib

all:
$(RUSTC) foo.rs
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -Wl,-rpath,$(TMPDIR) $(EXTRACFLAGS)
all: $(TMPDIR)/$(call BIN,bar)
$(call RUN,bar)
$(call REMOVE_DYLIBS,foo)
$(call FAIL,bar)

ifdef IS_MSVC
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
$(CC) bar.c $(TMPDIR)/foo.lib $(call OUT_EXE,bar)
else
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -L $(TMPDIR)
endif

$(call DYLIB,foo): foo.rs
$(RUSTC) foo.rs
5 changes: 2 additions & 3 deletions src/test/run-make/c-link-to-rust-staticlib/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
-include ../tools.mk

EXTRAFLAGS := $(EXTRACFLAGS)

# FIXME: ignore freebsd
ifneq ($(shell uname),FreeBSD)
all:
$(RUSTC) foo.rs
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) $(EXTRACXXFLAGS)
$(CC) bar.c $(TMPDIR)/libfoo.a $(call OUT_EXE,bar) \
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
$(call RUN,bar)
rm $(call STATICLIB,foo*)
$(call RUN,bar)
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make/c-static-dylib/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-include ../tools.mk

all: $(call STATICLIB,cfoo)
all: $(call NATIVE_STATICLIB,cfoo)
$(RUSTC) foo.rs -C prefer-dynamic
$(RUSTC) bar.rs
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
rm $(call NATIVE_STATICLIB,cfoo)
$(call RUN,bar)
$(call REMOVE_DYLIBS,foo)
$(call FAIL,bar)
4 changes: 2 additions & 2 deletions src/test/run-make/c-static-rlib/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-include ../tools.mk

all: $(call STATICLIB,cfoo)
all: $(call NATIVE_STATICLIB,cfoo)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(call REMOVE_RLIBS,foo)
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
rm $(call NATIVE_STATICLIB,cfoo)
$(call RUN,bar)
2 changes: 1 addition & 1 deletion src/test/run-make/crate-name-priority/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ all:
rm $(TMPDIR)/$(call BIN,bar)
$(RUSTC) foo1.rs
rm $(TMPDIR)/$(call BIN,foo)
$(RUSTC) foo1.rs -o $(TMPDIR)/bar1
$(RUSTC) foo1.rs -o $(TMPDIR)/$(call BIN,bar1)
rm $(TMPDIR)/$(call BIN,bar1)
8 changes: 3 additions & 5 deletions src/test/run-make/extern-fn-generic/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-include ../tools.mk

all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) testcrate.rs -L $(TMPDIR)
$(RUSTC) test.rs -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) testcrate.rs
$(RUSTC) test.rs
$(call RUN,test) || exit 1
6 changes: 2 additions & 4 deletions src/test/run-make/extern-fn-mangle/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-include ../tools.mk

all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) test.rs -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) test.rs
$(call RUN,test) || exit 1
6 changes: 2 additions & 4 deletions src/test/run-make/extern-fn-with-packed-struct/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-include ../tools.mk

all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) test.rs -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) test.rs
$(call RUN,test) || exit 1
10 changes: 10 additions & 0 deletions src/test/run-make/extern-fn-with-packed-struct/test.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// ignore-license
// Pragma needed cause of gcc bug on windows: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991

#ifdef _MSC_VER
#pragma pack(push,1)
struct Foo {
char a;
short b;
char c;
};
#else
#pragma pack(1)
struct __attribute__((packed)) Foo {
char a;
short b;
char c;
};
#endif

struct Foo foo(struct Foo foo) {
return foo;
Expand Down
8 changes: 3 additions & 5 deletions src/test/run-make/extern-fn-with-union/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-include ../tools.mk

all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) testcrate.rs -L $(TMPDIR)
$(RUSTC) test.rs -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) testcrate.rs
$(RUSTC) test.rs
$(call RUN,test) || exit 1
2 changes: 1 addition & 1 deletion src/test/run-make/interdependent-c-libraries/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# correct to complete the linkage. If passed as "-lfoo -lbar", then the 'foo'
# library will be stripped out, and the linkage will fail.

all: $(call STATICLIB,foo) $(call STATICLIB,bar)
all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(RUSTC) main.rs -Z print-link-args
2 changes: 1 addition & 1 deletion src/test/run-make/issue-12446/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include ../tools.mk

all: $(call STATICLIB,foo)
all: $(call NATIVE_STATICLIB,foo)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(call RUN,bar)
2 changes: 1 addition & 1 deletion src/test/run-make/issue-14500/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ endif
all:
$(RUSTC) foo.rs --crate-type=rlib
$(RUSTC) bar.rs --crate-type=staticlib -C lto -L. -o $(TMPDIR)/libbar.a
$(CC) foo.c -lbar -o $(call RUN_BINFILE,foo) $(EXTRACFLAGS)
$(CC) foo.c $(TMPDIR)/libbar.a $(EXTRACFLAGS) $(call OUT_EXE,foo)
$(call RUN,foo)
2 changes: 1 addition & 1 deletion src/test/run-make/issue-15460/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include ../tools.mk

all: $(TMPDIR)/libfoo.a
all: $(call NATIVE_STATICLIB,foo)
$(RUSTC) foo.rs -C extra-filename=-383hf8 -C prefer-dynamic
$(RUSTC) bar.rs
$(call RUN,bar)
4 changes: 4 additions & 0 deletions src/test/run-make/issue-15460/foo.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// ignore-license

#ifdef _WIN32
__declspec(dllexport)
#endif
void foo() {}
2 changes: 2 additions & 0 deletions src/test/run-make/issue-15460/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(linked_from)]
#![crate_type = "dylib"]

#[link(name = "foo", kind = "static")]
#[linked_from = "foo"]
extern {
pub fn foo();
}
6 changes: 2 additions & 4 deletions src/test/run-make/issue-25581/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-include ../tools.mk

all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) test.rs -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) test.rs
$(call RUN,test) || exit 1
4 changes: 2 additions & 2 deletions src/test/run-make/issue-26092/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-include ../tools.mk

all:
$(RUSTC) -o "" blank.rs 2>&1 | \
grep 'No such file or directory'
$(BARE_RUSTC) -o "" blank.rs 2>&1 | \
grep -i 'No such file or directory'
8 changes: 5 additions & 3 deletions src/test/run-make/link-path-order/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
CORRECT_DIR=$(TMPDIR)/correct
WRONG_DIR=$(TMPDIR)/wrong

all: $(TMPDIR)/libcorrect.a $(TMPDIR)/libwrong.a
F := $(call NATIVE_STATICLIB_FILE,foo)

all: $(call NATIVE_STATICLIB,correct) $(call NATIVE_STATICLIB,wrong)
mkdir -p $(CORRECT_DIR) $(WRONG_DIR)
mv $(TMPDIR)/libcorrect.a $(CORRECT_DIR)/libfoo.a
mv $(TMPDIR)/libwrong.a $(WRONG_DIR)/libfoo.a
mv $(call NATIVE_STATICLIB,correct) $(CORRECT_DIR)/$(F)
mv $(call NATIVE_STATICLIB,wrong) $(WRONG_DIR)/$(F)
$(RUSTC) main.rs -o $(TMPDIR)/should_succeed -L $(CORRECT_DIR) -L $(WRONG_DIR)
$(call RUN,should_succeed)
$(RUSTC) main.rs -o $(TMPDIR)/should_fail -L $(WRONG_DIR) -L $(CORRECT_DIR)
Expand Down
6 changes: 2 additions & 4 deletions src/test/run-make/linkage-attr-on-static/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-include ../tools.mk

all:
$(CC) foo.c -c -o $(TMPDIR)/foo.o
$(AR) rcs $(TMPDIR)/libfoo.a $(TMPDIR)/foo.o
$(RUSTC) bar.rs -lfoo -L $(TMPDIR)
all: $(call NATIVE_STATICLIB,foo)
$(RUSTC) bar.rs
$(call RUN,bar) || exit 1
1 change: 1 addition & 0 deletions src/test/run-make/linkage-attr-on-static/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#[linkage = "external"]
static BAZ: i32 = 21;

#[link(name = "foo", kind = "static")]
extern {
fn what() -> i32;
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-make/lto-smoke-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ CC := $(CC:-g=)

all:
$(RUSTC) foo.rs -C lto
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRACFLAGS) $(EXTRACXXFLAGS)
$(CC) bar.c $(TMPDIR)/libfoo.a \
$(call OUT_EXE,bar) \
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
$(call RUN,bar)
5 changes: 5 additions & 0 deletions src/test/run-make/no-duplicate-libs/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
-include ../tools.mk

ifdef IS_MSVC
# FIXME(#27979)
all:
else
all:
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(RUSTC) main.rs
$(call RUN,main)
endif
4 changes: 0 additions & 4 deletions src/test/run-make/no-duplicate-libs/bar.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/run-make/no-duplicate-libs/foo.c

This file was deleted.

10 changes: 6 additions & 4 deletions src/test/run-make/output-type-permutations/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ all:
$(call REMOVE_RLIBS,bar)
$(call REMOVE_DYLIBS,bar)
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
rm -f $(TMPDIR)/bar.{exp,lib}
# Check that $(TMPDIR) is empty.
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

Expand Down Expand Up @@ -36,23 +37,24 @@ all:
rm $(TMPDIR)/foo
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

$(RUSTC) foo.rs --emit=link -o $(TMPDIR)/foo
$(RUSTC) foo.rs --emit=link -o $(TMPDIR)/$(call BIN,foo)
rm $(TMPDIR)/$(call BIN,foo)
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo
rm $(TMPDIR)/foo
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/foo
rm $(TMPDIR)/$(call BIN,foo) # FIXME 13794
$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/$(call BIN,foo)
rm $(TMPDIR)/$(call BIN,foo)
rm -f $(TMPDIR)/foo.{exp,lib}
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
rm $(TMPDIR)/foo
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/foo
$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/$(call BIN,foo)
rm $(TMPDIR)/$(call BIN,foo)
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

Expand Down
Loading

0 comments on commit 43cc6d4

Please sign in to comment.