8278766: Enable OpenJDK build support for reproducible jars and jmods using --date

Reviewed-by: erikj
This commit is contained in:
Andrew Leonard 2021-12-23 11:01:26 +00:00
parent ad1dc9c2ae
commit 214f98f6b0
7 changed files with 60 additions and 21 deletions

View File

@ -226,6 +226,13 @@ else
JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.debuginfo,*.dSYM/**,*.dSYM}'
endif
# For reproducible builds specify the jmod --date using SOURCE_DATE in ISO-8601
ifeq ($(ENABLE_REPRODUCIBLE_BUILD), true)
JMOD_SOURCE_DATE := --date $(SOURCE_DATE_ISO_8601)
else
JMOD_SOURCE_DATE :=
endif
# Create jmods in the support dir and then move them into place to keep the
# module path in $(IMAGES_OUTPUTDIR)/jmods valid at all times.
$(eval $(call SetupExecute, create_$(JMOD_FILE), \
@ -237,6 +244,7 @@ $(eval $(call SetupExecute, create_$(JMOD_FILE), \
COMMAND := $(JMOD) create --module-version $(VERSION_SHORT) \
--target-platform '$(OPENJDK_MODULE_TARGET_PLATFORM)' \
--module-path $(JMODS_DIR) $(JMOD_FLAGS) \
$(JMOD_SOURCE_DATE) \
$(JMODS_SUPPORT_DIR)/$(JMOD_FILE), \
POST_COMMAND := $(MV) $(JMODS_SUPPORT_DIR)/$(JMOD_FILE) $(JMODS_DIR)/$(JMOD_FILE), \
))

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2021, 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
@ -313,6 +313,15 @@ else # $(HAS_SPEC)=true
SOURCE_DATE := $$(shell $$(DATE) +"%s")
endif
export SOURCE_DATE_EPOCH := $$(SOURCE_DATE)
ifeq ($$(IS_GNU_DATE), yes)
export SOURCE_DATE_ISO_8601 := $$(shell $$(DATE) --utc \
--date="@$$(SOURCE_DATE_EPOCH)" \
+"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null)
else
export SOURCE_DATE_ISO_8601 := $$(shell $$(DATE) -u \
-j -f "%s" "$$(SOURCE_DATE_EPOCH)" \
+"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null)
endif
endef
# Parse COMPARE_BUILD into COMPARE_BUILD_*

View File

@ -357,12 +357,16 @@ AC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
AC_SUBST(IS_GNU_TIME)
# Check if it's GNU date
AC_MSG_CHECKING([if date is the GNU version])
check_date=`$DATE --version 2>&1 | $GREP GNU`
if test "x$check_date" != x; then
AC_MSG_RESULT([yes])
IS_GNU_DATE=yes
else
AC_MSG_RESULT([no])
IS_GNU_DATE=no
fi
AC_SUBST(IS_GNU_DATE)
if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
UTIL_REQUIRE_PROGS(DSYMUTIL, dsymutil)

View File

@ -379,6 +379,16 @@ AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
# Finally, set some other options...
# Determine if the boot jdk jar supports the --date option
if $JAR --help 2>&1 | $GREP -q "\-\-date=TIMESTAMP"; then
BOOT_JDK_JAR_SUPPORTS_DATE=true
else
BOOT_JDK_JAR_SUPPORTS_DATE=false
fi
AC_MSG_CHECKING([if Boot JDK jar supports --date=TIMESTAMP])
AC_MSG_RESULT([$BOOT_JDK_JAR_SUPPORTS_DATE])
AC_SUBST(BOOT_JDK_JAR_SUPPORTS_DATE)
# When compiling code to be executed by the Boot JDK, force compatibility with the
# oldest supported bootjdk.
OLDEST_BOOT_JDK=`$ECHO $DEFAULT_ACCEPTABLE_BOOT_VERSIONS \

View File

@ -371,6 +371,9 @@ BUILD_JDK:=@BUILD_JDK@
CREATE_BUILDJDK:=@CREATE_BUILDJDK@
EXTERNAL_BUILDJDK:=@EXTERNAL_BUILDJDK@
# Whether the boot jdk jar supports --date=TIMESTAMP
BOOT_JDK_JAR_SUPPORTS_DATE:=@BOOT_JDK_JAR_SUPPORTS_DATE@
# When compiling Java source to be run by the boot jdk
# use these extra flags, eg -source 6 -target 6
BOOT_JDK_SOURCETARGET:=@BOOT_JDK_SOURCETARGET@
@ -707,6 +710,7 @@ CODESIGN:=@CODESIGN@
CP:=@CP@
CUT:=@CUT@
DATE:=@DATE@
IS_GNU_DATE:=@IS_GNU_DATE@
DIFF:=@DIFF@
DIRNAME:=@DIRNAME@
DSYMUTIL:=@DSYMUTIL@

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2021, 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
@ -236,13 +236,15 @@ AC_DEFUN([UTIL_GET_MATCHING_VALUES],
# $2: input date/time string
AC_DEFUN([UTIL_GET_EPOCH_TIMESTAMP],
[
if test "x$IS_GNU_DATE" = xyes; then
# GNU date
timestamp=$($DATE --utc --date=$2 +"%s" 2> /dev/null)
if test "x$timestamp" = x; then
# GNU date format did not work, try BSD date options
timestamp=$($DATE -j -f "%F %T" "$2" "+%s" 2> /dev/null)
else
# BSD date
timestamp=$($DATE -u -j -f "%F %T" "$2" "+%s" 2> /dev/null)
if test "x$timestamp" = x; then
# Perhaps the time was missing
timestamp=$($DATE -j -f "%F %T" "$2 00:00:00" "+%s" 2> /dev/null)
timestamp=$($DATE -u -j -f "%F %T" "$2 00:00:00" "+%s" 2> /dev/null)
# If this did not work, we give up and return the empty string
fi
fi

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2021, 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
@ -193,7 +193,7 @@ define SetupJarArchiveBody
$1_UPDATE_CONTENTS=\
if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
$(ECHO) " updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
$$($1_JAR_CMD) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
fi $$(NEWLINE)
# The s-variants of the above macros are used when the jar is created from scratch.
# NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
@ -212,25 +212,27 @@ define SetupJarArchiveBody
| $(SED) 's|$$(src)/|-C $$(src) |g' >> \
$$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
endif
$1_SUPDATE_CONTENTS=$$($1_JAR_CMD) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
$1_SUPDATE_CONTENTS=$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
# Use a slightly shorter name for logging, but with enough path to identify this jar.
$1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_JAR))
ifneq (,$$($1_CHECK_COMPRESS_JAR))
$1_JAR_CREATE_OPTIONS := c0fm
$1_JAR_UPDATE_OPTIONS := u0f
ifeq ($(COMPRESS_JARS), true)
$1_JAR_CREATE_OPTIONS := cfm
$1_JAR_UPDATE_OPTIONS := uf
# If reproducible build and the boot jdk jar supports --date option
# then specify the --date using SOURCE_DATE in ISO-8601
$1_JAR_OPTIONS :=
ifeq ($$(ENABLE_REPRODUCIBLE_BUILD), true)
ifeq ($$(BOOT_JDK_JAR_SUPPORTS_DATE), true)
$1_JAR_OPTIONS += --date $(SOURCE_DATE_ISO_8601)
endif
endif
ifneq (,$$($1_CHECK_COMPRESS_JAR))
ifneq ($(COMPRESS_JARS), true)
$1_JAR_OPTIONS += --no-compress
endif
else
$1_JAR_CREATE_OPTIONS := cfm
$1_JAR_UPDATE_OPTIONS := uf
endif
# Include all variables of significance in the vardeps file
$1_VARDEPS := $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) \
$1_VARDEPS := $$($1_JAR_CMD) $$($1_JAR_OPTIONS) $$($1_MANIFEST) \
$$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR) $$($1_ORIG_DEPS) $$($1_SRCS) \
$$($1_INCLUDES) $$($1_EXCLUDES) $$($1_EXCLUDE_FILES) $$($1_EXTRA_FILES)
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$$($1_JARNAME).vardeps)
@ -255,7 +257,7 @@ define SetupJarArchiveBody
$$(if $$($1_EXTRA_MANIFEST_ATTR), \
$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
$(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
$$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
$$($1_JAR_CMD) --create $$($1_JAR_OPTIONS) --file $$@ --manifest $$($1_MANIFEST_FILE) $$(NEWLINE) \
$$($1_SCAPTURE_CONTENTS) \
$$($1_SCAPTURE_METAINF) \
$$($1_SUPDATE_CONTENTS) \