langtools/make/gensrc/GensrcCommon.gmk
author mcimadamore
Thu, 08 Jan 2015 14:43:05 +0000
changeset 28334 1633de6070ae
parent 27579 d1a63c99cdd5
child 28458 f20c5dd05e34
permissions -rw-r--r--
8058542: Devise scheme for better diagnostic creation Summary: Add support for generating (at build-time) an enum-like class containing all javac diagnostics, which allows for safe diagnostic creation. Reviewed-by: jlahoda, jjg, vromero, erikj, jfranck

#
# Copyright (c) 2014, 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.
#

# This must be the first rule
default: all

include $(SPEC)
include MakeBase.gmk
include JavaCompilation.gmk

################################################################################
# The compileprops tools compiles a properties file into a resource bundle.
TOOL_COMPILEPROPS_CMD := $(JAVA) -cp $(BUILDTOOLS_OUTPUTDIR)/langtools_tools_classes \
    compileproperties.CompileProperties -quiet

################################################################################
# The compileprops tools compiles a properties file into an enum-like class.
TOOL_PARSEPROPS_CMD := $(JAVA) -cp $(BUILDTOOLS_OUTPUTDIR)/langtools_tools_classes \
    propertiesparser.PropertiesParser


################################################################################
# Sets up a rule that creates a version.properties file in the gensrc output
# directory.
# Param 1 - Variable to add generated file name to
# Param 2 - Name of version.properties file including packages from the src
#           root.
define SetupVersionProperties
  $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/$$(strip $2):
	$(MKDIR) -p $$(@D)
	$(PRINTF) "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" \
	    > $$@

  $$(strip $1) += $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/$$(strip $2)
endef

################################################################################
# Finds all properties files in the module source and creates a rule that runs
# CompileProperties on them into the gensrc dir.
# Param 1 - Variable to add targets to
# Param 2 - Extra properties files to process
define SetupCompileProperties
  # Lookup the properties that need to be compiled into resource bundles.
  PROPSOURCES := $2 $$(shell $(FIND) $(LANGTOOLS_TOPDIR)/src/$(MODULE)/share/classes -name "*.properties")

  # Convert .../src/<module>/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties
  # to .../langtools/gensrc/<module>/com/sun/tools/javac/resources/javac_zh_CN.java
  # Strip away prefix and suffix, leaving for example only: 
  # "<module>/share/classes/com/sun/tools/javac/resources/javac_zh_CN"
  PROPJAVAS := $$(patsubst $(LANGTOOLS_TOPDIR)/src/%, \
      $(SUPPORT_OUTPUTDIR)/gensrc/%, \
      $$(patsubst %.properties, %.java, \
      $$(subst /share/classes,, $$(PROPSOURCES))))

  # Generate the package dirs for the tobe generated java files. Sort to remove
  # duplicates.
  PROPDIRS := $$(sort $$(dir $$(PROPJAVAS)))

  # Now generate a sequence of:
  # "-compile ...javac_zh_CN.properties ...javac_zh_CN.java java.util.ListResourceBundle"
  # suitable to be fed into the CompileProperties command.
  PROPCMDLINE := $$(subst _SPACE_, $(SPACE), \
      $$(join $$(addprefix -compile_SPACE_, $$(PROPSOURCES)), \
      $$(addsuffix _SPACE_java.util.ListResourceBundle, \
      $$(addprefix _SPACE_, $$(PROPJAVAS)))))

  # Now setup the rule for the generation of the resource bundles.
  $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the_props: $$(PROPSOURCES)
	$(FIND) $$(@D) -name "*.java" $(FIND_DELETE)
	$(MKDIR) -p $$(@D) $$(PROPDIRS)
	$(ECHO) Compiling $$(words $$(PROPSOURCES)) properties into resource bundles for $(MODULE)
	$(TOOL_COMPILEPROPS_CMD) $$(PROPCMDLINE)
	$(TOUCH) $$@

  $$(strip $1) += $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the_props
endef

################################################################################
# Parse property files in given location and generate a Java-like enum in the gensrc folder.
# Param 1 - Variable to add targets to
# Param 2 - Extra properties files to process
define SetupParseProperties
  #property file to generate
  PARSEPROPSOURCES := $$(foreach var,$2,$$(addsuffix $$(var),$(LANGTOOLS_TOPDIR)/src/$(MODULE)/share/classes/))  

  PARSEPROPALLDIRS := $$(patsubst $(LANGTOOLS_TOPDIR)/src/%, \
      $(SUPPORT_OUTPUTDIR)/gensrc/%, \
      $$(dir $$(PARSEPROPSOURCES)))

  PARSEPROPDIRS := $$(sort $$(PARSEPROPALLDIRS))

  PARSEPROPCMDLINE := $$(subst _SPACE_, $$(SPACE), \
    $$(join $$(foreach var,$$(PARSEPROPSOURCES),$$(addprefix -compile_SPACE_,$$(var))), \
    $$(addprefix _SPACE_, $$(PARSEPROPALLDIRS))))
  
  # Now setup the rule for the generation of the resource bundles.
  $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the_parsed_props: $(PARSEPROPSOURCES)
	$(CP) -r $(LANGTOOLS_TOPDIR)/make/tools/propertiesparser/resources $(BUILDTOOLS_OUTPUTDIR)/langtools_tools_classes/propertiesparser/resources
	$(MKDIR) -p $$(@D) $$(PARSEPROPDIRS)
	$(ECHO) Parsing $$(words $$(PARSEPROPSOURCES)) properties into enum-like class for $(MODULE)
	$(TOOL_PARSEPROPS_CMD) $$(PARSEPROPCMDLINE)
	$(TOUCH) $$@

  $$(strip $1) += $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the_parsed_props
endef

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