make/common/SetupJavaCompilers.gmk
author ihse
Tue, 04 Dec 2018 11:08:07 +0100
branchihse-errorprone-branch
changeset 57056 85a97ef23187
parent 56846 1186bac4e290
permissions -rw-r--r--
Modify source to make errorprone complain.

#
# Copyright (c) 2011, 2018, 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
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

ifndef _SETUP_GMK
_SETUP_GMK := 1

# Include custom extension hook
$(eval $(call IncludeCustomExtension, common/SetupJavaCompilers.gmk))

include JavaCompilation.gmk

DISABLE_WARNINGS ?= -Xlint:all,-deprecation,-removal,-unchecked,-rawtypes,-cast,-serial,-dep-ann,-static,-fallthrough,-try,-varargs,-empty,-finally

# If warnings needs to be non-fatal for testing purposes use a command like:
# make JAVAC_WARNINGS="-Xlint:all -Xmaxwarns 10000"
JAVAC_WARNINGS ?= -Xlint:all -Werror

# The BOOT_JAVAC setup uses the boot jdk compiler to compile the tools
# and the interim javac, to be run by the boot jdk.
$(eval $(call SetupJavaCompiler,BOOT_JAVAC, \
    JAVAC := $(JAVAC), \
    FLAGS := \
        $(JAVA_TOOL_FLAGS_SMALL) \
        $(BOOT_JDK_SOURCETARGET) \
        -XDignore.symbol.file=true -g \
        -Xlint:all$(COMMA)-deprecation$(COMMA)-options -Werror, \
    DISABLE_SJAVAC := true, \
))

# Any java code executed during a JDK build to build other parts of the JDK must be
# executed by the bootstrap JDK (probably with -Xbootclasspath/p: ) and for this
# purpose must be built with -target PREVIOUS for bootstrapping purposes, which
# requires restricting to language level and api of previous JDK.
#
# The generate old bytecode javac setup uses the new compiler to compile for the
# boot jdk to generate tools that need to be run with the boot jdk.
# Thus we force the target bytecode to the previous JDK version.
# Add -Xlint:-options to avoid the warning about not setting -bootclasspath. Since
# it's running on the boot jdk, the default bootclasspath is correct.
$(eval $(call SetupJavaCompiler,GENERATE_OLDBYTECODE, \
    JVM := $(JAVA_SMALL), \
    JAVAC := $(NEW_JAVAC), \
    FLAGS := $(BOOT_JDK_SOURCETARGET) -XDignore.symbol.file=true -XDstringConcat=inline \
        $(DISABLE_WARNINGS) -Xlint:-options, \
    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
    SERVER_JVM := $(SJAVAC_SERVER_JAVA)))

ifneq ($(ERRORPRONE_JAR), )
  # Extra flags needed to run bootstrap javac with the errorprone static code
  # analysis tool as -Xplugin.

  ERRORPRONE_JAVA_FLAGS := \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.api=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.util=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.tree=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.main=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.code=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.processing=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.parser=ALL-UNNAMED \
          --add-exports jdk.compiler.interim/com.sun.tools.javac.comp=ALL-UNNAMED \
          --add-opens=jdk.compiler.interim/com.sun.tools.javac.comp=ALL-UNNAMED \
          #

          # --add-modules java.logging \

  ERRORPRONE_JAVAC_FLAGS := \
          '-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \
          -XDcompilePolicy=byfile \
          #
endif

# The generate new bytecode javac setup uses the new compiler to compile for the
# new jdk. This new bytecode might only be possible to run using the new jvm.
$(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE, \
    JVM := $(JAVA_JAVAC) $(ERRORPRONE_JAVA_FLAGS), \
    JAVAC := $(NEW_JAVAC), \
    FLAGS := -source 12 -target 12 --doclint-format html5 \
        -encoding ascii -XDignore.symbol.file=true $(JAVAC_WARNINGS) \
        $(ERRORPRONE_JAVAC_FLAGS), \
    PROCESSORPATH := $(ERRORPRONE_JAR), \
    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
    SERVER_JVM := $(SJAVAC_SERVER_JAVA)))

# The generate new bytecode javac setup uses the new compiler to compile for the
# new jdk. This new bytecode might only be possible to run using the new jvm.
$(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE_NOWARNINGS, \
    JVM := $(JAVA_JAVAC), \
    JAVAC := $(NEW_JAVAC), \
    FLAGS := -source 12 -target 12 \
        -encoding ascii -XDignore.symbol.file=true $(DISABLE_WARNINGS), \
    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
    SERVER_JVM := $(SJAVAC_SERVER_JAVA)))

# After the jdk is built, we want to build demos using only the recently
# generated jdk classes and nothing else, no jdk source, etc etc.
# I.e. the rt.jar, but since rt.jar has not yet been generated
# (it will be in "make images") therefore we use classes instead.
$(eval $(call SetupJavaCompiler,GENERATE_USINGJDKBYTECODE, \
    JVM := $(JAVA_SMALL), \
    JAVAC := $(NEW_JAVAC), \
    FLAGS := --upgrade-module-path $(JDK_OUTPUTDIR)/modules --system none $(DISABLE_WARNINGS), \
    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
    SERVER_JVM := $(SJAVAC_SERVER_JAVA)))

# Use boot javac to generate JDK 8 compatible class files explicitly
$(eval $(call SetupJavaCompiler,GENERATE_8_BYTECODE, \
    JAVAC := $(JAVAC), \
    FLAGS := \
        $(JAVA_TOOL_FLAGS_SMALL) \
        --release 8 \
        -XDignore.symbol.file=true -g \
        -Xlint:all -Werror, \
    DISABLE_SJAVAC := true, \
))

endif # _SETUP_GMK