8214309: Enhance makefiles to allow generating JCov instrumented build
authorshurailine
Thu, 29 Nov 2018 06:34:46 -0800
changeset 52774 56ca125c973b
parent 52773 61e442695048
child 52775 d488477865c0
8214309: Enhance makefiles to allow generating JCov instrumented build Reviewed-by: erikj
make/Bundles.gmk
make/Coverage.gmk
make/Main.gmk
make/autoconf/jdk-options.m4
make/autoconf/spec.gmk.in
make/conf/jib-profiles.js
--- a/make/Bundles.gmk	Thu Nov 29 13:17:14 2018 -0800
+++ b/make/Bundles.gmk	Thu Nov 29 06:34:46 2018 -0800
@@ -262,6 +262,21 @@
 
 ################################################################################
 
+ifneq ($(filter jcov-bundles, $(MAKECMDGOALS)), )
+  JCOV_BUNDLE_FILES := $(call CacheFind, $(JCOV_IMAGE_DIR))
+
+  $(eval $(call SetupBundleFile, BUILD_JCOV_BUNDLE, \
+      BUNDLE_NAME := $(JCOV_BUNDLE_NAME), \
+      FILES := $(JCOV_BUNDLE_FILES), \
+      BASE_DIRS := $(JCOV_IMAGE_DIR), \
+      SUBDIR := $(JDK_BUNDLE_SUBDIR), \
+  ))
+
+  JCOV_TARGETS += $(BUILD_JCOV_BUNDLE)
+endif
+
+################################################################################
+
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, Bundles.gmk))
 
@@ -270,5 +285,6 @@
 product-bundles: $(PRODUCT_TARGETS)
 test-bundles: $(TEST_TARGETS)
 docs-bundles: $(DOCS_TARGETS)
+jcov-bundles: $(JCOV_TARGETS)
 
