changeset 41658:14de1ab85d25

8062810: Examine src.zip in JDK image and decide if source classes should be organized by module Reviewed-by: mchung, kcr
author erikj
date Fri, 28 Oct 2016 14:29:20 +0200
parents 1dce857676f9
children 7c2c5a03a45f
files make/CompileJavaModules.gmk make/ZipSource.gmk make/common/MakeBase.gmk make/common/Modules.gmk make/common/ZipArchive.gmk
diffstat 5 files changed, 88 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/make/CompileJavaModules.gmk	Thu Oct 27 21:21:52 2016 +0000
+++ b/make/CompileJavaModules.gmk	Fri Oct 28 14:29:20 2016 +0200
@@ -473,6 +473,13 @@
 jdk.localedata_EXCLUDE_FILES += sun/text/resources/ext/BreakIteratorRules_th.java
 
 ################################################################################
+# 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
+endif
+
+################################################################################
 # Setup the compilation for the module
 #
 MODULE_SRC_DIRS := $(call FindModuleSrcDirs, $(MODULE))
--- a/make/ZipSource.gmk	Thu Oct 27 21:21:52 2016 +0000
+++ b/make/ZipSource.gmk	Fri Oct 28 14:29:20 2016 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2016, 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
@@ -28,61 +28,68 @@
 include $(SPEC)
 include MakeBase.gmk
 include JavaCompilation.gmk
+include Modules.gmk
+
+SRC_ZIP_WORK_DIR := $(SUPPORT_OUTPUTDIR)/src
 
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, , ZipSource.gmk))
 
 ################################################################################
+# Create the directory structure for src.zip using symlinks.
+# <module>/<package>/<file>.java
 
-# Use ?= to enable override in custom makefile
-SRC_ZIP_INCLUDES ?= \
-    com \
-    java \
-    javax \
-    jdk \
-    org \
-    sun \
-    #
+# Find extra source dirs for a module that are not part of normal compilation
+# but should be included in src.zip.
+# $1: Module to find dirs for
+ExtraSrcDirs = \
+    $(wildcard $(SUPPORT_OUTPUTDIR)/rmic/$(strip $1))
 
-SRC_ZIP_EXCLUDES ?=
+ALL_MODULES := $(FindAllModules)
 
