From 65ebcd772e76f057c3268096c94579f7265b2776 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Wed, 13 Apr 2022 11:27:19 -0700 Subject: [PATCH] Make sure dist files have license metadata. Bug: 151177513 Bug: 210912771 Bug: 240342946 Test: m droid dist reportmissinglicenses Change-Id: I0c85f6c49a3e9d9bb3219ed6ddfb939d90f80656 Merged-in: I0c85f6c49a3e9d9bb3219ed6ddfb939d90f80656 --- android/androidmk.go | 8 ++++++++ android/androidmk_test.go | 15 ++++++++++++++- apex/androidmk.go | 1 + java/androidmk.go | 1 + java/platform_bootclasspath_test.go | 4 +++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 5c715b473..6b675a66c 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -288,6 +288,8 @@ func (a *AndroidMkEntries) AddCompatibilityTestSuites(suites ...string) { // The contributions to the dist. type distContributions struct { + // Path to license metadata file. + licenseMetadataFile Path // List of goals and the dist copy instructions. copiesForGoals []*copiesForGoals } @@ -364,6 +366,8 @@ func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContr // Collate the contributions this module makes to the dist. distContributions := &distContributions{} + distContributions.licenseMetadataFile = amod.licenseMetadataFile + // Iterate over this module's dist structs, merged from the dist and dists properties. for _, dist := range amod.Dists() { // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore @@ -454,6 +458,10 @@ func generateDistContributionsForMake(distContributions *distContributions) []st ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals)) // Create dist-for-goals calls for each of the copy instructions. for _, c := range d.copies { + ret = append( + ret, + fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n", + c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String())) ret = append( ret, fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest)) diff --git a/android/androidmk_test.go b/android/androidmk_test.go index caf11f10f..ae2187f48 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -50,6 +50,8 @@ const ( func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) { + m.base().licenseMetadataFile = PathForOutput(ctx, "meta_lic") + // If the dist_output_file: true then create an output file that is stored in // the OutputFile property of the AndroidMkEntry. if proptools.BoolDefault(m.properties.Dist_output_file, true) { @@ -198,10 +200,13 @@ func TestGenerateDistContributionsForMake(t *testing.T) { }, } + dc.licenseMetadataFile = PathForTesting("meta_lic") makeOutput := generateDistContributionsForMake(dc) assertStringEquals(t, `.PHONY: my_goal +$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic)) $(call dist-for-goals,my_goal,one.out:one.out) +$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic)) $(call dist-for-goals,my_goal,two.out:other.out) `, strings.Join(makeOutput, "")) } @@ -243,18 +248,26 @@ func TestGetDistForGoals(t *testing.T) { expectedAndroidMkLines := []string{ ".PHONY: my_second_goal\n", + "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_second_goal,two.out:two.out)\n", + "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n", ".PHONY: my_third_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n", ".PHONY: my_fourth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n", ".PHONY: my_fifth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n", ".PHONY: my_sixth_goal\n", + "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n", ".PHONY: my_goal my_other_goal\n", + "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n", + "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n", "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n", } @@ -274,7 +287,7 @@ func TestGetDistForGoals(t *testing.T) { ) } for idx, line := range androidMkLines { - expectedLine := expectedAndroidMkLines[idx] + expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic", module.base().licenseMetadataFile.String()) if line != expectedLine { t.Errorf( "Expected AndroidMk line to be '%s', got '%s'", diff --git a/apex/androidmk.go b/apex/androidmk.go index e094a1276..938c8edd3 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -412,6 +412,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData { fmt.Fprintln(w, ".PHONY:", goal) fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", goal, a.installedFilesFile.String(), distFile) + fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String()) } for _, dist := range data.Entries.GetDistForGoals(a) { fmt.Fprintf(w, dist) diff --git a/java/androidmk.go b/java/androidmk.go index 7322637a7..a9a21b648 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -618,6 +618,7 @@ func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries { if dstubs.apiLintReport != nil { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint", dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt") + fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String()) } } if dstubs.checkNullabilityWarningsTimestamp != nil { diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go index 1c2a3aee5..cb0902079 100644 --- a/java/platform_bootclasspath_test.go +++ b/java/platform_bootclasspath_test.go @@ -271,7 +271,9 @@ func TestPlatformBootclasspath_Dist(t *testing.T) { entries := android.AndroidMkEntriesForTest(t, result.TestContext, platformBootclasspath) goals := entries[0].GetDistForGoals(platformBootclasspath) android.AssertStringEquals(t, "platform dist goals phony", ".PHONY: droidcore\n", goals[0]) - android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[1])) + android.AssertStringDoesContain(t, "platform dist goals meta check", goals[1], "$(if $(strip $(ALL_TARGETS.") + android.AssertStringDoesContain(t, "platform dist goals meta assign", goals[1], "),,$(eval ALL_TARGETS.") + android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[2])) } func TestPlatformBootclasspath_HiddenAPIMonolithicFiles(t *testing.T) {