8220383: Incremental build is broken and inefficient
authorerikj
Tue, 12 Mar 2019 08:04:33 -0700
changeset 54076 4b4745d185eb
parent 54075 daec95ed6795
child 54077 b4f4778cf3d9
8220383: Incremental build is broken and inefficient Reviewed-by: tbell
make/CompileJavaModules.gmk
make/Images.gmk
make/common/NativeCompilation.gmk
make/common/ProcessMarkdown.gmk
make/common/TestFilesCompilation.gmk
make/hotspot/lib/CompileJvm.gmk
make/test/JtregGraalUnit.gmk
make/test/JtregNativeHotspot.gmk
make/test/JtregNativeJdk.gmk
--- a/make/CompileJavaModules.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/CompileJavaModules.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -538,8 +538,13 @@
 ################################################################################
 # If this is an imported module that has prebuilt classes, only compile
 # module-info.java.
-ifneq ($(wildcard $(IMPORT_MODULES_CLASSES)/$(MODULE)), )
-  $(MODULE)_INCLUDE_FILES := module-info.java
+ifneq ($(IMPORT_MODULES_CLASSES), )
+  IMPORT_MODULE_DIR := $(IMPORT_MODULES_CLASSES)/$(MODULE)
+  ifneq ($(wildcard $(IMPORT_MODULE_DIR)), )
+    $(MODULE)_INCLUDE_FILES := module-info.java
+  endif
+else
+  IMPORT_MODULE_DIR :=
 endif
 
 ################################################################################
@@ -645,13 +650,13 @@
 # If this is an imported module, copy the pre built classes and resources into
 # the modules output dir
 
-ifneq ($(wildcard $(IMPORT_MODULES_CLASSES)/$(MODULE)), )
+ifneq ($(wildcard $(IMPORT_MODULE_DIR)), )
   $(JDK_OUTPUTDIR)/modules/$(MODULE)/_imported.marker: \
