Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix Issue 11414 - druntime should run debug unittest
Browse files Browse the repository at this point in the history
- change druntime's makefile structure to match phobos
- define ROOT folder as generated/$(OS)/$(BUILD)/$(MODEL)
- unittest rule recursively invokes debug/release unittest
- factor out common.mak from test/*/Makefile and test debug/release
  • Loading branch information
MartinNowak committed Jul 7, 2015
1 parent e64b999 commit 5c69814
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 92 deletions.
84 changes: 63 additions & 21 deletions posix.mak
Expand Up @@ -7,6 +7,20 @@ QUIET:=@

include osmodel.mak

# Default to a release built, override with BUILD=debug
ifeq (,$(BUILD))
BUILD_WAS_SPECIFIED=0
BUILD=release
else
BUILD_WAS_SPECIFIED=1
endif

ifneq ($(BUILD),release)
ifneq ($(BUILD),debug)
$(error Unrecognized BUILD=$(BUILD), must be 'debug' or 'release')
endif
endif

DMD=../dmd/src/dmd
INSTALL_DIR=../install

Expand All @@ -23,21 +37,40 @@ else
DOTLIB:=.a
endif

DFLAGS=$(MODEL_FLAG) -conf= -O -release -dip25 -inline -w -Isrc -Iimport $(PIC)
UDFLAGS=$(MODEL_FLAG) -conf= -O -release -dip25 -w -Isrc -Iimport $(PIC)
DDOCFLAGS=-conf= -c -w -o- -Isrc -Iimport -version=CoreDdoc

CFLAGS=$(MODEL_FLAG) -O $(PIC)
# Set CFLAGS
CFLAGS=
ifneq (,$(filter cc% gcc% clang% icc% egcc%, $(CC)))
CFLAGS += $(MODEL_FLAG) -fPIC -DHAVE_UNISTD_H
ifeq ($(BUILD),debug)
CFLAGS += -g
else
CFLAGS += -O3
endif
endif
ifeq (solaris,$(OS))
CFLAGS+=-D_REENTRANT # for thread-safe errno
endif

OBJDIR=obj/$(MODEL)
# Set DFLAGS
UDFLAGS=-conf= -Isrc -Iimport -w -dip25 $(MODEL_FLAG) $(PIC)
ifeq ($(BUILD),debug)
UDFLAGS += -g -debug
DFLAGS=$(UDFLAGS)
else
UDFLAGS += -O -release
DFLAGS=$(UDFLAGS) -inline # unittests don't compile with -inline
endif

ROOT_OF_THEM_ALL = generated
ROOT = $(ROOT_OF_THEM_ALL)/$(OS)/$(BUILD)/$(MODEL)
OBJDIR=obj/$(OS)/$(BUILD)/$(MODEL)
DRUNTIME_BASE=druntime-$(OS)$(MODEL)
DRUNTIME=lib/lib$(DRUNTIME_BASE).a
DRUNTIMESO=lib/lib$(DRUNTIME_BASE).so
DRUNTIMESOOBJ=lib/lib$(DRUNTIME_BASE)so.o
DRUNTIMESOLIB=lib/lib$(DRUNTIME_BASE)so.a
DRUNTIME=$(ROOT)/libdruntime.a
DRUNTIMESO=$(ROOT)/libdruntime.so
DRUNTIMESOOBJ=$(ROOT)/libdruntime.so.o
DRUNTIMESOLIB=$(ROOT)/libdruntime.so.a

DOCFMT=

Expand All @@ -61,13 +94,15 @@ SRCS:=$(subst \,/,$(SRCS))
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux

OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/bss_section.o $(OBJDIR)/threadasm.o
OBJS= $(ROOT)/errno_c.o $(ROOT)/bss_section.o $(ROOT)/threadasm.o

# build with shared library support
SHARED=$(if $(findstring $(OS),linux freebsd),1,)

LINKDL=$(if $(findstring $(OS),linux),-L-ldl,)

MAKEFILE = $(firstword $(MAKEFILE_LIST))

######################## All of'em ##############################

ifneq (,$(SHARED))
Expand Down Expand Up @@ -119,15 +154,15 @@ $(IMPDIR)/%.d : src/%.d

################### C/ASM Targets ############################

$(OBJDIR)/%.o : src/rt/%.c
$(ROOT)/%.o : src/rt/%.c
@mkdir -p `dirname $@`
$(CC) -c $(CFLAGS) $< -o$@

$(OBJDIR)/errno_c.o : src/core/stdc/errno.c
$(ROOT)/errno_c.o : src/core/stdc/errno.c
@mkdir -p `dirname $@`
$(CC) -c $(CFLAGS) $< -o$@

$(OBJDIR)/threadasm.o : src/core/threadasm.S
$(ROOT)/threadasm.o : src/core/threadasm.S
@mkdir -p $(OBJDIR)
$(CC) -c $(CFLAGS) $< -o$@

Expand All @@ -149,61 +184,68 @@ $(DRUNTIMESOLIB): $(OBJS) $(SRCS)
$(DRUNTIME): $(OBJS) $(SRCS)
$(DMD) -lib -of$(DRUNTIME) -Xfdruntime.json $(DFLAGS) $(SRCS) $(OBJS)

UT_MODULES:=$(patsubst src/%.d,$(OBJDIR)/%,$(SRCS))
UT_MODULES:=$(patsubst src/%.d,$(ROOT)/unittest/%,$(SRCS))
HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
endif

.PHONY : unittest
ifeq (1,$(BUILD_WAS_SPECIFIED))
unittest : $(UT_MODULES) $(addsuffix /.run,$(ADDITIONAL_TESTS))
@echo done
else
unittest : unittest-debug unittest-release
unittest-%:
$(MAKE) -f $(MAKEFILE) unittest OS=$(OS) MODEL=$(MODEL) DMD=$(DMD) BUILD=$*
endif

ifeq ($(OS),freebsd)
DISABLED_TESTS =
else
DISABLED_TESTS =
endif

$(addprefix $(OBJDIR)/,$(DISABLED_TESTS)) :
$(addprefix $(ROOT)/unittest/,$(DISABLED_TESTS)) :
@echo $@ - disabled

ifeq (,$(SHARED))

$(OBJDIR)/test_runner: $(OBJS) $(SRCS) src/test_runner.d
$(ROOT)/unittest/test_runner: $(OBJS) $(SRCS) src/test_runner.d
$(DMD) $(UDFLAGS) -unittest -of$@ src/test_runner.d $(SRCS) $(OBJS) -debuglib= -defaultlib=

else

UT_DRUNTIME:=$(OBJDIR)/lib$(DRUNTIME_BASE)-ut$(DOTDLL)
UT_DRUNTIME:=$(ROOT)/unittest/libdruntime-ut$(DOTDLL)

$(UT_DRUNTIME): override PIC:=-fPIC
$(UT_DRUNTIME): UDFLAGS+=-version=Shared
$(UT_DRUNTIME): $(OBJS) $(SRCS)
$(DMD) $(UDFLAGS) -shared -unittest -of$@ $(SRCS) $(OBJS) $(LINKDL) -debuglib= -defaultlib=

$(OBJDIR)/test_runner: $(UT_DRUNTIME) src/test_runner.d
$(ROOT)/unittest/test_runner: $(UT_DRUNTIME) src/test_runner.d
$(DMD) $(UDFLAGS) -of$@ src/test_runner.d -L$(UT_DRUNTIME) -debuglib= -defaultlib=

endif

# macro that returns the module name given the src path
moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1))))

$(OBJDIR)/% : $(OBJDIR)/test_runner
$(ROOT)/unittest/% : $(ROOT)/unittest/test_runner
@mkdir -p $(dir $@)
# make the file very old so it builds and runs again if it fails
@touch -t 197001230123 $@
# run unittest in its own directory
$(QUIET)$(RUN) $(OBJDIR)/test_runner $(call moduleName,$*)
$(QUIET)$(RUN) $< $(call moduleName,$*)
# succeeded, render the file new again
@touch $@

test/init_fini/.run test/exceptions/.run: $(DRUNTIME)
test/shared/.run: $(DRUNTIMESO)

test/%/.run: test/%/Makefile
$(QUIET)$(MAKE) -C test/$* MODEL=$(MODEL) OS=$(OS) DMD=$(abspath $(DMD)) \
$(QUIET)$(MAKE) -C test/$* MODEL=$(MODEL) OS=$(OS) DMD=$(abspath $(DMD)) BUILD=$(BUILD) \
DRUNTIME=$(abspath $(DRUNTIME)) DRUNTIMESO=$(abspath $(DRUNTIMESO)) QUIET=$(QUIET) LINKDL=$(LINKDL)

#################### test for undesired white spaces ##########################
Expand Down Expand Up @@ -237,7 +279,7 @@ install: target
cp LICENSE $(INSTALL_DIR)/druntime-LICENSE.txt

clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS))
rm -rf obj lib $(IMPDIR) $(DOCDIR) druntime.zip
rm -rf $(ROOT_OF_THEM_ALL) $(IMPDIR) $(DOCDIR) druntime.zip

test/%/.clean: test/%/Makefile
$(MAKE) -C test/$* clean
Expand Down
28 changes: 28 additions & 0 deletions test/common.mak
@@ -0,0 +1,28 @@
# set from top makefile
OS:=
MODEL:=
BUILD:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:=
LDL:=$(subst -L,,$(LINKDL)) # -ldl

SRC:=src
ROOT:=./generated/$(OS)/$(BUILD)/$(MODEL)

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -defaultlib= -debuglib=
# LINK_SHARED may be set by importing makefile
DFLAGS+=$(if $(LINK_SHARED),-L$(DRUNTIMESO),-L$(DRUNTIME))
ifeq ($(BUILD),debug)
DFLAGS += -g -debug
CFLAGS += -g
else
DFLAGS += -O -release
CFLAGS += -O3
endif
23 changes: 5 additions & 18 deletions test/coverage/Makefile
@@ -1,25 +1,12 @@
# set from top makefile
OS:=
MODEL:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:=

SRC:=src
ROOT:=./obj/$(OS)/$(MODEL)
include ../common.mak

DFLAGS+=-cov

NORMAL_TESTS:=$(addprefix $(ROOT)/,$(addsuffix .done,basic))
MERGE_TESTS:=$(addprefix $(ROOT)/,$(addsuffix .done,merge merge_true))

DIFF:=diff

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIME) -defaultlib= -debuglib= -cov

.PHONY: all clean
all: $(NORMAL_TESTS) $(MERGE_TESTS)

Expand All @@ -42,4 +29,4 @@ $(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$(ROOT)/$* $<

clean:
rm -rf obj *.lst
rm -rf $(ROOT) *.lst
19 changes: 2 additions & 17 deletions test/exceptions/Makefile
@@ -1,22 +1,7 @@
# set from top makefile
OS:=
MODEL:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:=
include ../common.mak

SRC:=src
ROOT:=./obj/$(OS)/$(MODEL)
TESTS:=stderr_msg unittest_assert

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIME) -defaultlib= -debuglib=

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

Expand All @@ -40,4 +25,4 @@ $(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

clean:
rm -rf obj
rm -rf $(ROOT)
19 changes: 2 additions & 17 deletions test/init_fini/Makefile
@@ -1,22 +1,7 @@
# set from top makefile
OS:=
MODEL:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:=
include ../common.mak

SRC:=src
ROOT:=./obj/$(OS)/$(MODEL)
TESTS:=thread_join runtime_args

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIME) -defaultlib= -debuglib=

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

Expand All @@ -29,4 +14,4 @@ $(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

clean:
rm -rf obj
rm -rf $(ROOT)
24 changes: 5 additions & 19 deletions test/shared/Makefile
@@ -1,24 +1,10 @@
# set from top makefile
OS:=
MODEL:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:= # -L-ldl
LDL:=$(subst -L,,$(LINKDL)) # -ldl

SRC:=src
ROOT:=./obj/$(OS)/$(MODEL)
LINK_SHARED:=1

include ../common.mak

TESTS:=link load linkD linkDR loadDR host finalize
TESTS+=link_linkdep load_linkdep link_loaddep load_loaddep load_13414

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIMESO) -defaultlib= -debuglib=

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

Expand Down Expand Up @@ -72,4 +58,4 @@ $(ROOT)/%.so: $(SRC)/%.d $(DRUNTIMESO)
$(QUIET)$(DMD) -fPIC -shared $(DFLAGS) -of$@ $< $(LINKDL)

clean:
rm -rf obj
rm -rf $(ROOT)

0 comments on commit 5c69814

Please sign in to comment.