summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2025-03-03 15:11:32 -0800
committer Cole Faust <colefaust@google.com> 2025-03-03 17:35:44 -0800
commit0523b8f1faec114e3c3eeefe02aa3a6988ffb8b9 (patch)
treef70e014d958d9272a3b37e7cdf6d7de77d77a813 /android
parent339f20817ae97ca1e9d3cc29a89b185834d79077 (diff)
Generate module targets per-variant
Previously, the module target was only generated for the final varinat, but it visited all its other variants to get output files from them. This was mostly fine, except for that now there's ctx.Device() and ctx.Target().HostCross checks in it. For a module with both device and host variants, only one of these checks would apply to all variants of the device, leading to missing -target or -host phonies. Instead, just create the phonies on all variants. We'll rely on the fact that phonies are merged/deduped, so saying `m foo` will still build all variants of foo. But now `m foo-host` or `m foo-target` will correctly only build the host or target variants. Fixes: 400503755 Test: atest CtsCompilationTestCases:android.compilation.cts.CompilationTest on a soong-only build Change-Id: I4896a6cb0461b373ec1853809fa862f9b852096c
Diffstat (limited to 'android')
-rw-r--r--android/module.go79
-rw-r--r--android/module_context.go13
-rw-r--r--android/prebuilt_test.go3
-rw-r--r--android/test_suites_test.go3
4 files changed, 48 insertions, 50 deletions
diff --git a/android/module.go b/android/module.go
index 405573c1b..7786f13ee 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1654,38 +1654,10 @@ func (m *ModuleBase) generateVariantTarget(ctx *moduleContext) {
}
+// generateModuleTarget generates phony targets so that you can do `m <module-name>`.
+// It will be run on every variant of the module, so it relies on the fact that phony targets
+// are deduped to merge all the deps from different variants together.
func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
- var allInstalledFiles InstallPaths
- var allCheckbuildTargets Paths
- var alloutputFiles Paths
- ctx.VisitAllModuleVariantProxies(func(module ModuleProxy) {
- var checkbuildTarget Path
- var uncheckedModule bool
- var skipAndroidMkProcessing bool
- if EqualModules(m.module, module) {
- allInstalledFiles = append(allInstalledFiles, ctx.installFiles...)
- checkbuildTarget = ctx.checkbuildTarget
- uncheckedModule = ctx.uncheckedModule
- skipAndroidMkProcessing = shouldSkipAndroidMkProcessing(ctx, m)
- } else {
- info := OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider)
- allInstalledFiles = append(allInstalledFiles, info.InstallFiles...)
- checkbuildTarget = info.CheckbuildTarget
- uncheckedModule = info.UncheckedModule
- skipAndroidMkProcessing = OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).SkipAndroidMkProcessing
- }
- if outputFiles, err := outputFilesForModule(ctx, module, ""); err == nil {
- alloutputFiles = append(alloutputFiles, outputFiles...)
- }
- // A module's -checkbuild phony targets should
- // not be created if the module is not exported to make.
- // Those could depend on the build target and fail to compile
- // for the current build target.
- if (!ctx.Config().KatiEnabled() || !skipAndroidMkProcessing) && !uncheckedModule && checkbuildTarget != nil {
- allCheckbuildTargets = append(allCheckbuildTargets, checkbuildTarget)
- }
- })
-
var namespacePrefix string
nameSpace := ctx.Namespace().Path
if nameSpace != "." {
@@ -1693,24 +1665,28 @@ func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
}
var deps Paths
- var info FinalModuleBuildTargetsInfo
+ var info ModuleBuildTargetsInfo
- if len(allInstalledFiles) > 0 {
+ if len(ctx.installFiles) > 0 {
name := namespacePrefix + ctx.ModuleName() + "-install"
- ctx.Phony(name, allInstalledFiles.Paths()...)
+ ctx.Phony(name, ctx.installFiles.Paths()...)
info.InstallTarget = PathForPhony(ctx, name)
deps = append(deps, info.InstallTarget)
}
- if len(allCheckbuildTargets) > 0 {
+ // A module's -checkbuild phony targets should
+ // not be created if the module is not exported to make.
+ // Those could depend on the build target and fail to compile
+ // for the current build target.
+ if (!ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, m)) && !ctx.uncheckedModule && ctx.checkbuildTarget != nil {
name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
- ctx.Phony(name, allCheckbuildTargets...)
+ ctx.Phony(name, ctx.checkbuildTarget)
deps = append(deps, PathForPhony(ctx, name))
}
- if len(alloutputFiles) > 0 {
+ if outputFiles, err := outputFilesForModule(ctx, ctx.Module(), ""); err == nil && len(outputFiles) > 0 {
name := namespacePrefix + ctx.ModuleName() + "-outputs"
- ctx.Phony(name, alloutputFiles...)
+ ctx.Phony(name, outputFiles...)
deps = append(deps, PathForPhony(ctx, name))
}
@@ -1734,7 +1710,7 @@ func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
}
info.BlueprintDir = ctx.ModuleDir()
- SetProvider(ctx, FinalModuleBuildTargetsProvider, info)
+ SetProvider(ctx, ModuleBuildTargetsProvider, info)
}
}
@@ -1876,15 +1852,15 @@ type SourceFilesInfo struct {
var SourceFilesInfoProvider = blueprint.NewProvider[SourceFilesInfo]()
-// FinalModuleBuildTargetsInfo is used by buildTargetSingleton to create checkbuild and
-// per-directory build targets. Only set on the final variant of each module
-type FinalModuleBuildTargetsInfo struct {
+// ModuleBuildTargetsInfo is used by buildTargetSingleton to create checkbuild and
+// per-directory build targets.
+type ModuleBuildTargetsInfo struct {
InstallTarget WritablePath
CheckbuildTarget WritablePath
BlueprintDir string
}
-var FinalModuleBuildTargetsProvider = blueprint.NewProvider[FinalModuleBuildTargetsInfo]()
+var ModuleBuildTargetsProvider = blueprint.NewProvider[ModuleBuildTargetsInfo]()
type CommonModuleInfo struct {
Enabled bool
@@ -2151,14 +2127,19 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
}
if sourceFileProducer, ok := m.module.(SourceFileProducer); ok {
+ srcs := sourceFileProducer.Srcs()
+ for _, src := range srcs {
+ if src == nil {
+ ctx.ModuleErrorf("SourceFileProducer cannot return nil srcs")
+ return
+ }
+ }
SetProvider(ctx, SourceFilesInfoProvider, SourceFilesInfo{Srcs: sourceFileProducer.Srcs()})
}
- if ctx.IsFinalModule(m.module) {
- m.generateModuleTarget(ctx)
- if ctx.Failed() {
- return
- }
+ m.generateModuleTarget(ctx)
+ if ctx.Failed() {
+ return
}
ctx.TransitiveInstallFiles = depset.New[InstallPath](depset.TOPOLOGICAL, ctx.installFiles, dependencyInstallFiles)
@@ -3098,7 +3079,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
modulesInDir := make(map[string]Paths)
ctx.VisitAllModuleProxies(func(module ModuleProxy) {
- info := OtherModuleProviderOrDefault(ctx, module, FinalModuleBuildTargetsProvider)
+ info := OtherModuleProviderOrDefault(ctx, module, ModuleBuildTargetsProvider)
if info.CheckbuildTarget != nil {
checkbuildDeps = append(checkbuildDeps, info.CheckbuildTarget)
diff --git a/android/module_context.go b/android/module_context.go
index fb62e6749..0a23a745f 100644
--- a/android/module_context.go
+++ b/android/module_context.go
@@ -456,6 +456,11 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
}
func (m *moduleContext) Phony(name string, deps ...Path) {
+ for _, dep := range deps {
+ if dep == nil {
+ panic("Phony dep cannot be nil")
+ }
+ }
m.phonies[name] = append(m.phonies[name], deps...)
}
@@ -748,6 +753,9 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat
m.packageFile(fullInstallPath, srcPath, executable, m.requiresFullInstall())
if checkbuild {
+ if srcPath == nil {
+ panic("srcPath cannot be nil")
+ }
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
}
@@ -879,6 +887,11 @@ func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath
// CheckbuildFile specifies the output files that should be built by checkbuild.
func (m *moduleContext) CheckbuildFile(srcPaths ...Path) {
+ for _, srcPath := range srcPaths {
+ if srcPath == nil {
+ panic("CheckbuildFile() files cannot be nil")
+ }
+ }
m.checkbuildFiles = append(m.checkbuildFiles, srcPaths...)
}
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 27a68fbe5..d31fc4fcd 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -551,6 +551,9 @@ func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
}
func (s *sourceModule) Srcs() Paths {
+ if s.src == nil {
+ return nil
+ }
return Paths{s.src}
}
diff --git a/android/test_suites_test.go b/android/test_suites_test.go
index dda93297a..03aa42413 100644
--- a/android/test_suites_test.go
+++ b/android/test_suites_test.go
@@ -108,7 +108,8 @@ var prepareForFakeTestSuite = GroupFixturePreparers(
func (f *fake_module) GenerateAndroidBuildActions(ctx ModuleContext) {
for _, output := range f.props.Outputs {
- ctx.InstallFile(pathForTestCases(ctx), output, nil)
+ f := PathForModuleOut(ctx, output)
+ ctx.InstallFile(pathForTestCases(ctx), output, f)
}
SetProvider(ctx, TestSuiteInfoProvider, TestSuiteInfo{