cosmetic: fail fast on empty module list
also minor refactoring to limit var scopes Test: m nothing and ensure ninja files are generated Bug: N/A Change-Id: If7bdede4e54687955896b03ab11ef771855d2225
This commit is contained in:
parent
83ede83a31
commit
71ce3eae12
1 changed files with 26 additions and 32 deletions
|
@ -74,22 +74,22 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
defer trace.Stop()
|
||||
}
|
||||
|
||||
srcDir := "."
|
||||
|
||||
ninjaDeps := make([]string, 0)
|
||||
|
||||
if args.ModuleListFile != "" {
|
||||
ctx.SetModuleListFile(args.ModuleListFile)
|
||||
ninjaDeps = append(ninjaDeps, args.ModuleListFile)
|
||||
} else {
|
||||
if args.ModuleListFile == "" {
|
||||
fatalf("-l <moduleListFile> is required and must be nonempty")
|
||||
}
|
||||
ctx.SetModuleListFile(args.ModuleListFile)
|
||||
|
||||
var ninjaDeps []string
|
||||
ninjaDeps = append(ninjaDeps, args.ModuleListFile)
|
||||
|
||||
ctx.BeginEvent("list_modules")
|
||||
filesToParse, err := ctx.ListModulePaths(srcDir)
|
||||
ctx.EndEvent("list_modules")
|
||||
if err != nil {
|
||||
var filesToParse []string
|
||||
if f, err := ctx.ListModulePaths("."); err != nil {
|
||||
fatalf("could not enumerate files: %v\n", err.Error())
|
||||
} else {
|
||||
filesToParse = f
|
||||
}
|
||||
ctx.EndEvent("list_modules")
|
||||
|
||||
ctx.RegisterBottomUpMutator("bootstrap_plugin_deps", pluginDeps)
|
||||
ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModuleFactory())
|
||||
|
@ -97,37 +97,34 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
ctx.RegisterSingletonType("bootstrap", newSingletonFactory())
|
||||
|
||||
ctx.BeginEvent("parse_bp")
|
||||
blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config)
|
||||
if len(errs) > 0 {
|
||||
if blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config); len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
}
|
||||
} else {
|
||||
ctx.EndEvent("parse_bp")
|
||||
|
||||
// Add extra ninja file dependencies
|
||||
ninjaDeps = append(ninjaDeps, blueprintFiles...)
|
||||
|
||||
extraDeps, errs := ctx.ResolveDependencies(config)
|
||||
if len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
}
|
||||
ninjaDeps = append(ninjaDeps, extraDeps...)
|
||||
|
||||
if resolvedDeps, errs := ctx.ResolveDependencies(config); len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
} else {
|
||||
ninjaDeps = append(ninjaDeps, resolvedDeps...)
|
||||
}
|
||||
|
||||
if stopBefore == StopBeforePrepareBuildActions {
|
||||
return ninjaDeps
|
||||
}
|
||||
|
||||
if ctx.BeforePrepareBuildActionsHook != nil {
|
||||
err := ctx.BeforePrepareBuildActionsHook()
|
||||
if err != nil {
|
||||
if err := ctx.BeforePrepareBuildActionsHook(); err != nil {
|
||||
fatalErrors([]error{err})
|
||||
}
|
||||
}
|
||||
|
||||
extraDeps, errs = ctx.PrepareBuildActions(config)
|
||||
if len(errs) > 0 {
|
||||
if buildActionsDeps, errs := ctx.PrepareBuildActions(config); len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
} else {
|
||||
ninjaDeps = append(ninjaDeps, buildActionsDeps...)
|
||||
}
|
||||
ninjaDeps = append(ninjaDeps, extraDeps...)
|
||||
|
||||
if stopBefore == StopBeforeWriteNinja {
|
||||
return ninjaDeps
|
||||
|
@ -147,7 +144,7 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
}
|
||||
|
||||
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 {
|
||||
fatalf("error opening Ninja file: %s", err)
|
||||
}
|
||||
|
@ -157,21 +154,18 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
out = io.Discard.(io.StringWriter)
|
||||
}
|
||||
|
||||
err = ctx.WriteBuildFile(out)
|
||||
if err != nil {
|
||||
if err := ctx.WriteBuildFile(out); err != nil {
|
||||
fatalf("error writing Ninja file contents: %s", err)
|
||||
}
|
||||
|
||||
if buf != nil {
|
||||
err = buf.Flush()
|
||||
if err != nil {
|
||||
if err := buf.Flush(); err != nil {
|
||||
fatalf("error flushing Ninja file contents: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if f != nil {
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
fatalf("error closing Ninja file: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue