Skip to content

Commit ffea913

Browse files
committed
8244592: Start supporting SOURCE_DATE_EPOCH
Reviewed-by: mbaesken Backport-of: 1a16a4b
1 parent 3e65a7c commit ffea913

File tree

7 files changed

+336
-4
lines changed

7 files changed

+336
-4
lines changed

make/Init.gmk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ else # HAS_SPEC=true
226226
# Parse COMPARE_BUILD (for makefile development)
227227
$(eval $(call ParseCompareBuild))
228228

229+
# Setup reproducible build environment
230+
$(eval $(call SetupReproducibleBuild))
231+
229232
# If no LOG= was given on command line, but we have a non-standard default
230233
# value, use that instead and re-parse log level.
231234
ifeq ($(LOG), )

make/InitSupport.gmk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ else # $(HAS_SPEC)=true
303303
topdir=$(TOPDIR)
304304
endif
305305

306+
# Setup the build environment to match the requested specification on
307+
# level of reproducible builds
308+
define SetupReproducibleBuild
309+
ifeq ($$(SOURCE_DATE), updated)
310+
SOURCE_DATE := $$(shell $$(DATE) +"%s")
311+
endif
312+
export SOURCE_DATE_EPOCH := $$(SOURCE_DATE)
313+
endef
314+
306315
# Parse COMPARE_BUILD into COMPARE_BUILD_*
307316
# Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
308317
# MAKE=<make targets>:COMP_OPTS=<compare script options>:

make/autoconf/configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ JDKOPT_ENABLE_DISABLE_FAILURE_HANDLER
235235
JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST
236236
JDKOPT_EXCLUDE_TRANSLATIONS
237237
JDKOPT_ENABLE_DISABLE_MANPAGES
238+
JDKOPT_SETUP_REPRODUCIBLE_BUILD
238239

239240
###############################################################################
240241
#

make/autoconf/jdk-options.m4

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,76 @@ AC_DEFUN([JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT],
683683
684684
AC_SUBST(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)
685685
])
686+
687+
################################################################################
688+
#
689+
# Check and set options related to reproducible builds.
690+
#
691+
AC_DEFUN_ONCE([JDKOPT_SETUP_REPRODUCIBLE_BUILD],
692+
[
693+
AC_ARG_WITH([source-date], [AS_HELP_STRING([--with-source-date],
694+
[how to set SOURCE_DATE_EPOCH ('updated', 'current', 'version' a timestamp or an ISO-8601 date) @<:@updated@:>@])],
695+
[with_source_date_present=true], [with_source_date_present=false])
696+
697+
AC_MSG_CHECKING([what source date to use])
698+
699+
if test "x$with_source_date" = xyes; then
700+
AC_MSG_ERROR([--with-source-date must have a value])
701+
elif test "x$with_source_date" = xupdated || test "x$with_source_date" = x; then
702+
# Tell the makefiles to update at each build
703+
SOURCE_DATE=updated
704+
AC_MSG_RESULT([determined at build time, from 'updated'])
705+
elif test "x$with_source_date" = xcurrent; then
706+
# Set the current time
707+
SOURCE_DATE=$($DATE +"%s")
708+
AC_MSG_RESULT([$SOURCE_DATE, from 'current'])
709+
elif test "x$with_source_date" = xversion; then
710+
# Use the date from version-numbers
711+
UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $DEFAULT_VERSION_DATE)
712+
if test "x$SOURCE_DATE" = x; then
713+
AC_MSG_RESULT([unavailable])
714+
AC_MSG_ERROR([Cannot convert DEFAULT_VERSION_DATE to timestamp])
715+
fi
716+
AC_MSG_RESULT([$SOURCE_DATE, from 'version'])
717+
else
718+
# It's a timestamp, an ISO-8601 date, or an invalid string
719+
# Additional [] needed to keep m4 from mangling shell constructs.
720+
if [ [[ "$with_source_date" =~ ^[0-9][0-9]*$ ]] ] ; then
721+
SOURCE_DATE=$with_source_date
722+
AC_MSG_RESULT([$SOURCE_DATE, from timestamp on command line])
723+
else
724+
UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $with_source_date)
725+
if test "x$SOURCE_DATE" != x; then
726+
AC_MSG_RESULT([$SOURCE_DATE, from ISO-8601 date on command line])
727+
else
728+
AC_MSG_RESULT([unavailable])
729+
AC_MSG_ERROR([Cannot parse date string "$with_source_date"])
730+
fi
731+
fi
732+
fi
733+
734+
REPRODUCIBLE_BUILD_DEFAULT=$with_source_date_present
735+
736+
if test "x$OPENJDK_BUILD_OS" = xwindows && \
737+
test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = xfalse; then
738+
# To support banning absolute paths on Windows, we must use the -pathmap
739+
# method, which requires reproducible builds.
740+
REPRODUCIBLE_BUILD_DEFAULT=true
741+
fi
742+
743+
UTIL_ARG_ENABLE(NAME: reproducible-build, DEFAULT: $REPRODUCIBLE_BUILD_DEFAULT,
744+
RESULT: ENABLE_REPRODUCIBLE_BUILD,
745+
DESC: [enable reproducible builds (not yet fully functional)],
746+
DEFAULT_DESC: [enabled if --with-source-date is given or on Windows without absolute paths])
747+
748+
if test "x$OPENJDK_BUILD_OS" = xwindows && \
749+
test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = xfalse && \
750+
test "x$ENABLE_REPRODUCIBLE_BUILD" = xfalse; then
751+
AC_MSG_NOTICE([On Windows it is not possible to combine --disable-reproducible-builds])
752+
AC_MSG_NOTICE([with --disable-absolute-paths-in-output.])
753+
AC_MSG_ERROR([Cannot continue])
754+
fi
755+
756+
AC_SUBST(SOURCE_DATE)
757+
AC_SUBST(ENABLE_REPRODUCIBLE_BUILD)
758+
])

make/autoconf/jdk-version.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
AC_DEFUN([JDKVER_CHECK_AND_SET_NUMBER],
3737
[
3838
# Additional [] needed to keep m4 from mangling shell constructs.
39-
if [ ! [[ "$2" =~ ^0*([1-9][0-9]*)|(0)$ ]] ] ; then
39+
if [ ! [[ "$2" =~ ^0*([1-9][0-9]*)$|^0*(0)$ ]] ] ; then
4040
AC_MSG_ERROR(["$2" is not a valid numerical value for $1])
4141
fi
4242
# Extract the version number without leading zeros.

make/autoconf/spec.gmk.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ RELEASE_FILE_OS_NAME:=@RELEASE_FILE_OS_NAME@
126126
RELEASE_FILE_OS_ARCH:=@RELEASE_FILE_OS_ARCH@
127127
RELEASE_FILE_LIBC:=@RELEASE_FILE_LIBC@
128128

129+
SOURCE_DATE := @SOURCE_DATE@
130+
ENABLE_REPRODUCIBLE_BUILD := @ENABLE_REPRODUCIBLE_BUILD@
131+
129132
LIBM:=@LIBM@
130133
LIBDL:=@LIBDL@
131134

0 commit comments

Comments
 (0)