-SRC_ZIP_SRCS += $(wildcard \
-    $(JDK_TOPDIR)/src/*/share/classes \
-    $(JDK_TOPDIR)/src/*/$(OPENJDK_TARGET_OS)/classes \
-    $(JDK_TOPDIR)/src/*/$(OPENJDK_TARGET_OS_API_DIR)/classes \
-    $(LANGTOOLS_TOPDIR)/src/*/share/classes \
-    $(CORBA_TOPDIR)/src/*/share/classes \
-    $(JAXP_TOPDIR)/src/*/share/classes \
-    $(JAXWS_TOPDIR)/src/*/share/classes \
-    $(SUPPORT_OUTPUTDIR)/gensrc/j* \
-    $(SUPPORT_OUTPUTDIR)/rmic/j* \
+# Generate the src dirs in the first make invocation and then call this makefile
+# again to create src.zip.
+$(foreach m, $(ALL_MODULES), \
+  $(foreach d, $(call FindModuleSrcDirs, $m) $(call ExtraSrcDirs, $m), \
+    $(eval $d_TARGET := $(SRC_ZIP_WORK_DIR)/$(patsubst $(TOPDIR)/%,%,$d)/$m) \
+    $(if $(SRC_GENERATED), , \
+      $(eval $$($d_TARGET): $d ; \
+          $$(if $(filter $(TOPDIR)/%, $d), $$(link-file-relative), $$(link-file-absolute)) \
+      ) \
     ) \
-    #
+    $(eval SRC_ZIP_SRCS += $$($d_TARGET)) \
+    $(eval SRC_ZIP_SRCS_$m += $$($d_TARGET)) \
+  ) \
+)
 
-# Need to copy launcher src files into desired directory structure
-# before zipping the sources.
-$(eval $(call SetupCopyFiles,COPY_LAUNCHER_SRC, \
-    SRC := $(JDK_TOPDIR)/src/java.base, \
-    DEST := $(SUPPORT_OUTPUTDIR)/src/launcher, \
-    FLATTEN := true, \
-    FILES := $(wildcard \
-        $(JDK_TOPDIR)/src/java.base/share/native/launcher/* \
-        $(JDK_TOPDIR)/src/java.base/share/native/libjli/* \
-        $(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_API_DIR)/native/libjli/java_md*)))
+TARGETS += $(SRC_ZIP_SRCS)
 
-# This dir needs to exist before macro is evaluated to avoid warning from find.
-$(call MakeDir, $(SUPPORT_OUTPUTDIR)/src)
-$(eval $(call SetupZipArchive,BUILD_SRC_ZIP, \
-    SRC := $(SRC_ZIP_SRCS) $(SUPPORT_OUTPUTDIR)/src, \
-    INCLUDES := $(SRC_ZIP_INCLUDES) launcher, \
-    EXCLUDES := $(SRC_ZIP_EXCLUDES), \
-    EXCLUDE_FILES := $(SRC_ZIP_EXCLUDE_FILES), \
-    SUFFIXES := .java .c .h, \
-    ZIP := $(SUPPORT_OUTPUTDIR)/src.zip, \
-    EXTRA_DEPS := $(COPY_LAUNCHER_SRC)))
+################################################################################
+# Only evaluate the creation of src.zip in a sub make call when the symlinked
+# src directory structure has been generated.
+ifeq ($(SRC_GENERATED), true)
+  $(eval $(call SetupZipArchive, BUILD_SRC_ZIP, \
+      SRC := $(dir $(SRC_ZIP_SRCS)), \
+      INCLUDES := $(SRC_ZIP_INCLUDES), \
+      INCLUDE_FILES := $(SRC_ZIP_INCLUDE_FILES), \
+      EXCLUDES := $(SRC_ZIP_EXCLUDES), \
+      EXCLUDE_FILES := $(SRC_ZIP_EXCLUDE_FILES), \
+      SUFFIXES := .java, \
+      ZIP := $(SUPPORT_OUTPUTDIR)/src.zip, \
+  ))
+
+  do-zip: $(BUILD_SRC_ZIP)
+
+  .PHONY: do-zip
+endif
+
+zip: $(SRC_ZIP_SRCS)
+	+$(MAKE) $(MAKE_ARGS) -f ZipSource.gmk do-zip SRC_GENERATED=true
+
+TARGETS += zip
 
 ################################################################################
 
-all: $(BUILD_SRC_ZIP)
+all: $(TARGETS)
 
-.PHONY: default all
+.PHONY: default all zip
--- a/make/common/MakeBase.gmk	Thu Oct 27 21:21:52 2016 +0000
+++ b/make/common/MakeBase.gmk	Fri Oct 28 14:29:20 2016 +0200
@@ -575,25 +575,21 @@
     $($(strip $1)_dotdots)/$($(strip $1)_suffix)
 
 ################################################################################
-# link-file-* works similarly to install file but creates a symlink instead on
-# platforms that support it. There are two versions, either creating a relative
-# or an absolute link.
-ifeq ($(OPENJDK_BUILD_OS), windows)
-  link-file-absolute = $(install-file)
-  link-file-relative = $(install-file)
-else
-  define link-file-relative
+# link-file-* works similarly to install-file but creates a symlink instead.
+# There are two versions, either creating a relative or an absolute link. Be
+# careful when using this on Windows since the symlink created is only valid in
+# the unix emulation environment.
+define link-file-relative
 	$(call MakeDir, $(@D))
 	$(RM) $@
 	$(LN) -s $(call RelativePath, $<, $(@D)) $@
-  endef
+endef
 
-  define link-file-absolute
+define link-file-absolute
 	$(call MakeDir, $(@D))
 	$(RM) $@
 	$(LN) -s $< $@
-  endef
-endif
+endef
 
 ################################################################################
 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
--- a/make/common/Modules.gmk	Thu Oct 27 21:21:52 2016 +0000
+++ b/make/common/Modules.gmk	Fri Oct 28 14:29:20 2016 +0200
@@ -178,6 +178,16 @@
           $(patsubst %,%/$(strip $1)/$(sub)/module-info.java, $(TOP_SRC_DIRS))) \
         $(patsubst %,%/$(strip $1)/module-info.java, $(IMPORT_MODULES_SRC)))
 
+# Find module-info.java files in the specific source dir
+# Param 1 - Src dir to find module-info.java files in
+FindModuleInfosForSrcDir = \
+    $(wildcard \
+        $(foreach sub, $(SRC_SUBDIRS), \
+          $(patsubst %,%/*/$(sub)/module-info.java, $(strip $1)) \
+        ) \
+        $(patsubst %,%/*/module-info.java, $(strip $1)) \
+    )
+
 # Extract the module names from the paths of module-info.java files. The
 # position of the module directory differs depending on if this is an imported
 # src dir or not.
@@ -193,6 +203,13 @@
     $(sort $(filter-out $(MODULES_FILTER), \
     $(call GetModuleNameFromModuleInfo, $(MODULE_INFOS))))
 
+# Find all modules in a specific src dir
+# Param 1 - Src dir to find modules in
+FindModulesForSrcDir = \
+    $(sort $(filter-out $(MODULES_FILTER), \
+        $(call GetModuleNameFromModuleInfo, $(call FindModuleInfosForSrcDir, $1)) \
+    ))
+
 FindImportedModules = \
     $(filter-out $(MODULES_FILTER), \
     $(if $(IMPORT_MODULES_CLASSES), $(notdir $(wildcard $(IMPORT_MODULES_CLASSES)/*))))
--- a/make/common/ZipArchive.gmk	Thu Oct 27 21:21:52 2016 +0000
+++ b/make/common/ZipArchive.gmk	Fri Oct 28 14:29:20 2016 +0200
@@ -73,6 +73,11 @@
     else
       $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
     endif
+  else
+    ifneq ($$($1_SUFFIXES),)
+      $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
+          $$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE)))
+    endif
   endif
   ifneq ($$($1_INCLUDE_FILES),)
     $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))