blob: 4a44837c54c08f9bf53bbe5bba379cbad80eee61 [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
Cole Faust81f1e922022-04-08 11:12:10 -070018define gather-all-makefiles-for-current-product
Cole Fauste23ae982022-02-28 14:20:48 -080019$(eval _all_products_visited := )\
Cole Faust81f1e922022-04-08 11:12:10 -070020$(sort $(call gather-all-makefiles-for-current-product-inner,$(INTERNAL_PRODUCT)))
Joe Onorato88155422012-07-23 13:51:44 -070021endef
22
Cole Faust81f1e922022-04-08 11:12:10 -070023define gather-all-makefiles-for-current-product-inner
Joe Onorato88155422012-07-23 13:51:44 -070024 $(foreach p,$(1),\
25 $(if $(filter $(p),$(_all_products_visited)),, \
26 $(p) \
27 $(eval _all_products_visited += $(p)) \
Cole Faust23b94e62022-04-27 11:55:08 -070028 $(call gather-all-makefiles-for-current-product-inner, $(PRODUCTS.$(strip $(p)).INHERITS_FROM))
Joe Onorato88155422012-07-23 13:51:44 -070029 ) \
30 )
31endef
32
Anton Hansson6ea18292019-05-16 11:09:57 +010033node_color_target := orange
34node_color_common := beige
35node_color_vendor := lavenderblush
36node_color_default := white
37define node-color
Cole Faust81f1e922022-04-08 11:12:10 -070038$(if $(filter $(1),$(PRIVATE_TOP_LEVEL_MAKEFILE)),\
Anton Hansson6ea18292019-05-16 11:09:57 +010039 $(node_color_target),\
40 $(if $(filter build/make/target/product/%,$(1)),\
41 $(node_color_common),\
42 $(if $(filter vendor/%,$(1)),$(node_color_vendor),$(node_color_default))\
43 )\
44)
45endef
46
Cole Faust81f1e922022-04-08 11:12:10 -070047open_parethesis := (
48close_parenthesis := )
49
Ying Wang3670c842013-08-01 17:45:35 -070050# Emit properties of a product node to a file.
51# $(1) the product
52# $(2) the output file
53define emit-product-node-props
54$(hide) echo \"$(1)\" [ \
Cole Faust81f1e922022-04-08 11:12:10 -070055label=\"$(dir $(1))\\n$(notdir $(1))$(if $(filter $(1),$(PRIVATE_TOP_LEVEL_MAKEFILE)),$(subst $(open_parethesis),,$(subst $(close_parenthesis),,\\n\\n$(PRODUCT_MODEL)\\n$(PRODUCT_DEVICE))))\" \
Anton Hansson6ea18292019-05-16 11:09:57 +010056style=\"filled\" fillcolor=\"$(strip $(call node-color,$(1)))\" \
Cole Fauste23ae982022-02-28 14:20:48 -080057colorscheme=\"svg\" fontcolor=\"darkblue\" \
Ying Wang3670c842013-08-01 17:45:35 -070058] >> $(2)
59
60endef
61
Cole Faust81f1e922022-04-08 11:12:10 -070062products_graph := $(OUT_DIR)/products.dot
Joe Onorato88155422012-07-23 13:51:44 -070063
Cole Faust81f1e922022-04-08 11:12:10 -070064$(products_graph): PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT := $(call gather-all-makefiles-for-current-product)
65$(products_graph): PRIVATE_TOP_LEVEL_MAKEFILE := $(INTERNAL_PRODUCT)
66$(products_graph):
67 @echo Product graph DOT: $@ for $(PRIVATE_TOP_LEVEL_MAKEFILE)
68 $(hide) echo 'digraph {' > $@
69 $(hide) echo 'graph [ ratio=.5 ];' >> $@
70 $(hide) $(foreach p,$(PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT), \
71 $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), echo \"$(d)\" -\> \"$(p)\" >> $@;))
72 $(foreach p,$(PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT),$(call emit-product-node-props,$(p),$@))
73 $(hide) echo '}' >> $@
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -080074
Dan Willemsen7a1da0e2018-07-24 01:21:12 -070075.PHONY: product-graph
Anton Hansson627cf052019-03-19 18:18:42 +000076product-graph: $(products_graph)
77 @echo Product graph .dot file: $(products_graph)
78 @echo Command to convert to pdf: dot -Tpdf -Nshape=box -o $(OUT_DIR)/products.pdf $(products_graph)
79 @echo Command to convert to svg: dot -Tsvg -Nshape=box -o $(OUT_DIR)/products.svg $(products_graph)