Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 991d11df authored by Yu Liu's avatar Yu Liu Committed by Gerrit Code Review
Browse files

Merge "Convert cc modules to use AndroidMkInfoProvider." into main

parents a077b940 56400087
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ func TestAndroidMkCcLibrary(t *testing.T) {

	module := result.ModuleForTests("my_cc_library", "android_vendor_arm64_armv8-a_shared").Module()

	entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
	entry := android.AndroidMkInfoForTest(t, result.TestContext, module).PrimaryInfo

	makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
	android.EnsureListContainsSuffix(t, makeVar, "my_aconfig_declarations_foo/intermediate.pb")
+21 −29
Original line number Diff line number Diff line
@@ -463,18 +463,18 @@ func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContr
func generateDistContributionsForMake(distContributions *distContributions) []string {
	var ret []string
	for _, d := range distContributions.copiesForGoals {
		ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals))
		ret = append(ret, fmt.Sprintf(".PHONY: %s", d.goals))
		// Create dist-for-goals calls for each of the copy instructions.
		for _, c := range d.copies {
			if distContributions.licenseMetadataFile != nil {
				ret = append(
					ret,
					fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n",
					fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))",
						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))
				fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)", d.goals, c.from.String(), c.dest))
		}
	}

@@ -523,7 +523,7 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
	a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...)

	for _, distString := range a.GetDistForGoals(mod) {
		fmt.Fprintf(&a.header, distString)
		fmt.Fprintln(&a.header, distString)
	}

	fmt.Fprintf(&a.header, "\ninclude $(CLEAR_VARS)  # type: %s, name: %s, variant: %s\n", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod))
@@ -807,9 +807,8 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs
	// Additional cases here require review for correct license propagation to make.
	var err error

	if info, ok := ctx.otherModuleProvider(mod, AndroidMkInfoProvider); ok {
		androidMkEntriesInfos := info.(*AndroidMkProviderInfo)
		err = translateAndroidMkEntriesInfoModule(ctx, w, moduleInfoJSONs, mod, androidMkEntriesInfos)
	if info, ok := OtherModuleProvider(ctx, mod, AndroidMkInfoProvider); ok {
		err = translateAndroidMkEntriesInfoModule(ctx, w, moduleInfoJSONs, mod, info)
	} else {
		switch x := mod.(type) {
		case AndroidMkDataProvider:
@@ -1100,6 +1099,10 @@ type AndroidMkInfo struct {
	EntryOrder []string
}

type AndroidMkProviderInfoProducer interface {
	PrepareAndroidMKProviderInfo(config Config) *AndroidMkProviderInfo
}

// TODO: rename it to AndroidMkEntriesProvider after AndroidMkEntriesProvider interface is gone.
var AndroidMkInfoProvider = blueprint.NewProvider[*AndroidMkProviderInfo]()

@@ -1272,7 +1275,7 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod blueprint.Mo
		a.HeaderStrings = append(a.HeaderStrings, distString)
	}

	a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS)  # type: %s, name: %s, variant: %s\n", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod)))
	a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS)  # type: %s, name: %s, variant: %s", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod)))

	// Collect make variable assignment entries.
	helperInfo.SetString("LOCAL_PATH", ctx.ModuleDir(mod))
@@ -1300,6 +1303,14 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod blueprint.Mo
		helperInfo.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install))
	}

	if info.UncheckedModule {
		helperInfo.SetBool("LOCAL_DONT_CHECK_MODULE", true)
	} else if info.CheckbuildTarget != nil {
		helperInfo.SetPath("LOCAL_CHECKED_MODULE", info.CheckbuildTarget)
	} else {
		helperInfo.SetOptionalPath("LOCAL_CHECKED_MODULE", a.OutputFile)
	}

	if len(info.TestData) > 0 {
		helperInfo.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...)
	}
@@ -1364,25 +1375,6 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod blueprint.Mo
		helperInfo.SetString("LOCAL_IS_HOST_MODULE", "true")
	}

	prefix := ""
	if base.ArchSpecific() {
		switch base.Os().Class {
		case Host:
			if base.Target().HostCross {
				prefix = "HOST_CROSS_"
			} else {
				prefix = "HOST_"
			}
		case Device:
			prefix = "TARGET_"

		}

		if base.Arch().ArchType != ctx.Config().Targets[base.Os()][0].Arch.ArchType {
			prefix = "2ND_" + prefix
		}
	}

	if licenseMetadata, ok := OtherModuleProvider(ctx, mod, LicenseMetadataProvider); ok {
		helperInfo.SetPath("LOCAL_SOONG_LICENSE_METADATA", licenseMetadata.LicenseMetadataPath)
	}
