blob: 6d51db17a9c2bcb7b33d278f9c7f1dba04839780 [file] [log] [blame]
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -08001#
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
Cole Fauste23ae982022-02-28 14:20:48 -080017# the sort also acts as a strip to remove the single space entries that creep in because of the evals
Joe Onorato88155422012-07-23 13:51:44 -070018define gather-all-products
Cole Fauste23ae982022-02-28 14:20:48 -080019$(eval _all_products_visited := )\
20$(sort $(call all-products-inner, $(PARENT_PRODUCT_FILES)))
Joe Onorato88155422012-07-23 13:51:44 -070021endef
22
23define all-products-inner
24 $(foreach p,$(1),\
25 $(if $(filter $(p),$(_all_products_visited)),, \
26 $(p) \
27 $(eval _all_products_visited += $(p)) \
28 $(call all-products-inner, $(PRODUCTS.$(strip $(p)).INHERITS_FROM))
29 ) \
30 )
31endef
32
Colin Cross6cdc5d22017-10-20 11:37:33 -070033this_makefile := build/make/core/product-graph.mk
Joe Onorato88155422012-07-23 13:51:44 -070034
Joe Onorato88155422012-07-23 13:51:44 -070035products_graph := $(OUT_DIR)/products.dot
Joe Onorato8b46e302012-05-07 17:15:15 -070036ifeq ($(strip $(ANDROID_PRODUCT_GRAPH)),)
37products_list := $(INTERNAL_PRODUCT)
38else
39ifeq ($(strip $(ANDROID_PRODUCT_GRAPH)),--all)
40products_list := --all
41else
42products_list := $(foreach prod,$(ANDROID_PRODUCT_GRAPH),$(call resolve-short-product-name,$(prod)))
43endif
44endif
45
Anton Hansson061cbcf2018-05-30 18:24:41 +010046all_products := $(call gather-all-products)
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -080047
Ying Wang3670c842013-08-01 17:45:35 -070048open_parethesis := (
49close_parenthesis := )
50
Anton Hansson6ea18292019-05-16 11:09:57 +010051node_color_target := orange
52node_color_common := beige
53node_color_vendor := lavenderblush
54node_color_default := white
55define node-color
56$(if $(filter $(1),$(PRIVATE_PRODUCTS_FILTER)),\
57 $(node_color_target),\
58 $(if $(filter build/make/target/product/%,$(1)),\
59 $(node_color_common),\
60 $(if $(filter vendor/%,$(1)),$(node_color_vendor),$(node_color_default))\
61 )\
62)
63endef
64
Ying Wang3670c842013-08-01 17:45:35 -070065# Emit properties of a product node to a file.
66# $(1) the product
67# $(2) the output file
68define emit-product-node-props
69$(hide) echo \"$(1)\" [ \
Anton Hanssoncca8cdb2019-10-28 11:30:40 +000070label=\"$(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)\" \
Anton Hansson6ea18292019-05-16 11:09:57 +010071style=\"filled\" fillcolor=\"$(strip $(call node-color,$(1)))\" \
Cole Fauste23ae982022-02-28 14:20:48 -080072colorscheme=\"svg\" fontcolor=\"darkblue\" \
Ying Wang3670c842013-08-01 17:45:35 -070073] >> $(2)
74
75endef
76
Anton Hansson061cbcf2018-05-30 18:24:41 +010077$(products_graph): PRIVATE_PRODUCTS := $(all_products)
Joe Onorato88155422012-07-23 13:51:44 -070078$(products_graph): PRIVATE_PRODUCTS_FILTER := $(products_list)
79
80$(products_graph): $(this_makefile)
Cole Faust985fa482021-10-07 17:14:23 -070081ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH)$(RBC_BOARD_CONFIG))
Joe Onorato88155422012-07-23 13:51:44 -070082 @echo Product graph DOT: $@ for $(PRIVATE_PRODUCTS_FILTER)
Ying Wang3670c842013-08-01 17:45:35 -070083 $(hide) echo 'digraph {' > $@.in
84 $(hide) echo 'graph [ ratio=.5 ];' >> $@.in
85 $(hide) $(foreach p,$(PRIVATE_PRODUCTS), \
86 $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), echo \"$(d)\" -\> \"$(p)\" >> $@.in;))
87 $(foreach p,$(PRIVATE_PRODUCTS),$(call emit-product-node-props,$(p),$@.in))
88 $(hide) echo '}' >> $@.in
Colin Crossfdea8932017-12-06 14:38:40 -080089 $(hide) build/make/tools/filter-product-graph.py $(PRIVATE_PRODUCTS_FILTER) < $@.in > $@
Sasha Smundak8d97bf52021-05-04 09:58:38 -070090else
91 @echo RBC_PRODUCT_CONFIG and RBC_NO_PRODUCT_GRAPH should be unset to generate product graph
92 false
93endif
Joe Onorato3366c072009-08-08 12:14:37 -070094
Cole Faust985fa482021-10-07 17:14:23 -070095ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH)$(RBC_BOARD_CONFIG))
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -080096
Dan Willemsen7a1da0e2018-07-24 01:21:12 -070097.PHONY: product-graph
Anton Hansson627cf052019-03-19 18:18:42 +000098product-graph: $(products_graph)
99 @echo Product graph .dot file: $(products_graph)
100 @echo Command to convert to pdf: dot -Tpdf -Nshape=box -o $(OUT_DIR)/products.pdf $(products_graph)
101 @echo Command to convert to svg: dot -Tsvg -Nshape=box -o $(OUT_DIR)/products.svg $(products_graph)
Sasha Smundak8d97bf52021-05-04 09:58:38 -0700102else
103.PHONY: product-graph
104 @echo RBC_PRODUCT_CONFIG and RBC_NO_PRODUCT_GRAPH should be unset to generate product graph
105 false
Cole Faust985fa482021-10-07 17:14:23 -0700106endif