-      $(call CacheFind, $(IMPORT_MODULES_CLASSES)/$(MODULE))
+      $(call CacheFind, $(IMPORT_MODULE_DIR))
 	$(call MakeDir, $(@D))
         # Do not delete marker and build meta data files
 	$(RM) -r $(filter-out $(@D)/_%, $(wildcard $(@D)/*))
-	$(CP) -R $(IMPORT_MODULES_CLASSES)/$(MODULE)/* $(@D)/
+	$(CP) -R $(IMPORT_MODULE_DIR)/* $(@D)/
 	$(TOUCH) $@
 
   TARGETS += $(JDK_OUTPUTDIR)/modules/$(MODULE)/_imported.marker
--- a/make/Images.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/Images.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -112,7 +112,11 @@
 JLINK_JRE_TARGETS := $(jlink_jre)
 
 ifeq ($(BUILD_CDS_ARCHIVE), true)
-  CDS_ARCHIVE := lib/server/classes.jsa
+  ifeq ($(OPENJDK_TARGET_OS), windows)
+    CDS_ARCHIVE := bin/server/classes.jsa
+  else
+    CDS_ARCHIVE := lib/server/classes.jsa
+  endif
 
   $(eval $(call SetupExecute, gen_cds_archive_jdk, \
       WARN := Creating CDS archive for jdk image, \
--- a/make/common/NativeCompilation.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/common/NativeCompilation.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -505,8 +505,9 @@
   $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
       $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
 
-  # Find all files in the source trees. Preserve order.
-  $1_SRCS := $$(foreach s, $$($1_SRC), $$(call CacheFind, $$(s)))
+  $1_SRCS_RAW = $$(call CacheFind, $$($1_SRC))
+  # Order src files according to the order of the src dirs
+  $1_SRCS := $$(foreach d, $$($1_SRC), $$(filter $$d%, $$($1_SRCS_RAW)))
   $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
   # Extract the C/C++ files.
   ifneq ($$($1_EXCLUDE_PATTERNS), )
@@ -970,10 +971,9 @@
           $$(shell $(RM) $$($1_TARGET))
         endif
         $$($1_IMPORT_LIBRARY): $$($1_TARGET)
-		$$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
-		  $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
-		)
 		$(TOUCH) $$@
+
+        $1 += $$($1_IMPORT_LIBRARY)
       endif
     endif
 
--- a/make/common/ProcessMarkdown.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/common/ProcessMarkdown.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -65,10 +65,13 @@
     endif
   endif
 
-  $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
+  # This does not need to be included in VARDEPS since it's from the actual
+  # source file. Only run the shell if the recipe gets executed below.
+  $1_$2_OPTIONS_FROM_SRC = \
+      $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
 
   ifneq ($$($1_FILTER), )
-    $1_$2_OPTIONS += --filter $$($1_FILTER)
+    $1_$2_OPTIONS := --filter $$($1_FILTER)
   endif
 
   $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \
@@ -82,8 +85,8 @@
 	$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \
 	    $$(PANDOC) $$($1_OPTIONS) -f $$(PANDOC_MARKDOWN_FLAG) \
 	    -t $$($1_FORMAT) --standalone \
-	    $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$($1_$2_PANDOC_INPUT)' \
-	    -o '$$($1_$2_PANDOC_OUTPUT)')
+	    $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS_FROM_SRC) $$($1_$2_OPTIONS) \
+	    '$$($1_$2_PANDOC_INPUT)' -o '$$($1_$2_PANDOC_OUTPUT)')
         ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
 	  TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \
 	  if [ "x$$$$TOO_LONG_LINES" != x ]; then \
--- a/make/common/TestFilesCompilation.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/common/TestFilesCompilation.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -90,8 +90,7 @@
     $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \
         NAME := $$(unprefixed_name), \
         TYPE := $$($1_COMPILATION_TYPE), \
-        SRC := $$(patsubst %/,%,$$(dir $$(file))), \
-        INCLUDE_FILES := $$(notdir $$(file)), \
+        EXTRA_FILES := $$(file), \
         OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$(name), \
         OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \
         CFLAGS := $$($1_BASE_CFLAGS) $$($1_CFLAGS) $$($1_CFLAGS_$$(name)), \
--- a/make/hotspot/lib/CompileJvm.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/hotspot/lib/CompileJvm.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -166,6 +166,9 @@
 # default.
 JVM_STRIPFLAGS ?= $(STRIPFLAGS)
 
+# This source set is reused so save in cache.
+$(eval $(call FillCacheFind, $(JVM_SRC_DIRS)))
+
 ################################################################################
 # Now set up the actual compilation of the main hotspot native library
 
--- a/make/test/JtregGraalUnit.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/test/JtregGraalUnit.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -41,115 +41,123 @@
 
 ifeq ($(INCLUDE_GRAAL), true)
   ifneq ($(GRAALUNIT_LIB), )
+
     SRC_DIR := $(TOPDIR)/src/jdk.internal.vm.compiler/share/classes
     TEST_DIR := $(TOPDIR)/test/hotspot/jtreg/compiler/graalunit
     COMPILE_OUTPUTDIR := $(SUPPORT_OUTPUTDIR)/test/graalunit
     LIB_OUTPUTDIR := $(TEST_IMAGE_DIR)/hotspot/jtreg/graal
 
-    TEST_COMPILE_CP := \
-        $(JDK_OUTPUTDIR)/modules/jdk.internal.vm.compiler \
-        $(JDK_OUTPUTDIR)/modules/jdk.internal.vm.ci \
-        $(LIB_OUTPUTDIR)/junit-4.12.jar \
-        $(LIB_OUTPUTDIR)/asm-5.0.4.jar \
-        $(LIB_OUTPUTDIR)/asm-tree-5.0.4.jar \
-        $(LIB_OUTPUTDIR)/java-allocation-instrumenter.jar \
-        $(LIB_OUTPUTDIR)/hamcrest-core-1.3.jar
+    # This evaluation is expensive and should only be done if this target was
+    # explicitly called.
+    ifneq ($(filter build-test-hotspot-jtreg-graal, $(MAKECMDGOALS)), )
+
+      TEST_COMPILE_CP := \
+          $(JDK_OUTPUTDIR)/modules/jdk.internal.vm.compiler \
+          $(JDK_OUTPUTDIR)/modules/jdk.internal.vm.ci \
+          $(LIB_OUTPUTDIR)/junit-4.12.jar \
+          $(LIB_OUTPUTDIR)/asm-5.0.4.jar \
+          $(LIB_OUTPUTDIR)/asm-tree-5.0.4.jar \
+          $(LIB_OUTPUTDIR)/java-allocation-instrumenter.jar \
+          $(LIB_OUTPUTDIR)/hamcrest-core-1.3.jar
 
-    TEST_JAVAC_FLAGS := \
-        -Xlint:none \
-        -processorpath $(BUILDTOOLS_OUTPUTDIR)/jdk.vm.compiler.replacements.verifier.jar \
-        --add-exports jdk.unsupported/sun.misc=ALL-UNNAMED \
-        --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
+      TEST_JAVAC_FLAGS := \
+          -Xlint:none \
+          -processorpath $(BUILDTOOLS_OUTPUTDIR)/jdk.vm.compiler.replacements.verifier.jar \
+          --add-exports jdk.unsupported/sun.misc=ALL-UNNAMED \
+          --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
 
-    ### Copy 3rd party libs
-    $(eval $(call SetupCopyFiles, COPY_GRAALUNIT_LIBS, \
-        FILES := $(wildcard $(GRAALUNIT_LIB)/*.jar), \
-        DEST := $(LIB_OUTPUTDIR), \
-    ))
+      ### Copy 3rd party libs
+      $(eval $(call SetupCopyFiles, COPY_GRAALUNIT_LIBS, \
+          FILES := $(wildcard $(GRAALUNIT_LIB)/*.jar), \
+          DEST := $(LIB_OUTPUTDIR), \
+      ))
 
-    TARGETS_EXTRA_LIB += $(COPY_GRAALUNIT_LIBS)
+      TARGETS_EXTRA_LIB += $(COPY_GRAALUNIT_LIBS)
 
-    ### Compile graalunit tests
-    $(eval $(call SetupJavaCompilation, BUILD_VM_COMPILER_TESTS, \
-        SETUP := GENERATE_USINGJDKBYTECODE, \
-        SRC := \
-            $(SRC_DIR)/jdk.internal.vm.compiler.collections.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.api.directives.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.api.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.asm.aarch64.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.asm.amd64.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.asm.sparc.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.asm.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.core.aarch64.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.core.amd64.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.core.jdk9.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.core.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.debug.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.graph.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.hotspot.amd64.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.hotspot.lir.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.hotspot.sparc.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.hotspot.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.jtt/src \
-            $(SRC_DIR)/org.graalvm.compiler.lir.jtt/src \
-            $(SRC_DIR)/org.graalvm.compiler.lir.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.loop.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.nodes.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.options.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.phases.common.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.replacements.jdk12.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.replacements.jdk9.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.replacements.test/src \
-            $(SRC_DIR)/org.graalvm.compiler.test/src \
-            $(SRC_DIR)/org.graalvm.util.test/src \
-            , \
-        EXCLUDE_FILES := org/graalvm/compiler/core/test/VerifyDebugUsageTest.java, \
-        BIN := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
-        CLASSPATH := $(TEST_COMPILE_CP), \
-        ADD_JAVAC_FLAGS := $(TEST_JAVAC_FLAGS), \
-    ))
+      ### Compile graalunit tests
+      $(eval $(call SetupJavaCompilation, BUILD_VM_COMPILER_TESTS, \
+          SETUP := GENERATE_USINGJDKBYTECODE, \
+          SRC := \
+              $(SRC_DIR)/jdk.internal.vm.compiler.collections.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.api.directives.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.api.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.asm.aarch64.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.asm.amd64.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.asm.sparc.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.asm.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.core.aarch64.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.core.amd64.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.core.jdk9.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.core.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.debug.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.graph.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.hotspot.amd64.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.hotspot.lir.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.hotspot.sparc.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.hotspot.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.jtt/src \
+              $(SRC_DIR)/org.graalvm.compiler.lir.jtt/src \
+              $(SRC_DIR)/org.graalvm.compiler.lir.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.loop.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.nodes.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.options.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.phases.common.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.replacements.jdk12.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.replacements.jdk9.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.replacements.test/src \
+              $(SRC_DIR)/org.graalvm.compiler.test/src \
+              $(SRC_DIR)/org.graalvm.util.test/src \
+              , \
+          EXCLUDE_FILES := org/graalvm/compiler/core/test/VerifyDebugUsageTest.java, \
+          BIN := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
+          CLASSPATH := $(TEST_COMPILE_CP), \
+          ADD_JAVAC_FLAGS := $(TEST_JAVAC_FLAGS), \
+      ))
+
+      TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS)
 
-    TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS)
+      ### Compile graalunit tests which require -XDstringConcat=inline
+      $(eval $(call SetupJavaCompilation, BUILD_VM_COMPILER_TESTS_SET2, \
+          SETUP := GENERATE_USINGJDKBYTECODE, \
+          DEPENDS := $(BUILD_VM_COMPILER_TESTS), \
+          SRC := $(SRC_DIR)/org.graalvm.compiler.core.test/src, \
+          INCLUDE_FILES := org/graalvm/compiler/core/test/VerifyDebugUsageTest.java, \
+          BIN := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
+          CLASSPATH := \
+              $(TEST_COMPILE_CP) \
+              $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests \
+              , \
+          ADD_JAVAC_FLAGS := \
+              $(TEST_JAVAC_FLAGS) \
+              -XDstringConcat=inline \
+              , \
+      ))
 
-    ### Compile graalunit tests which require -XDstringConcat=inline
-    $(eval $(call SetupJavaCompilation, BUILD_VM_COMPILER_TESTS_SET2, \
-        SETUP := GENERATE_USINGJDKBYTECODE, \
-        DEPENDS := $(BUILD_VM_COMPILER_TESTS), \
-        SRC := $(SRC_DIR)/org.graalvm.compiler.core.test/src, \
-        INCLUDE_FILES := org/graalvm/compiler/core/test/VerifyDebugUsageTest.java, \
-        BIN := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
-        CLASSPATH := \
-            $(TEST_COMPILE_CP) \
-            $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests \
-            , \
-        ADD_JAVAC_FLAGS := \
-            $(TEST_JAVAC_FLAGS) \
-            -XDstringConcat=inline \
-            , \
-    ))
-
-    TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS_SET2)
+      TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS_SET2)
 
-    ### Generate jdk.vm.compiler.tests.jar
-    $(eval $(call SetupJarArchive, BUILD_VM_COMPILER_TESTS_JAR, \
-        DEPENDENCIES := $(BUILD_VM_COMPILER_TESTS) $(BUILD_VM_COMPILER_TESTS_SET2), \
-        SRCS := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
-        JAR := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests.jar, \
-    ))
+      ### Generate jdk.vm.compiler.tests.jar
+      $(eval $(call SetupJarArchive, BUILD_VM_COMPILER_TESTS_JAR, \
+          DEPENDENCIES := $(BUILD_VM_COMPILER_TESTS) $(BUILD_VM_COMPILER_TESTS_SET2), \
+          SRCS := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests, \
+          JAR := $(COMPILE_OUTPUTDIR)/jdk.vm.compiler.tests.jar, \
+      ))
 
-    TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS_JAR)
+      TARGETS_BUILD += $(BUILD_VM_COMPILER_TESTS_JAR)
 
-    ### Compile and build mxtool
-    $(eval $(call SetupJavaCompilation, BUILD_MXTOOL, \
-        SETUP := GENERATE_USINGJDKBYTECODE, \
-        SRC := $(TEST_DIR)/com.oracle.mxtool.junit, \
-        BIN := $(COMPILE_OUTPUTDIR)/com.oracle.mxtool.junit, \
-        JAR := $(COMPILE_OUTPUTDIR)/com.oracle.mxtool.junit.jar, \
-        CLASSPATH := $(LIB_OUTPUTDIR)/junit-4.12.jar, \
-    ))
+      ### Compile and build mxtool
+      $(eval $(call SetupJavaCompilation, BUILD_MXTOOL, \
+          SETUP := GENERATE_USINGJDKBYTECODE, \
+          SRC := $(TEST_DIR)/com.oracle.mxtool.junit, \
+          BIN := $(COMPILE_OUTPUTDIR)/com.oracle.mxtool.junit, \
+          JAR := $(COMPILE_OUTPUTDIR)/com.oracle.mxtool.junit.jar, \
+          CLASSPATH := $(LIB_OUTPUTDIR)/junit-4.12.jar, \
+      ))
 
-    TARGETS_BUILD += $(BUILD_MXTOOL)
+      TARGETS_BUILD += $(BUILD_MXTOOL)
 
+      $(TARGETS_BUILD): $(TARGETS_EXTRA_LIB)
+
+    endif # build-test-hotspot-jtreg-graal
 
     ################################################################################
     # Targets for building test-image.
@@ -168,7 +176,6 @@
   endif
 endif
 
-$(TARGETS_BUILD): $(TARGETS_EXTRA_LIB)
 build-test-hotspot-jtreg-graal: $(TARGETS_BUILD)
 test-image-hotspot-jtreg-graal: $(TARGETS_IMAGE)
 
--- a/make/test/JtregNativeHotspot.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/test/JtregNativeHotspot.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -1513,19 +1513,23 @@
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libterminatedThread += -lpthread
 endif
 
-$(eval $(call SetupTestFilesCompilation, BUILD_HOTSPOT_JTREG_LIBRARIES, \
-    TYPE := LIBRARY, \
-    SOURCE_DIRS := $(BUILD_HOTSPOT_JTREG_NATIVE_SRC), \
-    OUTPUT_DIR := $(BUILD_HOTSPOT_JTREG_OUTPUT_DIR), \
-    EXCLUDE := $(BUILD_HOTSPOT_JTREG_EXCLUDE), \
-))
+# This evaluation is expensive and should only be done if this target was
+# explicitly called.
+ifneq ($(filter build-test-hotspot-jtreg-native, $(MAKECMDGOALS)), )
+  $(eval $(call SetupTestFilesCompilation, BUILD_HOTSPOT_JTREG_LIBRARIES, \
+      TYPE := LIBRARY, \
+      SOURCE_DIRS := $(BUILD_HOTSPOT_JTREG_NATIVE_SRC), \
+      OUTPUT_DIR := $(BUILD_HOTSPOT_JTREG_OUTPUT_DIR), \
+      EXCLUDE := $(BUILD_HOTSPOT_JTREG_EXCLUDE), \
+  ))
 
-$(eval $(call SetupTestFilesCompilation, BUILD_HOTSPOT_JTREG_EXECUTABLES, \
-    TYPE := PROGRAM, \
-    SOURCE_DIRS := $(BUILD_HOTSPOT_JTREG_NATIVE_SRC), \
-    OUTPUT_DIR := $(BUILD_HOTSPOT_JTREG_OUTPUT_DIR), \
-    EXCLUDE := $(BUILD_HOTSPOT_JTREG_EXCLUDE), \
-))
+  $(eval $(call SetupTestFilesCompilation, BUILD_HOTSPOT_JTREG_EXECUTABLES, \
+      TYPE := PROGRAM, \
+      SOURCE_DIRS := $(BUILD_HOTSPOT_JTREG_NATIVE_SRC), \
+      OUTPUT_DIR := $(BUILD_HOTSPOT_JTREG_OUTPUT_DIR), \
+      EXCLUDE := $(BUILD_HOTSPOT_JTREG_EXCLUDE), \
+  ))
+endif
 
 build-test-hotspot-jtreg-native: $(BUILD_HOTSPOT_JTREG_LIBRARIES) $(BUILD_HOTSPOT_JTREG_EXECUTABLES)
 
--- a/make/test/JtregNativeJdk.gmk	Tue Mar 12 14:35:26 2019 +0000
+++ b/make/test/JtregNativeJdk.gmk	Tue Mar 12 08:04:33 2019 -0700
@@ -82,19 +82,23 @@
   BUILD_JDK_JTREG_EXCLUDE += exeJniInvocationTest.c
 endif
 
-$(eval $(call SetupTestFilesCompilation, BUILD_JDK_JTREG_LIBRARIES, \
-    TYPE := LIBRARY, \
-    SOURCE_DIRS := $(BUILD_JDK_JTREG_NATIVE_SRC), \
-    OUTPUT_DIR := $(BUILD_JDK_JTREG_OUTPUT_DIR), \
-    EXCLUDE := $(BUILD_JDK_JTREG_EXCLUDE), \
-))
+# This evaluation is expensive and should only be done if this target was
+# explicitly called.
+ifneq ($(filter build-test-jdk-jtreg-native, $(MAKECMDGOALS)), )
+  $(eval $(call SetupTestFilesCompilation, BUILD_JDK_JTREG_LIBRARIES, \
+      TYPE := LIBRARY, \
+      SOURCE_DIRS := $(BUILD_JDK_JTREG_NATIVE_SRC), \
+      OUTPUT_DIR := $(BUILD_JDK_JTREG_OUTPUT_DIR), \
+      EXCLUDE := $(BUILD_JDK_JTREG_EXCLUDE), \
+  ))
 
-$(eval $(call SetupTestFilesCompilation, BUILD_JDK_JTREG_EXECUTABLES, \
-    TYPE := PROGRAM, \
-    SOURCE_DIRS := $(BUILD_JDK_JTREG_NATIVE_SRC), \
-    OUTPUT_DIR := $(BUILD_JDK_JTREG_OUTPUT_DIR), \
-    EXCLUDE := $(BUILD_JDK_JTREG_EXCLUDE), \
-))
+  $(eval $(call SetupTestFilesCompilation, BUILD_JDK_JTREG_EXECUTABLES, \
+      TYPE := PROGRAM, \
+      SOURCE_DIRS := $(BUILD_JDK_JTREG_NATIVE_SRC), \
+      OUTPUT_DIR := $(BUILD_JDK_JTREG_OUTPUT_DIR), \
+      EXCLUDE := $(BUILD_JDK_JTREG_EXCLUDE), \
+  ))
+endif
 
 build-test-jdk-jtreg-native: $(BUILD_JDK_JTREG_LIBRARIES) $(BUILD_JDK_JTREG_EXECUTABLES)