8199539: Provide a standard way for the build to filter un-needed legal .md files
authorerikj
Thu, 05 Apr 2018 23:46:05 +0200
changeset 49537 149dc554808c
parent 49536 c32855a64719
child 49538 707553fcca04
8199539: Provide a standard way for the build to filter un-needed legal .md files Reviewed-by: tbell, ihse
make/CreateJmods.gmk
make/common/Modules.gmk
make/copy/Copy-java.base.gmk
make/copy/Copy-java.desktop.gmk
make/copy/CopyCommon.gmk
--- a/make/CreateJmods.gmk	Thu Apr 05 20:31:57 2018 +0000
+++ b/make/CreateJmods.gmk	Thu Apr 05 23:46:05 2018 +0200
@@ -80,10 +80,15 @@
   DEPS += $(call CacheFind, $(MAN_DIR))
 endif
 
+# If a specific modules_legal dir exists for this module, only pick up files
+# from there. These files were explicitly filtered or modified in <module>-copy
+# targets. For the rest, just pick up everything from the source legal dirs.
 LEGAL_NOTICES := \
-    $(call uniq, $(SUPPORT_OUTPUTDIR)/modules_legal/java.base \
-    $(call FindModuleLegalDirs, $(MODULE))) \
-    #
+    $(SUPPORT_OUTPUTDIR)/modules_legal/common \
+    $(if $(wildcard $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE)), \
+      $(wildcard $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE)), \
+      $(call FindModuleLegalSrcDirs, $(MODULE)) \
+    )
 
 LEGAL_NOTICES_PATH := $(call PathList, $(LEGAL_NOTICES))
 DEPS += $(call CacheFind, $(LEGAL_NOTICES))
--- a/make/common/Modules.gmk	Thu Apr 05 20:31:57 2018 +0000
+++ b/make/common/Modules.gmk	Thu Apr 05 23:46:05 2018 +0200
@@ -394,12 +394,11 @@
 endif
 LEGAL_SUBDIRS += share/legal
 
-# Find all legal dirs for a particular module
+# Find all legal src dirs for a particular module
 # $1 - Module to find legal dirs for
-FindModuleLegalDirs = \
+FindModuleLegalSrcDirs = \
     $(strip $(wildcard \
-        $(addsuffix /$(strip $1), $(SUPPORT_OUTPUTDIR)/modules_legal \
-            $(IMPORT_MODULES_LEGAL)) \
+        $(addsuffix /$(strip $1), $(IMPORT_MODULES_LEGAL)) \
         $(foreach sub, $(LEGAL_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS))) \
     ))
 
--- a/make/copy/Copy-java.base.gmk	Thu Apr 05 20:31:57 2018 +0000
+++ b/make/copy/Copy-java.base.gmk	Thu Apr 05 23:46:05 2018 +0200
@@ -24,6 +24,7 @@
 #
 
 include CopyCommon.gmk
+include Modules.gmk
 include TextFileProcessing.gmk
 
 $(eval $(call IncludeCustomExtension, copy/Copy-java.base.gmk))
@@ -224,13 +225,28 @@
 
 $(eval $(call SetupCopyFiles, COPY_JDK_NOTICES, \
     FILES := $(JDK_LICENSE) $(JDK_NOTICE) $(JDK_ADDITIONAL_LICENSE_INFO), \
-    DEST := $(LEGAL_DST_DIR), \
+    DEST := $(COMMON_LEGAL_DST_DIR), \
     FLATTEN := true, \
 ))
 
 TARGETS += $(COPY_JDK_NOTICES)
 
 ################################################################################
+#
+# Copy and filter the legal files depending on what 3rd party components are
+# bundled or linked from the OS.
+#
+ifeq ($(USE_EXTERNAL_LIBZ), true)
+  LEGAL_EXCLUDES += zlib.md
+endif
+
+$(eval $(call SetupCopyLegalFiles, COPY_LEGAL, \
+    EXCLUDES := $(LEGAL_EXCLUDES), \
+))
+
+TARGETS += $(COPY_LEGAL)
+
+################################################################################
 # Optionally copy libffi.so.? into the the image
 
 ifeq ($(ENABLE_LIBFFI_BUNDLING), true)
--- a/make/copy/Copy-java.desktop.gmk	Thu Apr 05 20:31:57 2018 +0000
+++ b/make/copy/Copy-java.desktop.gmk	Thu Apr 05 23:46:05 2018 +0200
@@ -24,6 +24,7 @@
 #
 
 include CopyCommon.gmk
+include Modules.gmk
 
 $(eval $(call IncludeCustomExtension, copy/Copy-java.desktop.gmk))
 
@@ -48,3 +49,34 @@
 TARGETS += $(PSFONTPROPFILE_TARGET_FILES)
 
 ################################################################################
+#
+# Copy and filter the legal files depending on what 3rd party components are
+# bundled or linked from the OS.
+#
+ifeq ($(USE_EXTERNAL_LIBJPEG), true)
+  LEGAL_EXCLUDES += jpeg.md
+endif
+
+ifeq ($(USE_EXTERNAL_LIBGIF), true)
+  LEGAL_EXCLUDES += giflib.md
+endif
+
+ifeq ($(USE_EXTERNAL_LIBPNG), true)
+  LEGAL_EXCLUDES += libpng.md
+endif
+
+ifeq ($(USE_EXTERNAL_LCMS), true)
+  LEGAL_EXCLUDES += lcms.md
+endif
+
+ifeq ($(FREETYPE_TO_USE), system)
+  LEGAL_EXCLUDES += freetype.md
+endif
+
+$(eval $(call SetupCopyLegalFiles, COPY_LEGAL, \
+    EXCLUDES := $(LEGAL_EXCLUDES), \
+))
+
+TARGETS += $(COPY_LEGAL)
+
+################################################################################
--- a/make/copy/CopyCommon.gmk	Thu Apr 05 20:31:57 2018 +0000
+++ b/make/copy/CopyCommon.gmk	Thu Apr 05 23:46:05 2018 +0200
@@ -26,6 +26,7 @@
 LIB_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE)
 CONF_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_conf/$(MODULE)
 LEGAL_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE)
+COMMON_LEGAL_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_legal/common
 
 ################################################################################
 #
@@ -60,3 +61,23 @@
 
   TARGETS += $(COPY_EXPORTED_INCLUDE_OS)
 endif
+
+################################################################################
+# Setup make rules for copying legal files. This is only needed if the files
+# need to be filtered due to optional components being enabled/disabled.
+# Otherwise CreateJmods.gmk will find the legal files in the original src dirs.
+#
+# Parameter 1 is the name of the rule.
+#
+# Remaining parameters are named arguments. These include:
+#   EXCLUDES : List of filenames to exclude from copy
+SetupCopyLegalFiles = $(NamedParamsMacroTemplate)
+define SetupCopyLegalFilesBody
+  $$(eval $$(call SetupCopyFiles, $1, \
+      SRC := $$(CUSTOM_ROOT), \
+      DEST := $$(LEGAL_DST_DIR), \
+      FILES := $$(filter-out $$(addprefix %/, $$($1_EXCLUDES)), \
+          $$(wildcard $$(addsuffix /*, $$(call FindModuleLegalSrcDirs, $$(MODULE))))), \
+      FLATTEN := true, \
+  ))
+endef