make/GensrcModuleInfo.gmk
author bpb
Wed, 25 May 2016 15:51:09 -0700
changeset 39000 810f4edc8b50
parent 37981 e0375f6012c1
child 39110 712f29ba8708
permissions -rw-r--r--
8156580: Make TIFFTagSet subclasses final Summary: Change the class declarations to make TIFFTagSet subclasses final. Reviewed-by: prr

#
# Copyright (c) 2015, 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 file makes modifications to module-info.java files based on the build
# configuration.
#
# Depending on build platform, imported modules and optional parts of the build
# being active, some modules need to have extra exports, provides or uses
# declarations added to them. These optional extras are defined in .extra files:
#
# src/<module>/<share,platform>/classes/module-info.java.extra
#
# The contents of the .extra files are simply extra lines that could fit into
# the module-info file.
#
# This makefile is called once for each from-module with the variable
# MODULE naming the from-module.
#
# The modified module-info.java files are put in the gensrc directory where
# they will automatically override the static versions in the src tree.
#
################################################################################

default: all

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

################################################################################
# Define this here since jdk/make/Tools.gmk cannot be included from the top
# make directory. Should probably move some tools away from the jdk repo.
TOOL_GENMODULEINFOSOURCE = $(JAVA_SMALL) \
    $(INTERIM_LANGTOOLS_ARGS) \
    -cp "$(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes" \
    build.tools.module.GenModuleInfoSource

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

# Name of data file. Keep module-info.java.ext until javafx has changed.
MOD_FILENAME := module-info.java.extra module-info.java.ext

# Construct all possible src directories for the module.
MODULE_CLASSES_DIRS := $(call FindModuleSrcDirs, $(MODULE))

# Find all the .extra files in the src dirs.
MOD_FILES := $(wildcard $(foreach f, $(MOD_FILENAME), $(addsuffix /$(f), \
    $(MODULE_CLASSES_DIRS))))

ifneq ($(MOD_FILES), )
  # Only make this call if modification files are found for this module
  ALL_MODULES := $(call FindAllModules)

  # Read the contents of all the files into a variable. Replace space with / to
  # let space represent new lines in the variable as $(shell) normalizes all
  # whitespace.
  $(foreach f, $(MOD_FILES), \
    $(eval MOD_FILE_CONTENTS += $(shell $(GREP) -v -e ".\*" -e "//" $f | $(TR) ' ' '/')))

  # Separate the modifications into qualified exports and the rest
  MODS_QUALIFIED_EXPORTS := $(call containing, /to/, $(MOD_FILE_CONTENTS))
  MODS_REST := $(filter-out $(MODS_QUALIFIED_EXPORTS), $(MOD_FILE_CONTENTS))

  # Filter the contents for modules that are actually being built
  ALL_MODULES_FILTER := $(addprefix %/, $(addsuffix ;, $(ALL_MODULES)))
  MODIFICATIONS := $(filter $(ALL_MODULES_FILTER), $(MODS_QUALIFIED_EXPORTS)) \
      $(MODS_REST)

  # Returns non empty if the package exists in the current module
  # Param 1 - Name of package with dots
  PackageExists = \
      $(strip $(wildcard $(addsuffix $(subst .,/,/$(strip $1)), \
          $(MODULE_CLASSES_DIRS) \
          $(addsuffix /$(MODULE), $(IMPORT_MODULES_CLASSES)) \
      )))

  # Convert the modification lines into arguments for the modification tool.
  # Filter out modifications for non existing to-modules.
  $(foreach line, $(MODIFICATIONS), \
    $(eval split_line := $(subst /,$(SPACE),$(line))) \
    $(eval command := $(word 1, $(split_line))) \
    $(if $(filter $(command), exports), \
      $(eval package := $(patsubst %;,%,$(word 2, $(split_line)))) \
      $(if $(call PackageExists, $(package)), \
        $(eval to_module := $(patsubst %;,%,$(word 4, $(split_line)))) \
        $(if $(to_module), \
          $(eval ARGS += -$(command) $(package)/$(to_module)) \
        , \
          $(eval ARGS += -$(command) $(package)) \
        ) \
      ) \
    , \
      $(if $(filter $(command), provides), \
        $(eval provider := $(patsubst %;,%,$(word 2, $(split_line)))) \
        $(eval class := $(patsubst %;,%,$(word 4, $(split_line)))) \
        $(eval ARGS += -$(command) $(provider)/$(class)) \
      , \
        $(error A module-info.extra in $(MODULE) contains invalid command $(command)) \
      ) \
    ) \
  )

  ifneq ($(ARGS), )
    $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/module-info.java: \
        $(firstword $(call FindAllModuleInfos, $(MODULE))) \
        $(BUILD_TOOLS_JDK) \
        $(call DependOnVariable, ARGS)
		$(MKDIR) -p $(@D)
		$(RM) $@ $@.tmp
		$(TOOL_GENMODULEINFOSOURCE) $(ARGS) -o $@.tmp $<
		$(MV) $@.tmp $@

    TARGETS += $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/module-info.java
  endif

endif

# If no modifications are found for this module, remove any module-info.java
# created by a previous build since that is no longer valid.
ifeq ($(MODIFICATIONS), )
  ifneq ($(wildcard $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/module-info.java), )
    $(shell $(RM) $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/module-info.java)
  endif
endif

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

all: $(TARGETS)