@@ -1423,8 +1415,8 @@ func (a *AndroidMkInfo) write(w io.Writer) {
		return
	}

	combinedHeaderString := strings.Join(a.HeaderStrings, "\n")
	combinedFooterString := strings.Join(a.FooterStrings, "\n")
	combinedHeaderString := strings.Join(a.HeaderStrings, "\n") + "\n"
	combinedFooterString := strings.Join(a.FooterStrings, "\n") + "\n"
	w.Write([]byte(combinedHeaderString))
	for _, name := range a.EntryOrder {
		AndroidMkEmitAssignList(w, name, a.EntryMap[name])
+23 −24
Original line number Diff line number Diff line
@@ -195,8 +195,7 @@ func TestGenerateDistContributionsForMake(t *testing.T) {
$(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, ""))
$(call dist-for-goals,my_goal,two.out:other.out)`, strings.Join(makeOutput, "\n"))
}

func TestGetDistForGoals(t *testing.T) {
@@ -235,28 +234,28 @@ 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",
		".PHONY: my_second_goal",
		"$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_second_goal,two.out:two.out)",
		"$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_second_goal,three/four.out:four.out)",
		".PHONY: my_third_goal",
		"$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)",
		".PHONY: my_fourth_goal",
		"$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)",
		".PHONY: my_fifth_goal",
		"$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_fifth_goal,one.out:new-name)",
		".PHONY: my_sixth_goal",
		"$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)",
		".PHONY: my_goal my_other_goal",
		"$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)",
		"$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))",
		"$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)",
	}

	ctx, module := buildContextAndCustomModuleFoo(t, bp)
+11 −0
Original line number Diff line number Diff line
@@ -543,6 +543,13 @@ func (t *CommonTestOptions) SetAndroidMkEntries(entries *AndroidMkEntries) {
	}
}

func (t *CommonTestOptions) SetAndroidMkInfoEntries(entries *AndroidMkInfo) {
	entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
	if len(t.Tags) > 0 {
		entries.AddStrings("LOCAL_TEST_OPTIONS_TAGS", t.Tags...)
	}
}

// The key to use in TaggedDistFiles when a Dist structure does not specify a
// tag property. This intentionally does not use "" as the default because that
// would mean that an empty tag would have a different meaning when used in a dist
@@ -2085,6 +2092,10 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
		SetProvider(ctx, HostToolProviderKey, HostToolProviderData{
			HostToolPath: h.HostToolPath()})
	}

	if p, ok := m.module.(AndroidMkProviderInfoProducer); ok && !shouldSkipAndroidMkProcessing(ctx, m) {
		SetProvider(ctx, AndroidMkInfoProvider, p.PrepareAndroidMKProviderInfo(ctx.Config()))
	}
}

func SetJarJarPrefixHandler(handler func(ModuleContext)) {
+19 −0
Original line number Diff line number Diff line
@@ -1152,6 +1152,25 @@ func AndroidMkEntriesForTest(t *testing.T, ctx *TestContext, mod blueprint.Modul
	return entriesList
}

func AndroidMkInfoForTest(t *testing.T, ctx *TestContext, mod blueprint.Module) *AndroidMkProviderInfo {
	t.Helper()
	var ok bool
	if _, ok = mod.(AndroidMkProviderInfoProducer); !ok {
		t.Errorf("module does not implement AndroidMkProviderInfoProducer: " + mod.Name())
	}

	info := OtherModuleProviderOrDefault(ctx, mod, AndroidMkInfoProvider)
	aconfigUpdateAndroidMkInfos(ctx, mod.(Module), info)
	info.PrimaryInfo.fillInEntries(ctx, mod)
	if len(info.ExtraInfo) > 0 {
		for _, ei := range info.ExtraInfo {
			ei.fillInEntries(ctx, mod)
		}
	}

	return info
}

func AndroidMkDataForTest(t *testing.T, ctx *TestContext, mod blueprint.Module) AndroidMkData {
	t.Helper()
	var p AndroidMkDataProvider
Loading