-.PHONY: all default product-bundles test-bundles docs-bundles
+.PHONY: all default product-bundles test-bundles docs-bundles jcov-bundles
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/Coverage.gmk	Thu Nov 29 06:34:46 2018 -0800
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+include $(SPEC)
+include MakeBase.gmk
+
+################################################################################
+
+JCOV_INPUT_IMAGE_DIR :=
+
+ifneq ($(JCOV_INPUT_JDK), )
+  JCOV_INPUT_IMAGE_DIR := $(JCOV_INPUT_JDK)
+else
+  JCOV_INPUT_IMAGE_DIR := $(JDK_IMAGE_DIR)
+endif
+
+#moving instrumented jdk image in and out of jcov_temp because of CODETOOLS-7902299
+JCOV_TEMP := $(SUPPORT_OUTPUTDIR)/jcov_temp
+
+$(JCOV_IMAGE_DIR)/release: $(JCOV_INPUT_IMAGE_DIR)/release
+	$(call LogWarn, Creating instrumented jdk image with JCov)
+	$(call MakeDir, $(JCOV_TEMP) $(IMAGES_OUTPUTDIR))
+	$(RM) -r $(JCOV_IMAGE_DIR) $(JCOV_TEMP)/*
+	$(CP) -r $(JCOV_INPUT_IMAGE_DIR) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)
+	$(JAVA) -Xmx3g -jar $(JCOV_HOME)/lib/jcov.jar JREInstr \
+	    -t $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)/template.xml \
+	    -rt $(JCOV_HOME)/lib/jcov_network_saver.jar \
+	    -exclude 'java.lang.Object' \
+	    -exclude 'jdk.internal.org.objectweb.**' \
+	    -exclude jdk.test.Main -exclude '**\$Proxy*' \
+	    $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)
+	$(MV) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(JCOV_IMAGE_DIR)
+	$(RMDIR) $(JCOV_TEMP)
+
+jcov-image: $(JCOV_IMAGE_DIR)/release
--- a/make/Main.gmk	Thu Nov 29 13:17:14 2018 -0800
+++ b/make/Main.gmk	Thu Nov 29 06:34:46 2018 -0800
@@ -371,10 +371,15 @@
 exploded-image-optimize:
 	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ExplodedImageOptimize.gmk)
 
+ifeq ($(JCOV_ENABLED), true)
+  jcov-image:
+	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Coverage.gmk jcov-image)
+endif
+
 ALL_TARGETS += store-source-revision create-source-revision-tracker bootcycle-images zip-security \
     zip-source jrtfs-jar jdk-image legacy-jre-image \
     symbols-image mac-jdk-bundle mac-legacy-jre-bundle \
-    release-file exploded-image-optimize
+    release-file exploded-image-optimize jcov-image
 
 ################################################################################
 # Docs targets
@@ -577,7 +582,12 @@
 docs-bundles:
 	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk docs-bundles)
 
-ALL_TARGETS += product-bundles test-bundles docs-bundles
+ifeq ($(JCOV_ENABLED), true)
+  jcov-bundles:
+	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk jcov-bundles)
+endif
+
+ALL_TARGETS += product-bundles test-bundles docs-bundles jcov-bundles
 
 ################################################################################
 # Install targets
@@ -820,6 +830,10 @@
   mac-jdk-bundle: jdk-image
   mac-legacy-jre-bundle: legacy-jre-image
 
+  ifeq ($(JCOV_INPUT_JDK), )
+    jcov-image: jdk-image
+  endif
+
   # The optimize target can run as soon as the modules dir has been completely
   # populated (java, copy and gendata targets) and the basic libs and launchers
   # have been built.
@@ -900,6 +914,8 @@
 
   docs-bundles: docs-image
 
+  jcov-bundles: jcov-image
+
   generate-summary: jmods buildtools-modules
 
   update-x11wrappers: java.base-copy buildtools-jdk
--- a/make/autoconf/jdk-options.m4	Thu Nov 29 13:17:14 2018 -0800
+++ b/make/autoconf/jdk-options.m4	Thu Nov 29 06:34:46 2018 -0800
@@ -395,8 +395,37 @@
   elif test "x$enable_native_coverage" != "x"; then
     AC_MSG_ERROR([--enable-native-coverage can only be assigned "yes" or "no"])
   fi
+  AC_SUBST(GCOV_ENABLED)
 
-  AC_SUBST(GCOV_ENABLED)
+  AC_ARG_WITH(jcov, [AS_HELP_STRING([--with-jcov],
+      [jcov library location])])
+  AC_ARG_WITH(jcov-input-jdk, [AS_HELP_STRING([--with-jcov-input-jdk],
+      [jdk image to instrument])])
+  JCOV_HOME=
+  JCOV_INPUT_JDK=
+  JCOV_ENABLED=
+  if test "x$with_jcov" = "x" ; then
+    JCOV_ENABLED="false"
+  else
+    JCOV_HOME="$with_jcov"
+    if test ! -f "$JCOV_HOME/lib/jcov.jar"; then
+      AC_MSG_RESULT([fail])
+      AC_MSG_ERROR([Invalid JCov bundle: "$JCOV_HOME/lib/jcov.jar" does not exist])
+    fi
+    JCOV_ENABLED="true"
+    BASIC_FIXUP_PATH(JCOV_HOME)
+    if test "x$with_jcov_input_jdk" != "x" ; then
+      JCOV_INPUT_JDK="$with_jcov_input_jdk"
+      if test ! -f "$JCOV_INPUT_JDK/bin/java$EXE_SUFFIX"; then
+        AC_MSG_RESULT([fail])
+        AC_MSG_ERROR([Invalid JDK bundle: "$JCOV_INPUT_JDK/bin/java$EXE_SUFFIX" does not exist])
+      fi
+      BASIC_FIXUP_PATH(JCOV_INPUT_JDK)
+    fi
+  fi
+  AC_SUBST(JCOV_ENABLED)
+  AC_SUBST(JCOV_HOME)
+  AC_SUBST(JCOV_INPUT_JDK)
 ])
 
 ###############################################################################
--- a/make/autoconf/spec.gmk.in	Thu Nov 29 13:17:14 2018 -0800
+++ b/make/autoconf/spec.gmk.in	Thu Nov 29 06:34:46 2018 -0800
@@ -372,6 +372,9 @@
 UNLIMITED_CRYPTO=@UNLIMITED_CRYPTO@
 
 GCOV_ENABLED=@GCOV_ENABLED@
+JCOV_ENABLED=@JCOV_ENABLED@
+JCOV_HOME=@JCOV_HOME@
+JCOV_INPUT_JDK=@JCOV_INPUT_JDK@
 
 # AddressSanitizer
 export ASAN_ENABLED:=@ASAN_ENABLED@
@@ -839,10 +842,12 @@
 # Images directory definitions
 JDK_IMAGE_SUBDIR:=jdk
 JRE_IMAGE_SUBDIR:=jre
+JCOV_IMAGE_SUBDIR := jdk-jcov
 
 # Colon left out to be able to override output dir for bootcycle-images
 JDK_IMAGE_DIR=$(IMAGES_OUTPUTDIR)/$(JDK_IMAGE_SUBDIR)
 JRE_IMAGE_DIR=$(IMAGES_OUTPUTDIR)/$(JRE_IMAGE_SUBDIR)
+JCOV_IMAGE_DIR = $(IMAGES_OUTPUTDIR)/$(JCOV_IMAGE_SUBDIR)
 
 # Test image, as above
 TEST_IMAGE_SUBDIR:=test
@@ -889,12 +894,14 @@
 TEST_DEMOS_BUNDLE_NAME := jdk-$(BASE_NAME)_bin-tests-demos$(DEBUG_PART).tar.gz
 TEST_BUNDLE_NAME := jdk-$(BASE_NAME)_bin-tests$(DEBUG_PART).tar.gz
 DOCS_BUNDLE_NAME := jdk-$(BASE_NAME)_doc-api-spec$(DEBUG_PART).tar.gz
+JCOV_BUNDLE_NAME := jdk-jcov-$(BASE_NAME)_bin$(DEBUG_PART).$(JDK_BUNDLE_EXTENSION)
 
 JDK_BUNDLE := $(BUNDLES_OUTPUTDIR)/$(JDK_BUNDLE_NAME)
 JDK_SYMBOLS_BUNDLE :=  $(BUNDLES_OUTPUTDIR)/$(JDK_SYMBOLS_BUNDLE_NAME)
 TEST_DEMOS_BUNDLE := $(BUNDLES_OUTPUTDIR)/$(TEST_DEMOS_BUNDLE_NAME)
 TEST_BUNDLE :=  $(BUNDLES_OUTPUTDIR)/$(TEST_BUNDLE_NAME)
 DOCS_BUNDLE :=  $(BUNDLES_OUTPUTDIR)/$(DOCS_BUNDLE_NAME)
+JCOV_BUNDLE := $(BUNDLES_OUTPUTDIR)/$(JCOV_BUNDLE_NAME)
 
 # This macro is called to allow inclusion of closed source counterparts.
 # Unless overridden in closed sources, it expands to nothing.
--- a/make/conf/jib-profiles.js	Thu Nov 29 13:17:14 2018 -0800
+++ b/make/conf/jib-profiles.js	Thu Nov 29 06:34:46 2018 -0800
@@ -243,7 +243,7 @@
 
     // These are the base setttings for all the main build profiles.
     common.main_profile_base = {
-        dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh"],
+        dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh", "jcov"],
         default_make_targets: ["product-bundles", "test-bundles"],
         configure_args: concat(["--enable-jtreg-failure-handler"],
             "--with-exclude-translations=de,es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK",
@@ -898,6 +898,14 @@
             revision: "1.21+1.0"
         },
 
+        jcov: {
+            server: "jpg",
+            product: "jcov",
+            version: "3.0",
+            build_number: "b07",
+            file: "bundles/jcov-3_0.zip",
+        },
+
         gnumake: {
             organization: common.organization,
             ext: "tar.gz",