diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-06-10 23:18:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-06-10 23:18:09 +0000 |
commit | 52a972709d4f2525255f611cf8b24e7cd0fa1e30 (patch) | |
tree | 0e821bd3ef2197f7d58115426d192be2a8f1e6a9 | |
parent | 99b87147ece96c9b214a976c657beff0acd0a568 (diff) | |
parent | 6a661f011d926c642008e9060f4cbe85b957d77f (diff) | |
download | build-52a972709d4f2525255f611cf8b24e7cd0fa1e30.tar.gz |
Merge changes Ibd737c0d,Ibf5a9869 into tm-dev
* changes:
Record license text for every dist target.
Create lists of projects to share per dist target
-rw-r--r-- | core/definitions.mk | 137 | ||||
-rw-r--r-- | core/distdir.mk | 108 | ||||
-rw-r--r-- | core/notice_files.mk | 2 |
3 files changed, 236 insertions, 11 deletions
diff --git a/core/definitions.mk b/core/definitions.mk index 0c46de9fc6..84860f9fa4 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -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 ########################################################### @@ -705,6 +710,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) $(COPY_LICENSE_METADATA) + 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). ## ## $(2) -- license kinds e.g. SPDX-license-identifier-Apache-2.0 @@ -717,6 +776,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 +817,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 +890,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 +907,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 +919,14 @@ endef ########################################################### define report-missing-licenses-rule .PHONY: reportmissinglicenses -reportmissinglicenses: PRIVATE_NON_MODULES:=$(sort $(NON_MODULES_WITHOUT_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: PRIVATE_NON_MODULES:=$(sort $(NON_MODULES_WITHOUT_LICENSE_METADATA) $(TARGETS_MISSING_LICENSE_METADATA)) +reportmissinglicenses: PRIVATE_COPIED_FILES:=$(sort $(filter $(NON_MODULES_WITHOUT_LICENSE_METADATA) $(TARGETS_MISSING_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 +979,9 @@ $(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)) \ + $(foreach t,$(sort $(ALL_COPIED_TARGETS)),$(eval $(call copied-target-license-metadata-rule,$(t)))) \ $(eval $(call build-all-license-metadata-rule))) endef @@ -992,6 +1053,22 @@ $(strip \ ) endef +# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE +# to determine the intermediates directory. +# +# $(1): if non-empty, force the intermediates to be COMMON +# $(2): if non-empty, force the intermediates to be for the 2nd arch +# $(3): if non-empty, force the intermediates to be for the host cross os +define local-meta-intermediates-dir +$(strip \ + $(if $(strip $(LOCAL_MODULE_CLASS)),, \ + $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-meta-intermediates-dir)) \ + $(if $(strip $(LOCAL_MODULE)),, \ + $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-meta-intermediates-dir)) \ + $(call intermediates-dir-for,META$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST),$(1),$(2),$(3)) \ +) +endef + ########################################################### ## The generated sources directory. Placing generated ## source files directly in the intermediates directory @@ -2411,7 +2488,47 @@ define dump-words-to-file @$(call emit-line,$(wordlist 38001,38500,$(1)),$(2)) @$(call emit-line,$(wordlist 38501,39000,$(1)),$(2)) @$(call emit-line,$(wordlist 39001,39500,$(1)),$(2)) - @$(if $(wordlist 39501,39502,$(1)),$(error Too many words ($(words $(1))))) + @$(call emit-line,$(wordlist 39501,40000,$(1)),$(2)) + @$(call emit-line,$(wordlist 40001,40500,$(1)),$(2)) + @$(call emit-line,$(wordlist 40501,41000,$(1)),$(2)) + @$(call emit-line,$(wordlist 41001,41500,$(1)),$(2)) + @$(call emit-line,$(wordlist 41501,42000,$(1)),$(2)) + @$(call emit-line,$(wordlist 42001,42500,$(1)),$(2)) + @$(call emit-line,$(wordlist 42501,43000,$(1)),$(2)) + @$(call emit-line,$(wordlist 43001,43500,$(1)),$(2)) + @$(call emit-line,$(wordlist 43501,44000,$(1)),$(2)) + @$(call emit-line,$(wordlist 44001,44500,$(1)),$(2)) + @$(call emit-line,$(wordlist 44501,45000,$(1)),$(2)) + @$(call emit-line,$(wordlist 45001,45500,$(1)),$(2)) + @$(call emit-line,$(wordlist 45501,46000,$(1)),$(2)) + @$(call emit-line,$(wordlist 46001,46500,$(1)),$(2)) + @$(call emit-line,$(wordlist 46501,47000,$(1)),$(2)) + @$(call emit-line,$(wordlist 47001,47500,$(1)),$(2)) + @$(call emit-line,$(wordlist 47501,48000,$(1)),$(2)) + @$(call emit-line,$(wordlist 48001,48500,$(1)),$(2)) + @$(call emit-line,$(wordlist 48501,49000,$(1)),$(2)) + @$(call emit-line,$(wordlist 49001,49500,$(1)),$(2)) + @$(call emit-line,$(wordlist 49501,50000,$(1)),$(2)) + @$(call emit-line,$(wordlist 50001,50500,$(1)),$(2)) + @$(call emit-line,$(wordlist 50501,51000,$(1)),$(2)) + @$(call emit-line,$(wordlist 51001,51500,$(1)),$(2)) + @$(call emit-line,$(wordlist 51501,52000,$(1)),$(2)) + @$(call emit-line,$(wordlist 52001,52500,$(1)),$(2)) + @$(call emit-line,$(wordlist 52501,53000,$(1)),$(2)) + @$(call emit-line,$(wordlist 53001,53500,$(1)),$(2)) + @$(call emit-line,$(wordlist 53501,54000,$(1)),$(2)) + @$(call emit-line,$(wordlist 54001,54500,$(1)),$(2)) + @$(call emit-line,$(wordlist 54501,55000,$(1)),$(2)) + @$(call emit-line,$(wordlist 55001,55500,$(1)),$(2)) + @$(call emit-line,$(wordlist 55501,56000,$(1)),$(2)) + @$(call emit-line,$(wordlist 56001,56500,$(1)),$(2)) + @$(call emit-line,$(wordlist 56501,57000,$(1)),$(2)) + @$(call emit-line,$(wordlist 57001,57500,$(1)),$(2)) + @$(call emit-line,$(wordlist 57501,58000,$(1)),$(2)) + @$(call emit-line,$(wordlist 58001,58500,$(1)),$(2)) + @$(call emit-line,$(wordlist 58501,59000,$(1)),$(2)) + @$(call emit-line,$(wordlist 59001,59500,$(1)),$(2)) + @$(if $(wordlist 59501,59502,$(1)),$(error Too many words ($(words $(1))))) endef # Return jar arguments to compress files in a given directory # $(1): directory diff --git a/core/distdir.mk b/core/distdir.mk index aad8ff3d65..3d48a484a5 100644 --- a/core/distdir.mk +++ b/core/distdir.mk @@ -45,6 +45,105 @@ $(foreach file,$(2), \ $(eval _all_dist_goal_output_pairs += $$(goal):$$(dst)))) endef +.PHONY: shareprojects + +define __share-projects-rule +$(1) : PRIVATE_TARGETS := $(2) +$(1) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,codesharing)/$(1)/arguments +$(1): $(2) $(COMPLIANCE_LISTSHARE) + $(hide) rm -f $$@ + mkdir -p $$(dir $$@) + mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) + $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,$$(PRIVATE_TARGETS),$$(PRIVATE_ARGUMENT_FILE))) + $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(COMPLIANCE_LISTSHARE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@) +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 + +.PHONY: alllicensetexts + +define __license-texts-rule +$(2) : PRIVATE_GOAL := $(1) +$(2) : PRIVATE_TARGETS := $(3) +$(2) : PRIVATE_ROOTS := $(4) +$(2) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,licensetexts)/$(2)/arguments +$(2): $(3) $(TEXTNOTICE) + $(hide) rm -f $$@ + mkdir -p $$(dir $$@) + mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) + $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,\ + -product="$$(PRIVATE_GOAL)" -title="$$(PRIVATE_GOAL)" \ + $$(addprefix -strip_prefix ,$$(PRIVATE_ROOTS)) \ + -strip_prefix=$(PRODUCT_OUT)/ -strip_prefix=$(HOST_OUT)/\ + $$(PRIVATE_TARGETS),\ + $$(PRIVATE_ARGUMENT_FILE))) + $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(TEXTNOTICE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@) +endef + +# build list of projects to share in $(2) for dist targets in $(3) for dist goal $(1) +# +# $(1): the name of the dist goal +# $(2): the intermediate project sharing file +# $(3): the dist files to base the sharing on +define _license-texts-rule +$(eval $(call __license-texts-rule,$(1),$(2),$(call corresponding-license-metadata,$(3)),$(sort $(dir $(3))))) +endef + +# Add a build dependency +# +# $(1): the goal phony target +# $(2): the intermediate shareprojects file +define _license-texts-dep +$(1): $(2) +endef + +define _add_projects_to_share +$(strip $(eval _idir := $(call intermediates-dir-for,METAPACKAGING,shareprojects))) \ +$(strip $(eval _tdir := $(call intermediates-dir-for,METAPACKAGING,licensetexts))) \ +$(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) \ + $(eval _n := $(_tdir)/$(goal).txt) \ + $(call dist-for-goals,$(goal),$(_f):shareprojects/$(basename $(notdir $(_f)))) \ + $(call dist-for-goals,$(goal),$(_n):licensetexts/$(basename $(notdir $(_n)))) \ + $(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 $(call _license-texts-rule,$(goal),$(_n),$(_targets))) \ +)\ +$(eval _f := $(_idir)/all.shareprojects)\ +$(eval _n := $(_tdir)/all.txt)\ +$(eval _idir :=)\ +$(eval _tdir :=)\ +$(eval $(call _share-projects-dep,shareprojects,$(_f))) \ +$(eval $(call _license-texts-dep,alllicensetexts,$(_n))) \ +$(call dist-for-goals,droid shareprojects,$(_f):shareprojects/all)\ +$(call dist-for-goals,droid alllicensetexts,$(_n):licensetexts/all)\ +$(eval _allt := $(sort $(_allt)))\ +$(eval $(call _share-projects-rule,$(_f),$(_allt)))\ +$(eval $(call _license-texts-rule,droid,$(_n),$(_allt)))\ +$(eval _f :=)\ +$(evan _n :=) +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 +151,15 @@ endef # $(1): The file to write define dist-write-file $(strip \ + $(call _add_projects_to_share)\ + $(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))))\ + $(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)) \ $(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \ $(foreach goal,$(sort $(_all_dist_goals)), \ $(eval $$(goal): _dist_$$(goal))) \ diff --git a/core/notice_files.mk b/core/notice_files.mk index c05d4ea0be..4b67404fd2 100644 --- a/core/notice_files.mk +++ b/core/notice_files.mk @@ -125,7 +125,7 @@ local_path := $(LOCAL_PATH) module_license_metadata := ifdef my_register_name - module_license_metadata := $(call local-intermediates-dir)/$(my_register_name).meta_lic + module_license_metadata := $(call local-meta-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),\ $(eval ALL_TARGETS.$(target).META_LIC := $(module_license_metadata))) |