Home | History | Annotate | Download | only in tasks
      1 #
      2 # Copyright (C) 2015 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 #
     16 
     17 # Print modules and their transitive dependencies with license files.
     18 # To invoke, run "make deps-license PROJ_PATH=<proj-path-patterns> DEP_PATH=<dep-path-patterns>".
     19 # PROJ_PATH restricts the paths of the source modules; DEP_PATH restricts the paths of the dependency modules.
     20 # Both can be makefile patterns supported by makefile function $(filter).
     21 # Example: "make deps-license packages/app/% external/%" prints all modules in packages/app/ with their dpendencies in external/.
     22 # The printout lines look like "<module_name> :: <module_paths> :: <license_files>".
     23 
     24 ifneq (,$(filter deps-license,$(MAKECMDGOALS)))
     25 ifndef PROJ_PATH
     26 $(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.)
     27 endif
     28 ifndef DEP_PATH
     29 $(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.)
     30 endif
     31 
     32 # Expand a module's dependencies transitively.
     33 # $(1): the variable name to hold the result.
     34 # $(2): the initial module name.
     35 define get-module-all-dependencies
     36 $(eval _gmad_new := $(sort $(filter-out $($(1)),\
     37   $(foreach m,$(2),$(ALL_DEPS.$(m).ALL_DEPS)))))\
     38 $(if $(_gmad_new),$(eval $(1) += $(_gmad_new))\
     39   $(call get-module-all-dependencies,$(1),$(_gmad_new)))
     40 endef
     41 
     42 define print-deps-license
     43 $(foreach m, $(ALL_DEPS.MODULES),\
     44   $(eval m_p := $(sort $(ALL_MODULES.$(m).PATH) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\
     45   $(if $(filter $(PROJ_PATH),$(m_p)),\
     46     $(eval deps :=)\
     47     $(eval $(call get-module-all-dependencies,deps,$(m)))\
     48     $(info $(m) :: $(m_p) :: $(ALL_DEPS.$(m).LICENSE))\
     49     $(foreach d,$(deps),\
     50       $(eval d_p := $(sort $(ALL_MODULES.$(d).PATH) $(ALL_MODULES.$(d)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\
     51       $(if $(filter $(DEP_PATH),$(d_p)),\
     52         $(info $(space)$(space)$(space)$(space)$(d) :: $(d_p) :: $(ALL_DEPS.$(d).LICENSE))))))
     53 endef
     54 
     55 .PHONY: deps-license
     56 deps-license:
     57 	@$(call print-deps-license)
     58 
     59 endif
     60