Skip to content
Permalink
Browse files
8226346: Build better binary builders
Reviewed-by: tbell
  • Loading branch information
erikj79 committed Dec 13, 2019
1 parent 0a73d5b commit 4df99aa7aeaed0d6132ca5c86f803f1096df8841
Showing 40 changed files with 478 additions and 224 deletions.
@@ -37,10 +37,22 @@ ifeq ($(call isTargetOs, windows), true)
$(call install-file)
endif

prepare-test-image: $(FIXPATH_COPY)
BUILD_INFO_PROPERTIES := $(TEST_IMAGE_DIR)/build-info.properties

FIXPATH_ECHO := $(FIXPATH) $(call FixPath, $(ECHO))

$(BUILD_INFO_PROPERTIES):
$(call MakeTargetDir)
$(ECHO) "# Build info properties for JDK tests" > $@
$(FIXPATH_ECHO) "build.workspace.root=$(WORKSPACE_ROOT)" >> $@
$(FIXPATH_ECHO) "build.output.root=$(OUTPUTDIR)" >> $@

prepare-test-image: $(FIXPATH_COPY) $(BUILD_INFO_PROPERTIES)
$(call MakeDir, $(TEST_IMAGE_DIR))
$(ECHO) > $(TEST_IMAGE_DIR)/Readme.txt 'JDK test image'

################################################################################

all: prepare-test-image

.PHONY: default all prepare-test-image
@@ -86,6 +86,13 @@ AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
AC_SUBST(TOPDIR)
AC_SUBST(CONFIGURE_START_DIR)
if test "x$CUSTOM_ROOT" != x; then
WORKSPACE_ROOT="${CUSTOM_ROOT}"
else
WORKSPACE_ROOT="${TOPDIR}"
fi
AC_SUBST(WORKSPACE_ROOT)
# We can only call UTIL_FIXUP_PATH after BASIC_CHECK_PATHS_WINDOWS.
UTIL_FIXUP_PATH(CONFIGURE_START_DIR)
UTIL_FIXUP_PATH(TOPDIR)
@@ -313,11 +320,6 @@ AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
AC_MSG_RESULT([in build directory with custom name])
fi
if test "x$CUSTOM_ROOT" != x; then
WORKSPACE_ROOT="${CUSTOM_ROOT}"
else
WORKSPACE_ROOT="${TOPDIR}"
fi
OUTPUTDIR="${WORKSPACE_ROOT}/build/${CONF_NAME}"
$MKDIR -p "$OUTPUTDIR"
if test ! -d "$OUTPUTDIR"; then
@@ -374,7 +376,6 @@ AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
AC_SUBST(SPEC)
AC_SUBST(CONF_NAME)
AC_SUBST(OUTPUTDIR)
AC_SUBST(WORKSPACE_ROOT)
AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR)
# The spec.gmk file contains all variables for the make system.
@@ -97,6 +97,9 @@ HOTSPOT_SETUP_JVM_VARIANTS
# With basic setup done, call the custom early hook.
CUSTOM_EARLY_HOOK

# This only needs debug level to be setup
JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT

# Check if we have devkits, extra paths or sysroot set.
BASIC_SETUP_DEVKIT

@@ -855,18 +855,27 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
$1_WARNING_CFLAGS_JVM="-Wno-format-zero-length -Wtype-limits -Wuninitialized"
fi
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
# Check if compiler supports -fmacro-prefix-map. If so, use that to make
# the __FILE__ macro resolve to paths relative to the workspace root.
workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
FILE_MACRO_CFLAGS="-fmacro-prefix-map=${workspace_root_trailing_slash}="
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
PREFIX: $3,
IF_FALSE: [
FILE_MACRO_CFLAGS=
]
)
# Prevent the __FILE__ macro from generating absolute paths into the built
# binaries. Depending on toolchain, different mitigations are possible.
# * GCC and Clang of new enough versions have -fmacro-prefix-map.
# * For most other toolchains, supplying all source files and -I flags as
# relative paths fixes the issue.
FILE_MACRO_CFLAGS=
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
# Check if compiler supports -fmacro-prefix-map. If so, use that to make
# the __FILE__ macro resolve to paths relative to the workspace root.
workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
FILE_MACRO_CFLAGS="-fmacro-prefix-map=${workspace_root_trailing_slash}="
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
PREFIX: $3,
IF_FALSE: [
FILE_MACRO_CFLAGS=
]
)
fi
fi
AC_SUBST(FILE_MACRO_CFLAGS)
# EXPORT to API
CFLAGS_JVM_COMMON="$ALWAYS_CFLAGS_JVM $ALWAYS_DEFINES_JVM \
@@ -154,6 +154,12 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -Wl,--allow-shlib-undefined -pie"
fi
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
BASIC_LDFLAGS="$BASIC_LDFLAGS -pdbaltpath:%_PDB%"
fi
fi
# Export some intermediate variables for compatibility
LDFLAGS_CXX_JDK="$BASIC_LDFLAGS_ONLYCXX $BASIC_LDFLAGS_ONLYCXX_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY"
AC_SUBST(LDFLAGS_CXX_JDK)
@@ -598,3 +598,35 @@ AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE],
])
AC_SUBST(BUILD_CDS_ARCHIVE)
])

