Merge "Create lists of projects to share per dist target" am: 746806b3bb

Original change: https://android-review.googlesource.com/c/platform/build/+/2064290

Change-Id: Ib35ef1c1a8da7d81ce63aede3bc36d6ff99f7597
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2022-04-14 22:27:39 +00:00 committed by Automerger Merge Worker
commit 8a4f747caf
2 changed files with 72 additions and 8 deletions

View file

@ -570,16 +570,21 @@ define license-metadata-dir
$(call generated-sources-dir-for,META,lic,)
endef
TARGETS_MISSING_LICENSE_METADATA:=
###########################################################
# License metadata targets corresponding to targets in $(1)
###########################################################
define corresponding-license-metadata
$(strip $(foreach target, $(sort $(1)), \
$(strip $(filter-out 0p,$(foreach target, $(sort $(1)), \
$(if $(strip $(ALL_MODULES.$(target).META_LIC)), \
$(ALL_MODULES.$(target).META_LIC), \
$(if $(strip $(ALL_TARGETS.$(target).META_LIC)), \
$(ALL_TARGETS.$(target).META_LIC), \
$(call append-path,$(call license-metadata-dir),$(patsubst $(OUT_DIR)%,out%,$(target).meta_lic))))))
$(eval TARGETS_MISSING_LICENSE_METADATA += $(target)) \
) \
) \
)))
endef
###########################################################
@ -717,6 +722,7 @@ define declare-license-metadata
$(strip \
$(eval _tgt := $(subst //,/,$(strip $(1)))) \
$(eval ALL_NON_MODULES += $(_tgt)) \
$(eval ALL_TARGETS.$(_tgt).META_LIC := $(call license-metadata-dir)/$(patsubst $(OUT_DIR)%,out%,$(_tgt)).meta_lic) \
$(eval ALL_NON_MODULES.$(_tgt).LICENSE_KINDS := $(strip $(2))) \
$(eval ALL_NON_MODULES.$(_tgt).LICENSE_CONDITIONS := $(strip $(3))) \
$(eval ALL_NON_MODULES.$(_tgt).NOTICES := $(strip $(4))) \
@ -757,6 +763,7 @@ define declare-container-license-metadata
$(strip \
$(eval _tgt := $(subst //,/,$(strip $(1)))) \
$(eval ALL_NON_MODULES += $(_tgt)) \
$(eval ALL_TARGETS.$(_tgt).META_LIC := $(call license-metadata-dir)/$(patsubst $(OUT_DIR)%,out%,$(_tgt)).meta_lic) \
$(eval ALL_NON_MODULES.$(_tgt).LICENSE_KINDS := $(strip $(2))) \
$(eval ALL_NON_MODULES.$(_tgt).LICENSE_CONDITIONS := $(strip $(3))) \
$(eval ALL_NON_MODULES.$(_tgt).NOTICES := $(strip $(4))) \
@ -829,6 +836,7 @@ define declare-license-deps
$(strip \
$(eval _tgt := $(strip $(1))) \
$(eval ALL_NON_MODULES += $(_tgt)) \
$(eval ALL_TARGETS.$(_tgt).META_LIC := $(call license-metadata-dir)/$(patsubst $(OUT_DIR)%,out%,$(_tgt)).meta_lic) \
$(eval ALL_NON_MODULES.$(_tgt).DEPENDENCIES := $(strip $(ALL_NON_MODULES.$(_tgt).DEPENDENCIES) $(2))) \
)
endef
@ -845,6 +853,7 @@ define declare-container-license-deps
$(strip \
$(eval _tgt := $(strip $(1))) \
$(eval ALL_NON_MODULES += $(_tgt)) \
$(eval ALL_TARGETS.$(_tgt).META_LIC := $(call license-metadata-dir)/$(patsubst $(OUT_DIR)%,out%,$(_tgt)).meta_lic) \
$(eval ALL_NON_MODULES.$(_tgt).DEPENDENCIES := $(strip $(ALL_NON_MODULES.$(_tgt).DEPENDENCIES) $(2))) \
$(eval ALL_NON_MODULES.$(_tgt).IS_CONTAINER := true) \
$(eval ALL_NON_MODULES.$(_tgt).ROOT_MAPPINGS := $(strip $(ALL_NON_MODULES.$(_tgt).ROOT_MAPPINGS) $(3))) \
@ -856,12 +865,13 @@ endef
###########################################################
define report-missing-licenses-rule
.PHONY: reportmissinglicenses
reportmissinglicenses: PRIVATE_NON_MODULES:=$(sort $(NON_MODULES_WITHOUT_LICENSE_METADATA))
reportmissinglicenses: PRIVATE_NON_MODULES:=$(sort $(NON_MODULES_WITHOUT_LICENSE_METADATA) $(TARGETS_MISSING_LICENSE_METADATA))
reportmissinglicenses: PRIVATE_COPIED_FILES:=$(sort $(filter $(NON_MODULES_WITHOUT_LICENSE_METADATA),$(foreach _pair,$(PRODUCT_COPY_FILES), $(PRODUCT_OUT)/$(call word-colon,2,$(_pair)))))
reportmissinglicenses:
@echo Reporting $$(words $$(PRIVATE_NON_MODULES)) targets without license metadata
$$(foreach t,$$(PRIVATE_NON_MODULES),if ! [ -h $$(t) ]; then echo No license metadata for $$(t) >&2; fi;)
$$(foreach t,$$(PRIVATE_COPIED_FILES),if ! [ -h $$(t) ]; then echo No license metadata for copied file $$(t) >&2; fi;)
echo $$(words $$(PRIVATE_NON_MODULES)) targets missing license metadata >&2
endef
@ -914,13 +924,8 @@ $(strip \
$(foreach t,$(sort $(ALL_0P_TARGETS)), \
$(eval ALL_TARGETS.$(t).META_LIC := 0p) \
) \
$(foreach t,$(sort $(ALL_NON_MODULES)), \
$(eval ALL_TARGETS.$(t).META_LIC := $(call append-path,$(_dir),$(patsubst $(OUT_DIR)%,out%,$(t).meta_lic))) \
) \
$(foreach t,$(sort $(ALL_NON_MODULES)),$(eval $(call non-module-license-metadata-rule,$(t)))) \
$(foreach m,$(sort $(ALL_MODULES)),$(eval $(call license-metadata-rule,$(m)))) \
$(eval $(call report-missing-licenses-rule)) \
$(eval $(call report-all-notice-library-names-rule)) \
$(eval $(call build-all-license-metadata-rule)))
endef

View file

@ -45,6 +45,56 @@ $(foreach file,$(2), \
$(eval _all_dist_goal_output_pairs += $$(goal):$$(dst))))
endef
.PHONY: shareprojects
#shareprojects:
define __share-projects-rule
$(1) : PRIVATE_TARGETS := $(2)
$(1) : $(2) | $(COMPLIANCE_LISTSHARE)
$(hide) rm -f $$@
ifeq (,$(strip $(2)))
touch $$@
else
$(COMPLIANCE_LISTSHARE) $$(PRIVATE_TARGETS) > $$@
endif
endef
# build list of projects to share in $(1) for dist targets in $(2)
#
# $(1): the intermediate project sharing file
# $(2): the dist files to base the sharing on
define _share-projects-rule
$(eval $(call __share-projects-rule,$(1),$(call corresponding-license-metadata,$(2))))
endef
# Add a build dependency
#
# $(1): the goal phony target
# $(2): the intermediate shareprojects file
define _share-projects-dep
$(1): $(2)
endef
define _add_projects_to_share
$(strip $(eval _idir := $(call intermediates-dir-for,PACKAGING,shareprojects))) \
$(strip $(eval _goals := $(sort $(_all_dist_goals)))) \
$(strip $(eval _opairs := $(sort $(_all_dist_goal_output_pairs)))) \
$(strip $(eval _dpairs := $(sort $(_all_dist_src_dst_pairs)))) \
$(strip $(eval _allt :=)) \
$(foreach goal,$(_goals), \
$(eval _f := $(_idir)/$(goal).shareprojects) \
$(call dist-for-goals,$(goal),$(_f)) \
$(eval _targets :=) \
$(foreach op,$(filter $(goal):%,$(_opairs)),$(foreach p,$(filter %:$(call word-colon,2,$(op)),$(_dpairs)),$(eval _targets += $(call word-colon,1,$(p))))) \
$(eval _allt += $(_targets)) \
$(eval $(call _share-projects-rule,$(_f),$(_targets))) \
)\
$(eval _f := $(_idir)/all.shareprojects)\
$(eval $(call _share-projects-dep,shareprojects,$(_f))) \
$(call dist-for-goals,shareprojects,$(_f))\
$(eval $(call _share-projects-rule,$(_f),$(sort $(_allt))))
endef
#------------------------------------------------------------------
# To be used at the end of the build to collect all the uses of
# dist-for-goals, and write them into a file for the packaging step to use.
@ -52,6 +102,15 @@ endef
# $(1): The file to write
define dist-write-file
$(strip \
$(call _add_projects_to_share)\
$(if $(strip $(ANDROID_REQUIRE_LICENSE_METADATA)),\
$(if $(strip $(ANDROID_REQUIRE_LICENSE_METADATA)),\
$(foreach target,$(sort $(TARGETS_MISSING_LICENSE_METADATA)),$(warning target $(target) missing license metadata)))\
$(if $(strip $(TARGETS_MISSING_LICENSE_METADATA)),\
$(if $(filter true error,$(ANDROID_REQUIRE_LICENSE_METADATA)),\
$(error $(words $(sort $(TARGETS_MISSING_LICENSE_METADATA))) targets need license metadata))))\
$(eval $(call report-missing-licenses-rule)) \
$(eval $(call report-all-notice-library-names-rule)) \
$(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \
$(foreach goal,$(sort $(_all_dist_goals)), \
$(eval $$(goal): _dist_$$(goal))) \