1#
2# Copyright (C) 2009 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# the foreach and the if remove the single space entries that creep in because of the evals
18define gather-all-products
19$(sort $(foreach p, \
20	$(eval _all_products_visited := )
21  $(call all-products-inner, $(PARENT_PRODUCT_FILES)) \
22	, $(if $(strip $(p)),$(strip $(p)),)) \
23)
24endef
25
26define all-products-inner
27	$(foreach p,$(1),\
28		$(if $(filter $(p),$(_all_products_visited)),, \
29			$(p) \
30			$(eval _all_products_visited += $(p)) \
31			$(call all-products-inner, $(PRODUCTS.$(strip $(p)).INHERITS_FROM))
32		) \
33	)
34endef
35
36this_makefile := build/make/core/product-graph.mk
37
38products_graph := $(OUT_DIR)/products.dot
39ifeq ($(strip $(ANDROID_PRODUCT_GRAPH)),)
40products_list := $(INTERNAL_PRODUCT)
41else
42ifeq ($(strip $(ANDROID_PRODUCT_GRAPH)),--all)
43products_list := --all
44else
45products_list := $(foreach prod,$(ANDROID_PRODUCT_GRAPH),$(call resolve-short-product-name,$(prod)))
46endif
47endif
48
49all_products := $(call gather-all-products)
50
51open_parethesis := (
52close_parenthesis := )
53
54node_color_target := orange
55node_color_common := beige
56node_color_vendor := lavenderblush
57node_color_default := white
58define node-color
59$(if $(filter $(1),$(PRIVATE_PRODUCTS_FILTER)),\
60  $(node_color_target),\
61  $(if $(filter build/make/target/product/%,$(1)),\
62    $(node_color_common),\
63    $(if $(filter vendor/%,$(1)),$(node_color_vendor),$(node_color_default))\
64  )\
65)
66endef
67
68# Emit properties of a product node to a file.
69# $(1) the product
70# $(2) the output file
71define emit-product-node-props
72$(hide) echo \"$(1)\" [ \
73label=\"$(dir $(1))\\n$(notdir $(1))\\n\\n$(subst $(close_parenthesis),,$(subst $(open_parethesis),,$(call get-product-var,$(1),PRODUCT_MODEL)))\\n$(call get-product-var,$(1),PRODUCT_DEVICE)\" \
74style=\"filled\" fillcolor=\"$(strip $(call node-color,$(1)))\" \
75colorscheme=\"svg\" fontcolor=\"darkblue\" href=\"products/$(1).html\" \
76] >> $(2)
77
78endef
79
80$(products_graph): PRIVATE_PRODUCTS := $(all_products)
81$(products_graph): PRIVATE_PRODUCTS_FILTER := $(products_list)
82
83$(products_graph): $(this_makefile)
84	@echo Product graph DOT: $@ for $(PRIVATE_PRODUCTS_FILTER)
85	$(hide) echo 'digraph {' > $@.in
86	$(hide) echo 'graph [ ratio=.5 ];' >> $@.in
87	$(hide) $(foreach p,$(PRIVATE_PRODUCTS), \
88	  $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), echo \"$(d)\" -\> \"$(p)\" >> $@.in;))
89	$(foreach p,$(PRIVATE_PRODUCTS),$(call emit-product-node-props,$(p),$@.in))
90	$(hide) echo '}' >> $@.in
91	$(hide) build/make/tools/filter-product-graph.py $(PRIVATE_PRODUCTS_FILTER) < $@.in > $@
92
93# Evaluates to the name of the product file
94# $(1) product file
95define product-debug-filename
96$(OUT_DIR)/products/$(strip $(1)).html
97endef
98
99# Makes a rule for the product debug info
100# $(1) product file
101define transform-product-debug
102$(OUT_DIR)/products/$(strip $(1)).txt: $(this_makefile)
103	@echo Product debug info file: $$@
104	$(hide) rm -f $$@
105	$(hide) mkdir -p $$(dir $$@)
106	$(hide) echo 'FILE=$(strip $(1))' >> $$@
107	$(hide) echo 'PRODUCT_NAME=$(call get-product-var,$(1),PRODUCT_NAME)' >> $$@
108	$(hide) echo 'PRODUCT_MODEL=$(call get-product-var,$(1),PRODUCT_MODEL)' >> $$@
109	$(hide) echo 'PRODUCT_LOCALES=$(call get-product-var,$(1),PRODUCT_LOCALES)' >> $$@
110	$(hide) echo 'PRODUCT_AAPT_CONFIG=$(call get-product-var,$(1),PRODUCT_AAPT_CONFIG)' >> $$@
111	$(hide) echo 'PRODUCT_AAPT_PREF_CONFIG=$(call get-product-var,$(1),PRODUCT_AAPT_PREF_CONFIG)' >> $$@
112	$(hide) echo 'PRODUCT_PACKAGES=$(call get-product-var,$(1),PRODUCT_PACKAGES)' >> $$@
113	$(hide) echo 'PRODUCT_DEVICE=$(call get-product-var,$(1),PRODUCT_DEVICE)' >> $$@
114	$(hide) echo 'PRODUCT_MANUFACTURER=$(call get-product-var,$(1),PRODUCT_MANUFACTURER)' >> $$@
115	$(hide) echo 'PRODUCT_PROPERTY_OVERRIDES=$(call get-product-var,$(1),PRODUCT_PROPERTY_OVERRIDES)' >> $$@
116	$(hide) echo 'PRODUCT_DEFAULT_PROPERTY_OVERRIDES=$(call get-product-var,$(1),PRODUCT_DEFAULT_PROPERTY_OVERRIDES)' >> $$@
117	$(hide) echo 'PRODUCT_SYSTEM_DEFAULT_PROPERTIES=$(call get-product-var,$(1),PRODUCT_SYSTEM_DEFAULT_PROPERTIES)' >> $$@
118	$(hide) echo 'PRODUCT_PRODUCT_PROPERTIES=$(call get-product-var,$(1),PRODUCT_PRODUCT_PROPERTIES)' >> $$@
119	$(hide) echo 'PRODUCT_SYSTEM_EXT_PROPERTIES=$(call get-product-var,$(1),PRODUCT_SYSTEM_EXT_PROPERTIES)' >> $$@
120	$(hide) echo 'PRODUCT_ODM_PROPERTIES=$(call get-product-var,$(1),PRODUCT_ODM_PROPERTIES)' >> $$@
121	$(hide) echo 'PRODUCT_CHARACTERISTICS=$(call get-product-var,$(1),PRODUCT_CHARACTERISTICS)' >> $$@
122	$(hide) echo 'PRODUCT_COPY_FILES=$(call get-product-var,$(1),PRODUCT_COPY_FILES)' >> $$@
123	$(hide) echo 'PRODUCT_OTA_PUBLIC_KEYS=$(call get-product-var,$(1),PRODUCT_OTA_PUBLIC_KEYS)' >> $$@
124	$(hide) echo 'PRODUCT_EXTRA_RECOVERY_KEYS=$(call get-product-var,$(1),PRODUCT_EXTRA_RECOVERY_KEYS)' >> $$@
125	$(hide) echo 'PRODUCT_PACKAGE_OVERLAYS=$(call get-product-var,$(1),PRODUCT_PACKAGE_OVERLAYS)' >> $$@
126	$(hide) echo 'DEVICE_PACKAGE_OVERLAYS=$(call get-product-var,$(1),DEVICE_PACKAGE_OVERLAYS)' >> $$@
127	$(hide) echo 'PRODUCT_SDK_ADDON_NAME=$(call get-product-var,$(1),PRODUCT_SDK_ADDON_NAME)' >> $$@
128	$(hide) echo 'PRODUCT_SDK_ADDON_COPY_FILES=$(call get-product-var,$(1),PRODUCT_SDK_ADDON_COPY_FILES)' >> $$@
129	$(hide) echo 'PRODUCT_SDK_ADDON_COPY_MODULES=$(call get-product-var,$(1),PRODUCT_SDK_ADDON_COPY_MODULES)' >> $$@
130	$(hide) echo 'PRODUCT_SDK_ADDON_DOC_MODULES=$(call get-product-var,$(1),PRODUCT_SDK_ADDON_DOC_MODULES)' >> $$@
131	$(hide) echo 'PRODUCT_DEFAULT_WIFI_CHANNELS=$(call get-product-var,$(1),PRODUCT_DEFAULT_WIFI_CHANNELS)' >> $$@
132	$(hide) echo 'PRODUCT_DEFAULT_DEV_CERTIFICATE=$(call get-product-var,$(1),PRODUCT_DEFAULT_DEV_CERTIFICATE)' >> $$@
133	$(hide) echo 'PRODUCT_MAINLINE_SEPOLICY_DEV_CERTIFICATES=$(call get-product-var,$(1),PRODUCT_MAINLINE_SEPOLICY_DEV_CERTIFICATES)' >> $$@
134	$(hide) echo 'PRODUCT_RESTRICT_VENDOR_FILES=$(call get-product-var,$(1),PRODUCT_RESTRICT_VENDOR_FILES)' >> $$@
135	$(hide) echo 'PRODUCT_VENDOR_KERNEL_HEADERS=$(call get-product-var,$(1),PRODUCT_VENDOR_KERNEL_HEADERS)' >> $$@
136
137$(call product-debug-filename, $(p)): \
138			$(OUT_DIR)/products/$(strip $(1)).txt \
139			build/make/tools/product_debug.py \
140			$(this_makefile)
141	@echo Product debug html file: $$@
142	$(hide) mkdir -p $$(dir $$@)
143	$(hide) cat $$< | build/make/tools/product_debug.py > $$@
144endef
145
146product_debug_files:=
147$(foreach p,$(all_products), \
148			$(eval $(call transform-product-debug, $(p))) \
149			$(eval product_debug_files += $(call product-debug-filename, $(p))) \
150   )
151
152.PHONY: product-graph
153product-graph: $(products_graph)
154	@echo Product graph .dot file: $(products_graph)
155	@echo Command to convert to pdf: dot -Tpdf -Nshape=box -o $(OUT_DIR)/products.pdf $(products_graph)
156	@echo Command to convert to svg: dot -Tsvg -Nshape=box -o $(OUT_DIR)/products.svg $(products_graph)
157