################################################################################
#
# Disallow any output from containing absolute paths from the build system.
# This setting defaults to allowed on debug builds and not allowed on release
# builds.
#
AC_DEFUN([JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT],
[
AC_ARG_ENABLE([absolute-paths-in-output],
[AS_HELP_STRING([--disable-absolute-paths-in-output],
[Set to disable to prevent any absolute paths from the build to end up in
any of the build output. @<:@disabled in release builds, otherwise enabled@:>@])
])
AC_MSG_CHECKING([if absolute paths should be allowed in the build output])
if test "x$enable_absolute_paths_in_output" = "xno"; then
AC_MSG_RESULT([no, forced])
ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
elif test "x$enable_absolute_paths_in_output" = "xyes"; then
AC_MSG_RESULT([yes, forced])
ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
elif test "x$DEBUG_LEVEL" = "xrelease"; then
AC_MSG_RESULT([no, release build])
ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
else
AC_MSG_RESULT([yes, debug build])
ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
fi
AC_SUBST(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)
])
@@ -338,6 +338,8 @@ BUILD_MANPAGES := @BUILD_MANPAGES@

BUILD_CDS_ARCHIVE := @BUILD_CDS_ARCHIVE@

ALLOW_ABSOLUTE_PATHS_IN_OUTPUT := @ALLOW_ABSOLUTE_PATHS_IN_OUTPUT@

# The boot jdk to use. This is overridden in bootcycle-spec.gmk. Make sure to keep
# it in sync.
BOOT_JDK:=@BOOT_JDK@
@@ -381,6 +383,7 @@ LIBFFI_CFLAGS:=@LIBFFI_CFLAGS@
ENABLE_LIBFFI_BUNDLING:=@ENABLE_LIBFFI_BUNDLING@
LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@
GRAALUNIT_LIB := @GRAALUNIT_LIB@
FILE_MACRO_CFLAGS := @FILE_MACRO_CFLAGS@

STATIC_LIBS_CFLAGS := @STATIC_LIBS_CFLAGS@

@@ -204,6 +204,68 @@ DEPENDENCY_TARGET_SED_PATTERN := \
-e 's/$$$$/ :/' \
#

################################################################################
# When absolute paths are not allowed in the output, and the compiler does not
# support any options to avoid it, we need to rewrite compile commands to use
# relative paths. By doing this, the __FILE__ macro will resolve to relative
# paths. The relevant input paths on the command line are the -I flags and the
# path to the source file itself.
#
# The macro MakeCommandRelative is used to rewrite the command line like this:
# 'CD $(WORKSPACE_ROOT) && <cmd>'
# and changes all paths in cmd to be relative to the workspace root. This only
# works properly if the build dir is inside the workspace root. If it's not,
# relative paths are still calculated, but depending on the distance between the
# dirs, paths in the build dir may end up as essentially absolute anyway.
#
# The fix-deps-file macro is used to adjust the contents of the generated make
# dependency files to contain paths compatible with make.
#
ifeq ($(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)-$(FILE_MACRO_CFLAGS), false-)
# Need to handle -I flags as both '-Ifoo' and '-I foo'.
MakeCommandRelative = \
$(CD) $(WORKSPACE_ROOT) && \
$(foreach o, $1, \
$(if $(filter $(WORKSPACE_ROOT)/% $(OUTPUTDIR)/%, $o), \
$(call RelativePath, $o, $(WORKSPACE_ROOT)) \
, \
$(if $(filter -I$(WORKSPACE_ROOT)/%, $o), \
-I$(call RelativePath, $(patsubst -I%, %, $o), $(WORKSPACE_ROOT)) \
, \
$o \
) \
) \
)

