Skip to content

Commit

Permalink
8244592: Start supporting SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
Reviewed-by: erikj
  • Loading branch information
magicus committed May 7, 2020
1 parent 74132fe commit 1a16a4b
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 2 deletions.
3 changes: 3 additions & 0 deletions make/Init.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ else # HAS_SPEC=true
# Parse COMPARE_BUILD (for makefile development)
$(eval $(call ParseCompareBuild))

# Setup reproducible build environment
$(eval $(call SetupReproducibleBuild))

# If no LOG= was given on command line, but we have a non-standard default
# value, use that instead and re-parse log level.
ifeq ($(LOG), )
Expand Down
9 changes: 9 additions & 0 deletions make/InitSupport.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ else # $(HAS_SPEC)=true
topdir=$(TOPDIR)
endif

# Setup the build environment to match the requested specification on
# level of reproducible builds
define SetupReproducibleBuild
ifeq ($$(SOURCE_DATE), updated)
SOURCE_DATE := $$(shell $$(DATE) +"%s")
endif
export SOURCE_DATE_EPOCH := $$(SOURCE_DATE)
endef

# Parse COMPARE_BUILD into COMPARE_BUILD_*
# Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
# MAKE=<make targets>:COMP_OPTS=<compare script options>:
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST
JDKOPT_EXCLUDE_TRANSLATIONS
JDKOPT_ENABLE_DISABLE_MANPAGES
JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE
JDKOPT_SETUP_REPRODUCIBLE_BUILD

###############################################################################
#
Expand Down
56 changes: 56 additions & 0 deletions make/autoconf/jdk-options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,59 @@ AC_DEFUN([JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT],
AC_SUBST(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)
])

################################################################################
#
# Check and set options related to reproducible builds.
#
AC_DEFUN_ONCE([JDKOPT_SETUP_REPRODUCIBLE_BUILD],
[
AC_ARG_WITH([source-date], [AS_HELP_STRING([--with-source-date],
[how to set SOURCE_DATE_EPOCH ('updated', 'current', 'version' a timestamp or an ISO-8601 date) @<:@updated@:>@])],
[with_source_date_present=true], [with_source_date_present=false])
AC_MSG_CHECKING([what source date to use])
if test "x$with_source_date" = xyes; then
AC_MSG_ERROR([--with-source-date must have a value])
elif test "x$with_source_date" = xupdated || test "x$with_source_date" = x; then
# Tell the makefiles to update at each build
SOURCE_DATE=updated
AC_MSG_RESULT([determined at build time, from 'updated'])
elif test "x$with_source_date" = xcurrent; then
# Set the current time
SOURCE_DATE=$($DATE +"%s")
AC_MSG_RESULT([$SOURCE_DATE, from 'current'])
elif test "x$with_source_date" = xversion; then
# Use the date from version-numbers
UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $DEFAULT_VERSION_DATE)
if test "x$SOURCE_DATE" = x; then
AC_MSG_RESULT([unavailable])
AC_MSG_ERROR([Cannot convert DEFAULT_VERSION_DATE to timestamp])
fi
AC_MSG_RESULT([$SOURCE_DATE, from 'version'])
else
# It's a timestamp, an ISO-8601 date, or an invalid string
# Additional [] needed to keep m4 from mangling shell constructs.
if [ [[ "$with_source_date" =~ ^[0-9][0-9]*$ ]] ] ; then
SOURCE_DATE=$with_source_date
AC_MSG_RESULT([$SOURCE_DATE, from timestamp on command line])
else
UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $with_source_date)
if test "x$SOURCE_DATE" != x; then
AC_MSG_RESULT([$SOURCE_DATE, from ISO-8601 date on command line])
else
AC_MSG_RESULT([unavailable])
AC_MSG_ERROR([Cannot parse date string "$with_source_date"])
fi
fi
fi
UTIL_ARG_ENABLE(NAME: reproducible-build, DEFAULT: $with_source_date_present,
RESULT: ENABLE_REPRODUCIBLE_BUILD,
DESC: [enable reproducible builds (not yet fully functional)],
DEFAULT_DESC: [enabled if --with-source-date is given])
AC_SUBST(SOURCE_DATE)
AC_SUBST(ENABLE_REPRODUCIBLE_BUILD)
])
2 changes: 1 addition & 1 deletion make/autoconf/jdk-version.m4
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
AC_DEFUN([JDKVER_CHECK_AND_SET_NUMBER],
[
# Additional [] needed to keep m4 from mangling shell constructs.
if [ ! [[ "$2" =~ ^0*([1-9][0-9]*)|(0)$ ]] ] ; then
if [ ! [[ "$2" =~ ^0*([1-9][0-9]*)$|^0*(0)$ ]] ] ; then
AC_MSG_ERROR(["$2" is not a valid numerical value for $1])
fi
# Extract the version number without leading zeros.
Expand Down
3 changes: 3 additions & 0 deletions make/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ OPENJDK_MODULE_TARGET_PLATFORM:=@OPENJDK_MODULE_TARGET_PLATFORM@
RELEASE_FILE_OS_NAME:=@RELEASE_FILE_OS_NAME@
RELEASE_FILE_OS_ARCH:=@RELEASE_FILE_OS_ARCH@

SOURCE_DATE := @SOURCE_DATE@
ENABLE_REPRODUCIBLE_BUILD := @ENABLE_REPRODUCIBLE_BUILD@

LIBM:=@LIBM@
LIBDL:=@LIBDL@

Expand Down
30 changes: 29 additions & 1 deletion make/autoconf/util.m4
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,29 @@ AC_DEFUN([UTIL_GET_MATCHING_VALUES],
fi
])

###############################################################################
# Converts an ISO-8601 date/time string to a unix epoch timestamp. If no
# suitable conversion method was found, an empty string is returned.
#
# Sets the specified variable to the resulting list.
#
# $1: result variable name
# $2: input date/time string
AC_DEFUN([UTIL_GET_EPOCH_TIMESTAMP],
[
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)
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)
# If this did not work, we give up and return the empty string
fi
fi
$1=$timestamp
])

