From ba3372439f34a570af02511a438c6e3c947ce3f1 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Fri, 27 May 2022 19:40:41 -0700 Subject: [PATCH] Create license metadata for copied targets. Bug: 213388645 Test: m cts dist reportmissinglicenses Change-Id: I43043e5e7b80d9f3210d6498c215846aec761add --- core/Makefile | 2 +- core/definitions.mk | 83 ++++++++++++++++++++++++--- core/main.mk | 2 +- core/notice_files.mk | 3 +- core/tasks/tools/vts_package_utils.mk | 2 +- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/core/Makefile b/core/Makefile index 78382bd69b..a6f6dd2568 100644 --- a/core/Makefile +++ b/core/Makefile @@ -3506,7 +3506,7 @@ INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img $(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDORIMAGE),$(INSTALLED_VENDORIMAGE_TARGET))) $(if $(strip $(ALL_TARGETS.$(INSTALLED_VENDORIMAGE_TARGET).META_LIC)),,\ $(if $(strip $(ALL_TARGETS.$(BOARD_PREBUILT_VENDORIMAGE).META_LIC)),\ - $(eval ALL_TARGETS.$(INSTALLED_VENDORIMAGE_TARGET).META_LIC:=$(ALL_TARGETS.$(BOARD_PREBUILT_VENDORIMAGE).META_LIC)),\ + $(call declare-copy-target-license-metadata,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_PREBUILT_VENDORIMAGE)),\ $(call declare-license-metadata,$(INSTALLED_VENDORIMAGE_TARGET),legacy_proprietary,proprietary,,"Vendor Image",vendor))) endif diff --git a/core/definitions.mk b/core/definitions.mk index e424bc27f9..c5423e79a4 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -41,6 +41,9 @@ ALL_MODULES:= ALL_NON_MODULES:= NON_MODULES_WITHOUT_LICENSE_METADATA:= +# List of copied targets that need license metadata copied. +ALL_COPIED_TARGETS:= + # Full paths to targets that should be added to the "make droid" # set of installed targets. ALL_DEFAULT_INSTALLED_MODULES:= @@ -582,6 +585,19 @@ $(strip $(foreach target, $(sort $(1)), \ $(call append-path,$(call license-metadata-dir),$(patsubst $(OUT_DIR)%,out%,$(target).meta_lic)))))) endef +########################################################### +## Record a target $(1) copied from another target(s) $(2) that will need +## license metadata. +########################################################### +define declare-copy-target-license-metadata +$(strip $(if $(filter $(OUT_DIR)%,$(2)),$(eval _dir:=$(call license-metadata-dir))\ + $(eval _tgt:=$(strip $(1)))\ + $(eval _meta := $(call append-path,$(_dir),$(patsubst $(OUT_DIR)%,out%,$(_tgt).meta_lic)))\ + $(eval ALL_COPIED_TARGETS.$(_tgt).SOURCES := $(ALL_COPIED_TARGETS.$(_tgt).SOURCES) $(filter $(OUT_DIR)%,$(2)))\ + $(eval ALL_COPIED_TARGETS += $(_tgt)),\ + $(eval ALL_TARGETS.$(1).META_LIC:=$(module_license_metadata)))) +endef + ########################################################### ## License metadata build rule for my_register_name $(1) ########################################################### @@ -661,13 +677,6 @@ $(strip $(eval _deps := $(sort $(filter-out 0p: :,$(foreach d,$(strip $(ALL_NON_ $(strip $(eval _notices := $(sort $(ALL_NON_MODULES.$(_tgt).NOTICES)))) $(strip $(eval _path := $(sort $(ALL_NON_MODULES.$(_tgt).PATH)))) $(strip $(eval _install_map := $(ALL_NON_MODULES.$(_tgt).ROOT_MAPPINGS))) -$(strip $(eval \ - $$(foreach d,$(strip $(ALL_NON_MODULES.$(_tgt).DEPENDENCIES)), \ - $$(if $$(strip $$(ALL_TARGETS.$$(d).META_LIC)), \ - , \ - $$(eval NON_MODULES_WITHOUT_LICENSE_METADATA += $$(d))) \ - )) \ -) $(_meta): PRIVATE_KINDS := $(sort $(ALL_NON_MODULES.$(_tgt).LICENSE_KINDS)) $(_meta): PRIVATE_CONDITIONS := $(sort $(ALL_NON_MODULES.$(_tgt).LICENSE_CONDITIONS)) @@ -704,6 +713,60 @@ $(_meta) : $(foreach d,$(_deps),$(call word-colon,1,$(d))) $(foreach n,$(_notice endef +########################################################### +## Record missing dependencies for non-module target $(1) +########################################################### +define record-missing-non-module-dependencies +$(strip $(eval _tgt := $(strip $(1)))) +$(strip $(foreach d,$(strip $(ALL_NON_MODULES.$(_tgt).DEPENDENCIES)), \ + $(if $(strip $(ALL_TARGETS.$(d).META_LIC)), \ + , \ + $(eval NON_MODULES_WITHOUT_LICENSE_METADATA += $(d))) \ +)) +endef + +########################################################### +## License metadata build rule for copied target $(1) +########################################################### +define copied-target-license-metadata-rule +$(if $(strip $(ALL_TARGETS.$(1).META_LIC)),,$(call _copied-target-license-metadata-rule,$(1))) +endef + +define _copied-target-license-metadata-rule +$(strip $(eval _dir := $(call license-metadata-dir))) +$(strip $(eval _meta := $(call append-path,$(_dir),$(patsubst $(OUT_DIR)%,out%,$(1).meta_lic)))) +$(strip $(eval ALL_TARGETS.$(1).META_LIC:=$(_meta))) +$(strip $(eval _dep:=)) +$(strip $(foreach s,$(ALL_COPIED_TARGETS.$(1).SOURCES),\ + $(eval _dmeta:=$(ALL_TARGETS.$(s).META_LIC))\ + $(if $(filter 0p,$(_dmeta)),\ + $(if $(filter-out 0p,$(_dep)),,$(eval ALL_TARGETS.$(1).META_LIC:=0p)),\ + $(if $(_dep),\ + $(if $(filter-out $(_dep),$(_dmeta)),$(error cannot copy target from multiple modules: $(1) from $(_dep) and $(_dmeta))), + $(eval _dep:=$(_dmeta)))))) +$(strip $(if $(strip $(_dep)),,$(error cannot copy target from unknown module: $(1) from $(ALL_COPIED_TARGETS.$(1).SOURCES)))) + +ifneq (0p,$(ALL_TARGETS.$(1).META_LIC)) +$(_meta): PRIVATE_DEST_TARGET := $(1) +$(_meta): PRIVATE_SOURCE_TARGETS := $(ALL_COPIED_TARGETS.$(1).SOURCES) +$(_meta): PRIVATE_SOURCE_METADATA := $(_dep) +$(_meta): PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,PACKAGING,copynotice)/$(_meta)/arguments +$(_meta) : $(_dep) + rm -f $$@ + mkdir -p $$(dir $$@) + mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) + $$(call dump-words-to-file,\ + $$(addprefix -i ,$$(PRIVATE_DEST_TARGET))\ + $$(addprefix -s ,$$(PRIVATE_SOURCE_TARGETS))\ + $$(addprefix -d ,$$(PRIVATE_SOURCE_METADATA)),\ + $$(PRIVATE_ARGUMENT_FILE)) + OUT_DIR=$(OUT_DIR) $(COPY_LICENSE_METADATA) \ + @$$(PRIVATE_ARGUMENT_FILE) \ + -o $$@ + +endif +endef + ########################################################### ## Declare the license metadata for non-module target $(1). ## @@ -919,6 +982,8 @@ $(strip \ ) \ $(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)))) \ + $(foreach t,$(sort $(ALL_COPIED_TARGETS)),$(eval $(call copied-target-license-metadata-rule,$(t)))) \ + $(foreach t,$(sort $(ALL_NON_MODULES)),$(call record-missing-non-module-dependencies,$(t))) \ $(eval $(call report-missing-licenses-rule)) \ $(eval $(call report-all-notice-library-names-rule)) \ $(eval $(call build-all-license-metadata-rule))) @@ -3402,11 +3467,11 @@ endef define create-suite-dependencies $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ $(eval $(if $(strip $(module_license_metadata)),\ - $$(foreach f,$$(my_compat_dist_$(suite)),$$(eval ALL_TARGETS.$$(call word-colon,2,$$(f)).META_LIC := $(module_license_metadata))),\ + $$(foreach f,$$(my_compat_dist_$(suite)),$$(call declare-copy-target-license-metadata,$$(call word-colon,2,$$(f)),$$(call word-colon,1,$$(f)))),\ $$(eval my_test_data += $$(foreach f,$$(my_compat_dist_$(suite)), $$(call word-colon,2,$$(f)))) \ )) \ $(eval $(if $(strip $(module_license_metadata)),\ - $$(foreach f,$$(my_compat_dist_config_$(suite)),$$(eval ALL_TARGETS.$$(call word-colon,2,$$(f)).META_LIC := $(module_license_metadata))),\ + $$(foreach f,$$(my_compat_dist_config_$(suite)),$$(call declare-copy-target-license-metadata,$$(call word-colon,2,$$(f)),$$(call word-colon,1,$$(f)))),\ $$(eval my_test_config += $$(foreach f,$$(my_compat_dist_config_$(suite)), $$(call word-colon,2,$$(f)))) \ )) \ $(if $(filter $(suite),$(ALL_COMPATIBILITY_SUITES)),,\ diff --git a/core/main.mk b/core/main.mk index 78f38f33d4..2cfea453cf 100644 --- a/core/main.mk +++ b/core/main.mk @@ -935,7 +935,7 @@ $(foreach suite,general-tests device-tests vts tvts art-host-tests host-unit-tes $(eval my_testcases := $(HOST_OUT_TESTCASES)),\ $(eval my_testcases := $$(COMPATIBILITY_TESTCASES_OUT_$(suite))))\ $(eval target := $(my_testcases)/$(lastword $(subst /, ,$(dir $(f))))/$(notdir $(f)))\ - $(if $(strip $(ALL_TARGETS.$(target).META_LIC)),,$(eval ALL_TARGETS.$(target).META_LIC:=$(module_license_metadata)))\ + $(if $(strip $(ALL_TARGETS.$(target).META_LIC)),,$(call declare-copy-target-license-metadata,$(target),$(f)))\ $(eval COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES := \ $$(COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES) $(f):$(target))\ $(eval COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES := \ diff --git a/core/notice_files.mk b/core/notice_files.mk index c05d4ea0be..84523af5e2 100644 --- a/core/notice_files.mk +++ b/core/notice_files.mk @@ -127,7 +127,8 @@ module_license_metadata := ifdef my_register_name module_license_metadata := $(call local-intermediates-dir)/$(my_register_name).meta_lic - $(foreach target,$(ALL_MODULES.$(my_register_name).BUILT) $(ALL_MODULES.$(my_register_name).INSTALLED) $(my_test_data) $(my_test_config),\ + $(foreach target,$(ALL_MODULES.$(my_register_name).BUILT) $(ALL_MODULES.$(my_register_name).INSTALLED) $(foreach bi,$(LOCAL_SOONG_BUILT_INSTALLED),$(call word-colon,1,$(bi))) \ + $(my_test_data) $(my_test_config),\ $(eval ALL_TARGETS.$(target).META_LIC := $(module_license_metadata))) ALL_MODULES.$(my_register_name).META_LIC := $(strip $(ALL_MODULES.$(my_register_name).META_LIC) $(module_license_metadata)) diff --git a/core/tasks/tools/vts_package_utils.mk b/core/tasks/tools/vts_package_utils.mk index f1159b3bd9..06161f0b3c 100644 --- a/core/tasks/tools/vts_package_utils.mk +++ b/core/tasks/tools/vts_package_utils.mk @@ -29,6 +29,6 @@ $(foreach m,$(1),\ $(eval my_copy_dest := $(patsubst data/%,DATA/%,\ $(patsubst system/%,DATA/%,\ $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))))\ - $(eval ALL_TARGETS.$(2)/$(my_copy_dest).META_LIC := $(if $(strip $(ALL_MODULES.$(m).META_LIC)),$(ALL_MODULES.$(m).META_LIC),$(ALL_MODULES.$(m).DELAYED_META_LIC)))\ + $(call declare-copy-target-license-metadata,$(2)/$(my_copy_dest),$(bui))\ $(bui):$(2)/$(my_copy_dest)))) endef