# When compiling with relative paths, the deps file comes out with relative
# paths.
ifeq ($(TOOLCHAIN_TYPE), solstudio)
define fix-deps-file
$(SED) -e 's|\./|$(WORKSPACE_ROOT)/|g' $1.tmp > $1
endef
else
define fix-deps-file
$(SED) -e 's|^\([ ]*\)|\1$(WORKSPACE_ROOT)|' $1.tmp > $1
endef
endif
else
# By default the MakeCommandRelative macro does nothing.
MakeCommandRelative = $1

# Even with absolute paths on the command line, the Solaris studio compiler
# doesn't output the full path to the object file in the generated deps files.
# For other toolchains, no adjustment is needed.
ifeq ($(TOOLCHAIN_TYPE), solstudio)
define fix-deps-file
$(SED) 's|^$$(@F):|$$@:|' $1.tmp > $1
endef
else
define fix-deps-file
$(MV) $1.tmp $1
endef
endif
endif

################################################################################
# Create the recipe needed to compile a single native source file.
#
@@ -214,7 +276,6 @@ DEPENDENCY_TARGET_SED_PATTERN := \
# Remaining parameters are named arguments:
# FILE - The full path of the source file to compiler
# BASE - The name of the rule for the entire binary to build ($1)
# DISABLE_THIS_FILE_DEFINE - Set to true to disable the THIS_FILE define.
#
SetupCompileNativeFile = $(NamedParamsMacroTemplate)
define SetupCompileNativeFileBody
@@ -236,12 +297,6 @@ define SetupCompileNativeFileBody
# This is the definite source file to use for $1_FILENAME.
$1_SRC_FILE := $$($1_FILE)

ifneq ($$($1_DEFINE_THIS_FILE), false)
ifneq ($$($$($1_BASE)_DEFINE_THIS_FILE), false)
$1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
endif
endif

ifeq ($$($1_OPTIMIZATION), )
$1_OPT_CFLAGS := $$($$($1_BASE)_OPT_CFLAGS)
$1_OPT_CXXFLAGS := $$($$($1_BASE)_OPT_CXXFLAGS)
@@ -284,13 +339,13 @@ define SetupCompileNativeFileBody
ifneq ($$(filter %.c, $$($1_FILENAME)), )
# Compile as a C file
$1_FLAGS := $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) $$($1_BASE_CFLAGS) \
$$($1_OPT_CFLAGS) $$($1_CFLAGS) $$($1_THIS_FILE) -c
$$($1_OPT_CFLAGS) $$($1_CFLAGS) -c
$1_COMPILER := $$($$($1_BASE)_CC)
$1_DEP_FLAG := $(C_FLAG_DEPS)
else ifneq ($$(filter %.m, $$($1_FILENAME)), )
# Compile as an Objective-C file
$1_FLAGS := -x objective-c $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) \
$$($1_BASE_CFLAGS) $$($1_OPT_CFLAGS) $$($1_CFLAGS) $$($1_THIS_FILE) -c
$$($1_BASE_CFLAGS) $$($1_OPT_CFLAGS) $$($1_CFLAGS) -c
$1_COMPILER := $$($$($1_BASE)_CC)
$1_DEP_FLAG := $(C_FLAG_DEPS)
else ifneq ($$(filter %.s %.S, $$($1_FILENAME)), )
@@ -301,7 +356,7 @@ define SetupCompileNativeFileBody
else ifneq ($$(filter %.cpp %.cc %.mm, $$($1_FILENAME)), )
# Compile as a C++ or Objective-C++ file
$1_FLAGS := $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) $$($1_BASE_CXXFLAGS) \
$$($1_OPT_CXXFLAGS) $$($1_CXXFLAGS) $$($1_THIS_FILE) -c
$$($1_OPT_CXXFLAGS) $$($1_CXXFLAGS) -c
$1_COMPILER := $$($$($1_BASE)_CXX)
$1_DEP_FLAG := $(CXX_FLAG_DEPS)
else
@@ -341,21 +396,17 @@ define SetupCompileNativeFileBody
$$(call LogInfo, Compiling $$($1_FILENAME) (for $$($$($1_BASE)_BASENAME)))
$$(call MakeDir, $$(@D))
ifneq ($(TOOLCHAIN_TYPE), microsoft)
ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s, $$($1_FILENAME)), solstudio)
# The Solaris studio compiler doesn't output the full path to the
# object file in the generated deps files. Fixing it with sed. If
# compiling assembly, don't try this.
$$(call ExecuteWithLog, $$@, \
$$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEPS_FILE).tmp $$($1_COMPILE_OPTIONS))
$(SED) 's|^$$(@F):|$$@:|' $$($1_DEPS_FILE).tmp > $$($1_DEPS_FILE)
else
$$(call ExecuteWithLog, $$@, \
$$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEPS_FILE) $$($1_COMPILE_OPTIONS))
endif
# Create a dependency target file from the dependency file.
# Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
$$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
$$($1_COMPILER) $$($1_DEP_FLAG) \
$$(addsuffix .tmp, $$($1_DEPS_FILE)) \
$$($1_COMPILE_OPTIONS)))
ifneq ($$($1_DEPS_FILE), )
$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
$$(call fix-deps-file, $$($1_DEPS_FILE))
# Create a dependency target file from the dependency file.
# Solution suggested by:
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) \
> $$($1_DEPS_TARGETS_FILE)
endif
else
# The Visual Studio compiler lacks a feature for generating make
@@ -365,8 +416,8 @@ define SetupCompileNativeFileBody
# Keep as much as possible on one execution line for best performance
# on Windows. No need to save exit code from compilation since
# pipefail is always active on Windows.
$$(call ExecuteWithLog, $$@, \
$$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS)) \
$$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
$$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS))) \
| $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
-e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
$(ECHO) $$@: \\ > $$($1_DEPS_FILE) ; \
@@ -430,7 +481,6 @@ endef
# STRIPFLAGS Optionally change the flags given to the strip command
# PRECOMPILED_HEADER Header file to use as precompiled header
# PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
# DEFINE_THIS_FILE Set to false to not set the THIS_FILE preprocessor macro
#
# After being called, some variables are exported from this macro, all prefixed
# with parameter 1 followed by a '_':
@@ -734,7 +784,6 @@ define SetupNativeCompilationBody
FILE := $$($1_GENERATED_PCH_SRC), \
BASE := $1, \
EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
DEFINE_THIS_FILE := false, \
))

