Remove some unnecessary arguments from Blueprint. am: ce41c169b5 am: f05ce1b487 am: 40c2cd13a5 am: 9da7aa7843

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

Change-Id: Ie2bf9bb4a32c62643e9c53086b86a29dbf1a5314
This commit is contained in:
Lukacs T. Berki 2021-08-31 14:42:53 +00:00 committed by Automerger Merge Worker
commit 28dc7366e1
3 changed files with 51 additions and 74 deletions

View file

@ -735,45 +735,41 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
ctx.AddSubninja(subninja) ctx.AddSubninja(subninja)
} }
if s.config.stage == StagePrimary { for _, i := range s.config.primaryBuilderInvocations {
for _, i := range s.config.primaryBuilderInvocations { flags := make([]string, 0)
flags := make([]string, 0) flags = append(flags, primaryBuilderCmdlinePrefix...)
flags = append(flags, primaryBuilderCmdlinePrefix...) flags = append(flags, i.Args...)
flags = append(flags, i.Args...)
// Build the main build.ninja // Build the main build.ninja
ctx.Build(pctx, blueprint.BuildParams{
Rule: generateBuildNinja,
Outputs: i.Outputs,
Inputs: i.Inputs,
Args: map[string]string{
"builder": primaryBuilderFile,
"extra": strings.Join(flags, " "),
},
// soong_ui explicitly requests what it wants to be build. This is
// because the same Ninja file contains instructions to run
// soong_build, run bp2build and to generate the JSON module graph.
Optional: true,
})
}
}
if s.config.stage == StageMain {
// Add a phony target for building various tools that are part of blueprint
ctx.Build(pctx, blueprint.BuildParams{ ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony, Rule: generateBuildNinja,
Outputs: []string{"blueprint_tools"}, Outputs: i.Outputs,
Inputs: blueprintTools, Inputs: i.Inputs,
}) Args: map[string]string{
"builder": primaryBuilderFile,
// Add a phony target for running go tests "extra": strings.Join(flags, " "),
ctx.Build(pctx, blueprint.BuildParams{ },
Rule: blueprint.Phony, // soong_ui explicitly requests what it wants to be build. This is
Outputs: []string{"blueprint_go_packages"}, // because the same Ninja file contains instructions to run
Inputs: blueprintGoPackages, // soong_build, run bp2build and to generate the JSON module graph.
Optional: true, Optional: true,
}) })
} }
// Add a phony target for building various tools that are part of blueprint
ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony,
Outputs: []string{"blueprint_tools"},
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,
})
} }
// packageRoot returns the module-specific package root directory path. This // packageRoot returns the module-specific package root directory path. This

View file

@ -30,24 +30,24 @@ import (
) )
type Args struct { type Args struct {
OutFile string ModuleListFile string
Subninjas []string OutDir string
Cpuprofile string SoongOutDir string
Memprofile string
DelveListen string
DelvePath string
TraceFile string
RunGoTests bool
UseValidations bool
NoGC bool
EmptyNinjaFile bool
BuildDir string
ModuleListFile string
NinjaBuildDir string
TopFile string
GeneratingPrimaryBuilder bool
OutFile string
Subninjas []string
PrimaryBuilderInvocations []PrimaryBuilderInvocation PrimaryBuilderInvocations []PrimaryBuilderInvocation
RunGoTests bool
UseValidations bool
EmptyNinjaFile bool
NoGC bool
Cpuprofile string
Memprofile string
DelveListen string
DelvePath string
TraceFile string
} }
func PrimaryBuilderExtraFlags(args Args, mainNinjaFile string) []string { func PrimaryBuilderExtraFlags(args Args, mainNinjaFile string) []string {
@ -105,7 +105,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
defer trace.Stop() defer trace.Stop()
} }
srcDir := filepath.Dir(args.TopFile) srcDir := "."
ninjaDeps := make([]string, 0) ninjaDeps := make([]string, 0)
@ -122,11 +122,6 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
soongOutDir := config.(BootstrapConfig).SoongOutDir() soongOutDir := config.(BootstrapConfig).SoongOutDir()
stage := StageMain
if args.GeneratingPrimaryBuilder {
stage = StagePrimary
}
mainNinjaFile := filepath.Join("$soongOutDir", "build.ninja") mainNinjaFile := filepath.Join("$soongOutDir", "build.ninja")
var invocations []PrimaryBuilderInvocation var invocations []PrimaryBuilderInvocation
@ -135,19 +130,15 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
invocations = args.PrimaryBuilderInvocations invocations = args.PrimaryBuilderInvocations
} else { } else {
primaryBuilderArgs := PrimaryBuilderExtraFlags(args, mainNinjaFile) primaryBuilderArgs := PrimaryBuilderExtraFlags(args, mainNinjaFile)
primaryBuilderArgs = append(primaryBuilderArgs, args.TopFile)
invocations = []PrimaryBuilderInvocation{{ invocations = []PrimaryBuilderInvocation{{
Inputs: []string{args.TopFile}, Inputs: []string{},
Outputs: []string{mainNinjaFile}, Outputs: []string{mainNinjaFile},
Args: primaryBuilderArgs, Args: primaryBuilderArgs,
}} }}
} }
bootstrapConfig := &Config{ bootstrapConfig := &Config{
stage: stage,
topLevelBlueprintsFile: args.TopFile,
subninjas: args.Subninjas, subninjas: args.Subninjas,
runGoTests: args.RunGoTests, runGoTests: args.RunGoTests,
useValidations: args.UseValidations, useValidations: args.UseValidations,
@ -160,7 +151,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
ctx.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory(bootstrapConfig, true)) ctx.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory(bootstrapConfig, true))
ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig)) ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig))
blueprintFiles, errs := ctx.ParseFileList(filepath.Dir(args.TopFile), filesToParse, config) blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config)
if len(errs) > 0 { if len(errs) > 0 {
fatalErrors(errs) fatalErrors(errs)
} }
@ -203,7 +194,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
} }
} }
if stage != StageMain || !args.EmptyNinjaFile { if !args.EmptyNinjaFile {
f, err = os.OpenFile(joinPath(ctx.SrcDir(), args.OutFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, outFilePermissions) f, err = os.OpenFile(joinPath(ctx.SrcDir(), args.OutFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, outFilePermissions)
if err != nil { if err != nil {
fatalf("error opening Ninja file: %s", err) fatalf("error opening Ninja file: %s", err)

View file

@ -113,13 +113,6 @@ type ConfigStopBefore interface {
StopBefore() StopBefore StopBefore() StopBefore
} }
type Stage int
const (
StagePrimary Stage = iota
StageMain
)
type PrimaryBuilderInvocation struct { type PrimaryBuilderInvocation struct {
Inputs []string Inputs []string
Outputs []string Outputs []string
@ -127,10 +120,7 @@ type PrimaryBuilderInvocation struct {
} }
type Config struct { type Config struct {
stage Stage subninjas []string
topLevelBlueprintsFile string
subninjas []string
runGoTests bool runGoTests bool
useValidations bool useValidations bool