Skip to content

Commit c052ca3

Browse files
Optimize make targets to not compile C/C++ files when not changed & skip running cpp tests when targeting an integration test
1 parent 0cb40be commit c052ca3

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Makefile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ TESTS ?=
7575
CPP_TEST_SOURCES := test/native/testRunner.cpp $(shell find test/native -name '*Test.cpp')
7676
CPP_TEST_HEADER := test/native/testRunner.hpp
7777
CPP_TEST_INCLUDES := -Isrc -Itest/native
78+
CPP_TEST_LIB_SOURCES := test/native/testRunner.cpp $(shell find test/native/libs \( -name "*.c" -o -name "*.cpp" \))
79+
CPP_TEST_BIN_SOURCES := test/native/testRunner.cpp $(shell find test/test \( -name "*.c" -o -name "*.cpp" \))
7880

7981
ifeq ($(JAVA_HOME),)
8082
JAVA_HOME:=$(shell java -cp . JavaHome)
@@ -132,8 +134,22 @@ ifneq (,$(STATIC_BINARY))
132134
CFLAGS += -static -fdata-sections -ffunction-sections -Wl,--gc-sections
133135
endif
134136

137+
# Default is to run cpp unit tests
138+
RUN_CPP_TESTS :=
135139

136-
.PHONY: all jar release build-test test clean coverage clean-coverage build-test-java build-test-cpp build-test-libs build-test-bins test-cpp test-java check-md format-md
140+
# Determine if the target should run (test-cpp is explicitly invoked, OR test is invoked and TESTS is empty)
141+
ifeq ($(filter test-cpp,$(MAKECMDGOALS)),test-cpp)
142+
RUN_CPP_TESTS := 1
143+
endif
144+
145+
ifeq ($(filter test,$(MAKECMDGOALS)),test)
146+
ifeq ($(strip $(TESTS)),)
147+
RUN_CPP_TESTS := 1
148+
endif
149+
endif
150+
151+
152+
.PHONY: all jar release build-test test clean coverage clean-coverage build-test-java build-test-cpp test-cpp test-java check-md format-md
137153

138154
all: build/bin build/lib build/$(LIB_PROFILER) build/$(ASPROF) jar build/$(JFRCONV) build/$(ASPROF_HEADER)
139155

@@ -211,20 +227,22 @@ build/$(CONVERTER_JAR): $(CONVERTER_SOURCES) $(RESOURCES)
211227

212228
build/test/cpptests: $(CPP_TEST_SOURCES) $(CPP_TEST_HEADER) $(SOURCES) $(HEADERS) $(RESOURCES) $(JAVA_HELPER_CLASSES)
213229
mkdir -p build/test
230+
ifneq ($(RUN_CPP_TESTS),)
214231
ifeq ($(MERGE),true)
215232
for f in src/*.cpp test/native/*.cpp; do echo '#include "'$$f'"'; done |\
216233
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEFS) $(INCLUDES) $(CPP_TEST_INCLUDES) -fPIC -o $@ -xc++ - $(LIBS)
217234
else
218235
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEFS) $(INCLUDES) $(CPP_TEST_INCLUDES) -fPIC -o $@ $(SOURCES) $(CPP_TEST_SOURCES) $(LIBS)
219236
endif
237+
endif
220238

221-
build-test-java: all build/$(TEST_JAR) build-test-libs build-test-bins
239+
build-test-java: all build/$(TEST_JAR) build/test/build-test-libs build/test/build-test-bins
222240

223-
build-test-cpp: build/test/cpptests build-test-libs
241+
build-test-cpp: build/test/cpptests build/test/build-test-libs
224242

225243
build-test: build-test-cpp build-test-java
226244

227-
build-test-libs:
245+
build/test/build-test-libs: $(CPP_TEST_LIB_SOURCES)
228246
@mkdir -p $(TEST_LIB_DIR)
229247
$(CC) -shared -fPIC -o $(TEST_LIB_DIR)/libreladyn.$(SOEXT) test/native/libs/reladyn.c
230248
$(CC) -shared -fPIC -o $(TEST_LIB_DIR)/libcallsmalloc.$(SOEXT) test/native/libs/callsmalloc.c
@@ -243,8 +261,9 @@ ifeq ($(OS_TAG),linux)
243261
$(AS) -o $(TEST_LIB_DIR)/twiceatzero.o test/native/libs/twiceatzero.s
244262
$(LD) -shared -o $(TEST_LIB_DIR)/libtwiceatzero.$(SOEXT) $(TEST_LIB_DIR)/twiceatzero.o --section-start=.seg1=0x4000 -z max-page-size=0x1000
245263
endif
264+
@touch $@
246265

247-
build-test-bins:
266+
build/test/build-test-bins: $(CPP_TEST_BIN_SOURCES)
248267
@mkdir -p $(TEST_BIN_DIR)
249268
$(CC) -o $(TEST_BIN_DIR)/malloc_plt_dyn test/test/nativemem/malloc_plt_dyn.c
250269
$(CC) -o $(TEST_BIN_DIR)/native_api -Isrc test/test/c/native_api.c -ldl
@@ -253,10 +272,13 @@ build-test-bins:
253272
$(CC) -o $(TEST_BIN_DIR)/preload_malloc -Isrc test/test/nativemem/preload_malloc.c -ldl
254273
$(CC) -o $(TEST_BIN_DIR)/nativemem_known_lib_crash -Isrc test/test/nativemem/nativemem_known_lib_crash.c -ldl
255274
$(CXX) -o $(TEST_BIN_DIR)/non_java_app -std=c++11 $(INCLUDES) $(CPP_TEST_INCLUDES) test/test/nonjava/non_java_app.cpp $(LIBS)
275+
@touch $@
256276

257277
test-cpp: build-test-cpp
258-
echo "Running cpp tests..."
278+
ifneq ($(RUN_CPP_TESTS),)
279+
@echo "Running cpp tests..."
259280
LD_LIBRARY_PATH="$(TEST_LIB_DIR)" DYLD_LIBRARY_PATH="$(TEST_LIB_DIR)" build/test/cpptests
281+
endif
260282

261283
test-java: build-test-java
262284
echo "Running tests against $(LIB_PROFILER)"

0 commit comments

Comments
 (0)