$1_USE_PCH_FLAGS := \
@@ -769,7 +818,8 @@ define SetupNativeCompilationBody
$$($1_PCH_FILE): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
$$(call LogInfo, Generating precompiled header)
$$(call MakeDir, $$(@D))
$$(call ExecuteWithLog, $$@, $$($1_PCH_COMMAND) $$< -o $$@)
$$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
$$($1_PCH_COMMAND) $$< -o $$@))
$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_PCH_DEPS_FILE) \
> $$($1_PCH_DEPS_TARGETS_FILE)

@@ -825,9 +875,9 @@ define SetupNativeCompilationBody
$$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
$$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$($1_BASENAME)))
$$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
$$(call ExecuteWithLog, $$@, \
$$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
$$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
$$($1_VERSIONINFO_RESOURCE) 2>&1 )
$$($1_VERSIONINFO_RESOURCE) 2>&1 ))
# Windows RC compiler does not support -showIncludes, so we mis-use CL
# for this. Filter out RC specific arguments that are unknown to CL.
# For some unknown reason, in this case CL actually outputs the show
@@ -38,6 +38,7 @@ define SetupCharacterData
$$(call LogInfo, Generating $1.java)
$$(call MakeDir, $$(@D))
$(TOOL_GENERATECHARACTER) $2 \
$(if $(call equals, $(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT), true), -d) \
-template $(CHARACTERDATA)/$1.java.template \
-spec $(UNICODEDATA)/UnicodeData.txt \
-specialcasing $(UNICODEDATA)/SpecialCasing.txt \
@@ -81,7 +81,9 @@ ifneq ($(MOD_FILES), )
$(call DependOnVariable, ALL_MODULES)
$(call MakeTargetDir)
$(RM) $@ $@.tmp
$(TOOL_GENMODULEINFOSOURCE) -o $@.tmp \
$(TOOL_GENMODULEINFOSOURCE) \
$(if $(call equals, $(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT), true), -d) \
-o $@.tmp \
--source-file $< \
--modules $(call CommaList, $(ALL_MODULES)) \
$(MOD_FILES)

0 comments on commit 4df99aa

Please sign in to comment.