diff options
author | 2025-02-07 16:55:11 -0800 | |
---|---|---|
committer | 2025-02-10 11:44:39 -0800 | |
commit | d62a4896b99fb3dc842190a49ea22f18872d1855 (patch) | |
tree | 7fd3471d6c60843fd56953859f3ea1a700377f55 | |
parent | 2572d255162882161479aadc938655fb08e0917d (diff) |
Allow calling ctx.DistForGoal from GenerateAndroidBuildActions
Right now you have to dist files in either the AndroidMk stuff,
or in MakeVars providers. Allow calling it from
GenerateAndroidBuildActions so that we can further remove our reliance
on make.
Bug: 395184523
Test: m nothing --no-skip-soong-tests
Change-Id: I6ad12fa89896b86c333fc2d23eaf4f77466e42a3
-rw-r--r-- | android/Android.bp | 1 | ||||
-rw-r--r-- | android/androidmk.go | 32 | ||||
-rw-r--r-- | android/makevars.go | 6 | ||||
-rw-r--r-- | android/makevars_test.go | 42 | ||||
-rw-r--r-- | android/module.go | 13 | ||||
-rw-r--r-- | android/module_context.go | 49 |
6 files changed, 130 insertions, 13 deletions
diff --git a/android/Android.bp b/android/Android.bp index d27a8facf..75027b182 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -141,6 +141,7 @@ bootstrap_go_package { "license_kind_test.go", "license_test.go", "licenses_test.go", + "makevars_test.go", "module_test.go", "mutator_test.go", "namespace_test.go", diff --git a/android/androidmk.go b/android/androidmk.go index 2153c2741..db1b9e7ec 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -768,7 +768,7 @@ func (c *androidMkSingleton) soongOnlyBuildActions(ctx SingletonContext, mods [] pctx: provider.pctx, } provider.call(mctx) - if contribution := getMakeVarsDistContributions(mctx); contribution != nil { + if contribution := distsToDistContributions(mctx.dists); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } @@ -851,24 +851,24 @@ func writeValueIfChanged(ctx SingletonContext, path string, value string) { } } -func getMakeVarsDistContributions(mctx *makeVarsContext) *distContributions { - if len(mctx.dists) == 0 { +func distsToDistContributions(dists []dist) *distContributions { + if len(dists) == 0 { return nil } copyGoals := []*copiesForGoals{} - for _, dist := range mctx.dists { + for _, dist := range dists { for _, goal := range dist.goals { - copy := &copiesForGoals{} - copy.goals = goal - copy.copies = dist.paths - copyGoals = append(copyGoals, copy) + copyGoals = append(copyGoals, &copiesForGoals{ + goals: goal, + copies: dist.paths, + }) } } - contribution := &distContributions{} - contribution.copiesForGoals = copyGoals - return contribution + return &distContributions{ + copiesForGoals: copyGoals, + } } // getSoongOnlyDataFromMods gathers data from the given modules needed in soong-only builds. @@ -877,6 +877,12 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []blueprint.Module) var allDistContributions []distContributions var moduleInfoJSONs []*ModuleInfoJSON for _, mod := range mods { + if distInfo, ok := OtherModuleProvider(ctx, mod, DistProvider); ok { + if contribution := distsToDistContributions(distInfo.Dists); contribution != nil { + allDistContributions = append(allDistContributions, *contribution) + } + } + if amod, ok := mod.(Module); ok && shouldSkipAndroidMkProcessing(ctx, amod.base()) { continue } @@ -946,7 +952,7 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []blueprint.Module) continue } x.MakeVars(mctx) - if contribution := getMakeVarsDistContributions(mctx); contribution != nil { + if contribution := distsToDistContributions(mctx.dists); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } @@ -957,7 +963,7 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []blueprint.Module) pctx: pctx, } x.MakeVars(mctx) - if contribution := getMakeVarsDistContributions(mctx); contribution != nil { + if contribution := distsToDistContributions(mctx.dists); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } diff --git a/android/makevars.go b/android/makevars.go index c8eb5e436..3a60bbb63 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -185,6 +185,7 @@ func makeVarsSingletonFunc() Singleton { type makeVarsSingleton struct { varsForTesting []makeVarsVariable installsForTesting []byte + lateForTesting []byte } type makeVarsProvider struct { @@ -285,6 +286,10 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { katiVintfManifestInstalls = append(katiVintfManifestInstalls, info.KatiVintfInstalls...) katiSymlinks = append(katiSymlinks, info.KatiSymlinks...) } + + if distInfo, ok := OtherModuleProvider(ctx, m, DistProvider); ok { + dists = append(dists, distInfo.Dists...) + } }) compareKatiInstalls := func(a, b katiInstall) int { @@ -354,6 +359,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { if ctx.Config().RunningInsideUnitTest() { s.varsForTesting = vars s.installsForTesting = installsBytes + s.lateForTesting = lateOutBytes } } diff --git a/android/makevars_test.go b/android/makevars_test.go new file mode 100644 index 000000000..5e4499fbb --- /dev/null +++ b/android/makevars_test.go @@ -0,0 +1,42 @@ +package android + +import ( + "regexp" + "testing" +) + +func TestDistFilesInGenerateAndroidBuildActions(t *testing.T) { + result := GroupFixturePreparers( + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("my_module_type", newDistFileModule) + }), + FixtureModifyConfig(SetKatiEnabledForTests), + PrepareForTestWithMakevars, + ).RunTestWithBp(t, ` + my_module_type { + name: "foo", + } + `) + + lateContents := string(result.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).lateForTesting) + matched, err := regexp.MatchString(`call dist-for-goals,my_goal,.*/my_file.txt:my_file.txt\)`, lateContents) + if err != nil || !matched { + t.Fatalf("Expected a dist, but got: %s", lateContents) + } +} + +type distFileModule struct { + ModuleBase +} + +func newDistFileModule() Module { + m := &distFileModule{} + InitAndroidModule(m) + return m +} + +func (m *distFileModule) GenerateAndroidBuildActions(ctx ModuleContext) { + out := PathForModuleOut(ctx, "my_file.txt") + WriteFileRule(ctx, out, "Hello, world!") + ctx.DistForGoal("my_goal", out) +} diff --git a/android/module.go b/android/module.go index 39a165463..80275a309 100644 --- a/android/module.go +++ b/android/module.go @@ -1925,6 +1925,12 @@ type HostToolProviderInfo struct { var HostToolProviderInfoProvider = blueprint.NewProvider[HostToolProviderInfo]() +type DistInfo struct { + Dists []dist +} + +var DistProvider = blueprint.NewProvider[DistInfo]() + type SourceFileGenerator interface { GeneratedSourceFiles() Paths GeneratedHeaderDirs() Paths @@ -2222,6 +2228,13 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) Phonies: ctx.phonies, }) } + + if len(ctx.dists) > 0 { + SetProvider(ctx, DistProvider, DistInfo{ + Dists: ctx.dists, + }) + } + buildComplianceMetadataProvider(ctx, m) commonData := CommonModuleInfo{ diff --git a/android/module_context.go b/android/module_context.go index d3c537097..1851e7c94 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -255,6 +255,24 @@ type ModuleContext interface { setContainersInfo(info ContainersInfo) setAconfigPaths(paths Paths) + + // DistForGoals creates a rule to copy one or more Paths to the artifacts + // directory on the build server when any of the specified goals are built. + DistForGoal(goal string, paths ...Path) + + // DistForGoalWithFilename creates a rule to copy a Path to the artifacts + // directory on the build server with the given filename when the specified + // goal is built. + DistForGoalWithFilename(goal string, path Path, filename string) + + // DistForGoals creates a rule to copy one or more Paths to the artifacts + // directory on the build server when any of the specified goals are built. + DistForGoals(goals []string, paths ...Path) + + // DistForGoalsWithFilename creates a rule to copy a Path to the artifacts + // directory on the build server with the given filename when any of the + // specified goals are built. + DistForGoalsWithFilename(goals []string, path Path, filename string) } type moduleContext struct { @@ -312,6 +330,8 @@ type moduleContext struct { // complianceMetadataInfo is for different module types to dump metadata. // See android.ModuleContext interface. complianceMetadataInfo *ComplianceMetadataInfo + + dists []dist } var _ ModuleContext = &moduleContext{} @@ -959,3 +979,32 @@ func (m *moduleContext) getContainersInfo() ContainersInfo { func (m *moduleContext) setContainersInfo(info ContainersInfo) { m.containersInfo = info } + +func (c *moduleContext) DistForGoal(goal string, paths ...Path) { + c.DistForGoals([]string{goal}, paths...) +} + +func (c *moduleContext) DistForGoalWithFilename(goal string, path Path, filename string) { + c.DistForGoalsWithFilename([]string{goal}, path, filename) +} + +func (c *moduleContext) DistForGoals(goals []string, paths ...Path) { + var copies distCopies + for _, path := range paths { + copies = append(copies, distCopy{ + from: path, + dest: path.Base(), + }) + } + c.dists = append(c.dists, dist{ + goals: slices.Clone(goals), + paths: copies, + }) +} + +func (c *moduleContext) DistForGoalsWithFilename(goals []string, path Path, filename string) { + c.dists = append(c.dists, dist{ + goals: slices.Clone(goals), + paths: distCopies{{from: path, dest: filename}}, + }) +} |