###############################################################################
# Sort a space-separated list, and remove duplicates.
#
Expand Down Expand Up @@ -320,12 +343,14 @@ AC_DEFUN([UTIL_ALIASED_ARG_ENABLE],
# option should be available. Must set AVAILABLE to 'false' if not.
# IF_GIVEN: An optional code block to execute if the option was given on the
# command line (regardless of the value).
# IF_NOT_GIVEN: An optional code block to execute if the option was not given
# on the command line (regardless of the value).
# IF_ENABLED: An optional code block to execute if the option is turned on.
# IF_DISABLED: An optional code block to execute if the option is turned off.
#
UTIL_DEFUN_NAMED([UTIL_ARG_ENABLE],
[*NAME RESULT DEFAULT AVAILABLE DESC DEFAULT_DESC CHECKING_MSG
CHECK_AVAILABLE IF_GIVEN IF_ENABLED IF_DISABLED], [$@],
CHECK_AVAILABLE IF_GIVEN IF_NOT_GIVEN IF_ENABLED IF_DISABLED], [$@],
[
##########################
# Part 1: Set up m4 macros
Expand Down Expand Up @@ -356,6 +381,7 @@ UTIL_DEFUN_NAMED([UTIL_ARG_ENABLE],
# tripping up bash.
m4_define([ARG_CHECK_AVAILABLE], m4_if(ARG_CHECK_AVAILABLE, , :, ARG_CHECK_AVAILABLE))
m4_define([ARG_IF_GIVEN], m4_if(ARG_IF_GIVEN, , :, ARG_IF_GIVEN))
m4_define([ARG_IF_NOT_GIVEN], m4_if(ARG_IF_NOT_GIVEN, , :, ARG_IF_NOT_GIVEN))
m4_define([ARG_IF_ENABLED], m4_if(ARG_IF_ENABLED, , :, ARG_IF_ENABLED))
m4_define([ARG_IF_DISABLED], m4_if(ARG_IF_DISABLED, , :, ARG_IF_DISABLED))
Expand Down Expand Up @@ -425,6 +451,8 @@ UTIL_DEFUN_NAMED([UTIL_ARG_ENABLE],
# Execute result payloads, if present
if test x$ARG_GIVEN = xtrue; then
ARG_IF_GIVEN
else
ARG_IF_NOT_GIVEN
fi
if test x$ARG_RESULT = xtrue; then
Expand Down

0 comments on commit 1a16a4b

Please sign in to comment.