Add blueprint_go_packages phony to build all go packages am: 0f0e304d08 am: 5832a98338

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1713431

Change-Id: I092c67fdcd674b0a9ee2239be692f0bfef0cd587
This commit is contained in:
Dan Willemsen 2021-05-24 21:54:48 +00:00 committed by Automerger Merge Worker
commit f060e1f905

View file

@ -367,6 +367,16 @@ func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) {
testSrcs, g.config.useValidations) testSrcs, g.config.useValidations)
} }
// Don't build for test-only packages
if len(srcs) == 0 && len(genSrcs) == 0 {
ctx.Build(pctx, blueprint.BuildParams{
Rule: touch,
Outputs: []string{g.archiveFile},
Optional: true,
})
return
}
buildGoPackage(ctx, g.pkgRoot, g.properties.PkgPath, g.archiveFile, buildGoPackage(ctx, g.pkgRoot, g.properties.PkgPath, g.archiveFile,
srcs, genSrcs) srcs, genSrcs)
} }
@ -686,16 +696,25 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
var primaryBuilders []*goBinary var primaryBuilders []*goBinary
// blueprintTools contains blueprint go binaries that will be built in StageMain // blueprintTools contains blueprint go binaries that will be built in StageMain
var blueprintTools []string var blueprintTools []string
ctx.VisitAllModulesIf(isBootstrapBinaryModule, // blueprintGoPackages contains all blueprint go packages that can be built in StageMain
var blueprintGoPackages []string
ctx.VisitAllModulesIf(IsBootstrapModule,
func(module blueprint.Module) { func(module blueprint.Module) {
if ctx.PrimaryModule(module) == module { if ctx.PrimaryModule(module) == module {
binaryModule := module.(*goBinary) if binaryModule, ok := module.(*goBinary); ok {
if binaryModule.properties.Tool_dir {
if binaryModule.properties.Tool_dir { blueprintTools = append(blueprintTools, binaryModule.InstallPath())
blueprintTools = append(blueprintTools, binaryModule.InstallPath()) }
if binaryModule.properties.PrimaryBuilder {
primaryBuilders = append(primaryBuilders, binaryModule)
}
} }
if binaryModule.properties.PrimaryBuilder {
primaryBuilders = append(primaryBuilders, binaryModule) if packageModule, ok := module.(*goPackage); ok {
blueprintGoPackages = append(blueprintGoPackages,
packageModule.GoPackageTarget())
blueprintGoPackages = append(blueprintGoPackages,
packageModule.GoTestTargets()...)
} }
} }
}) })
@ -788,6 +807,14 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Outputs: []string{"blueprint_tools"}, Outputs: []string{"blueprint_tools"},
Inputs: blueprintTools, Inputs: blueprintTools,
}) })
// Add a phony target for running go tests
ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony,
Outputs: []string{"blueprint_go_packages"},
Inputs: blueprintGoPackages,
Optional: true,
})
} }
} }