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()
|
defer trace.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
srcDir := "."
|
if args.ModuleListFile == "" {
|
||||||
|
|
||||||
ninjaDeps := make([]string, 0)
|
|
||||||
|
|
||||||
if args.ModuleListFile != "" {
|
|
||||||
ctx.SetModuleListFile(args.ModuleListFile)
|
|
||||||
ninjaDeps = append(ninjaDeps, args.ModuleListFile)
|
|
||||||
} else {
|
|
||||||
fatalf("-l <moduleListFile> is required and must be nonempty")
|
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")
|
ctx.BeginEvent("list_modules")
|
||||||
filesToParse, err := ctx.ListModulePaths(srcDir)
|
var filesToParse []string
|
||||||
ctx.EndEvent("list_modules")
|
if f, err := ctx.ListModulePaths("."); err != nil {
|
||||||
if err != nil {
|
|
||||||
fatalf("could not enumerate files: %v\n", err.Error())
|
fatalf("could not enumerate files: %v\n", err.Error())
|
||||||
|
} else {
|
||||||
|
filesToParse = f
|
||||||
}
|
}
|
||||||
|
ctx.EndEvent("list_modules")
|
||||||
|
|
||||||
ctx.RegisterBottomUpMutator("bootstrap_plugin_deps", pluginDeps)
|
ctx.RegisterBottomUpMutator("bootstrap_plugin_deps", pluginDeps)
|
||||||
ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModuleFactory())
|
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.RegisterSingletonType("bootstrap", newSingletonFactory())
|
||||||
|
|
||||||
ctx.BeginEvent("parse_bp")
|
ctx.BeginEvent("parse_bp")
|
||||||
blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config)
|
if blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config); len(errs) > 0 {
|
||||||
if len(errs) > 0 {
|
|
||||||
fatalErrors(errs)
|
fatalErrors(errs)
|
||||||
|
} else {
|
||||||
|
ctx.EndEvent("parse_bp")
|
||||||
|
ninjaDeps = append(ninjaDeps, blueprintFiles...)
|
||||||
}
|
}
|
||||||
ctx.EndEvent("parse_bp")
|
|
||||||
|
|
||||||
// Add extra ninja file dependencies
|
if resolvedDeps, errs := ctx.ResolveDependencies(config); len(errs) > 0 {
|
||||||
ninjaDeps = append(ninjaDeps, blueprintFiles...)
|
|
||||||
|
|
||||||
extraDeps, errs := ctx.ResolveDependencies(config)
|
|
||||||
if len(errs) > 0 {
|
|
||||||
fatalErrors(errs)
|
fatalErrors(errs)
|
||||||
|
} else {
|
||||||
|
ninjaDeps = append(ninjaDeps, resolvedDeps...)
|
||||||
}
|
}
|
||||||
ninjaDeps = append(ninjaDeps, extraDeps...)
|
|
||||||
|
|
||||||
if stopBefore == StopBeforePrepareBuildActions {
|
if stopBefore == StopBeforePrepareBuildActions {
|
||||||
return ninjaDeps
|
return ninjaDeps
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.BeforePrepareBuildActionsHook != nil {
|
if ctx.BeforePrepareBuildActionsHook != nil {
|
||||||
err := ctx.BeforePrepareBuildActionsHook()
|
if err := ctx.BeforePrepareBuildActionsHook(); err != nil {
|
||||||
if err != nil {
|
|
||||||
fatalErrors([]error{err})
|
fatalErrors([]error{err})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extraDeps, errs = ctx.PrepareBuildActions(config)
|
if buildActionsDeps, errs := ctx.PrepareBuildActions(config); len(errs) > 0 {
|
||||||
if len(errs) > 0 {
|
|
||||||
fatalErrors(errs)
|
fatalErrors(errs)
|
||||||
|
} else {
|
||||||
|
ninjaDeps = append(ninjaDeps, buildActionsDeps...)
|
||||||
}
|
}
|
||||||
ninjaDeps = append(ninjaDeps, extraDeps...)
|
|
||||||
|
|
||||||
if stopBefore == StopBeforeWriteNinja {
|
if stopBefore == StopBeforeWriteNinja {
|
||||||
return ninjaDeps
|
return ninjaDeps
|
||||||
|
@ -147,7 +144,7 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
||||||
}
|
}
|
||||||
|
|
||||||
if !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)
|
||||||
}
|
}
|
||||||
|
@ -157,21 +154,18 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
||||||
out = io.Discard.(io.StringWriter)
|
out = io.Discard.(io.StringWriter)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ctx.WriteBuildFile(out)
|
if err := ctx.WriteBuildFile(out); err != nil {
|
||||||
if err != nil {
|
|
||||||
fatalf("error writing Ninja file contents: %s", err)
|
fatalf("error writing Ninja file contents: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if buf != nil {
|
if buf != nil {
|
||||||
err = buf.Flush()
|
if err := buf.Flush(); err != nil {
|
||||||
if err != nil {
|
|
||||||
fatalf("error flushing Ninja file contents: %s", err)
|
fatalf("error flushing Ninja file contents: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if f != nil {
|
if f != nil {
|
||||||
err = f.Close()
|
if err := f.Close(); err != nil {
|
||||||
if err != nil {
|
|
||||||
fatalf("error closing Ninja file: %s", err)
|
fatalf("error closing Ninja file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue