Merge "Cosmetic: More helpful error message"

This commit is contained in:
Treehugger Robot
2022-08-12 22:32:12 +00:00
committed by Gerrit Code Review
2 changed files with 50 additions and 16 deletions

View File

@@ -268,6 +268,8 @@ func fixBadDanglingLink(ctx build.Context, name string) {
func dumpVar(ctx build.Context, config build.Config, args []string, _ string) {
flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)
flags.SetOutput(ctx.Writer)
flags.Usage = func() {
fmt.Fprintf(ctx.Writer, "usage: %s --dumpvar-mode [--abs] <VAR>\n\n", os.Args[0])
fmt.Fprintln(ctx.Writer, "In dumpvar mode, print the value of the legacy make variable VAR to stdout")
@@ -318,6 +320,8 @@ func dumpVar(ctx build.Context, config build.Config, args []string, _ string) {
func dumpVars(ctx build.Context, config build.Config, args []string, _ string) {
flags := flag.NewFlagSet("dumpvars", flag.ExitOnError)
flags.SetOutput(ctx.Writer)
flags.Usage = func() {
fmt.Fprintf(ctx.Writer, "usage: %s --dumpvars-mode [--vars=\"VAR VAR ...\"]\n\n", os.Args[0])
fmt.Fprintln(ctx.Writer, "In dumpvars mode, dump the values of one or more legacy make variables, in")
@@ -401,6 +405,8 @@ func dumpVarConfig(ctx build.Context, args ...string) build.Config {
func buildActionConfig(ctx build.Context, args ...string) build.Config {
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
flags.SetOutput(ctx.Writer)
flags.Usage = func() {
fmt.Fprintf(ctx.Writer, "usage: %s --build-mode --dir=<path> <build action> [<build arg 1> <build arg 2> ...]\n\n", os.Args[0])
fmt.Fprintln(ctx.Writer, "In build mode, build the set of modules based on the specified build")
@@ -453,21 +459,32 @@ func buildActionConfig(ctx build.Context, args ...string) build.Config {
const numBuildActionFlags = 2
if len(args) < numBuildActionFlags {
flags.Usage()
ctx.Fatalln("Improper build action arguments.")
ctx.Fatalln("Improper build action arguments: too few arguments")
}
flags.Parse(args[0:numBuildActionFlags])
parseError := flags.Parse(args[0:numBuildActionFlags])
// The next block of code is to validate that exactly one build action is set and the dir flag
// is specified.
buildActionCount := 0
buildActionFound := false
var buildAction build.BuildAction
for _, flag := range buildActionFlags {
if flag.set {
buildActionCount++
buildAction = flag.action
for _, f := range buildActionFlags {
if f.set {
if buildActionFound {
if parseError == nil {
//otherwise Parse() already called Usage()
flags.Usage()
}
ctx.Fatalf("Build action already specified, omit: --%s\n", f.name)
}
buildActionFound = true
buildAction = f.action
}
}
if buildActionCount != 1 {
if !buildActionFound {
if parseError == nil {
//otherwise Parse() already called Usage()
flags.Usage()
}
ctx.Fatalln("Build action not defined.")
}
if *dir == "" {
@@ -509,8 +526,16 @@ func runMake(ctx build.Context, config build.Config, _ []string, logsDir string)
// getCommand finds the appropriate command based on args[1] flag. args[0]
// is the soong_ui filename.
func getCommand(args []string) (*command, []string, error) {
listFlags := func() []string {
flags := make([]string, len(commands))
for i, c := range commands {
flags[i] = c.flag
}
return flags
}
if len(args) < 2 {
return nil, nil, fmt.Errorf("Too few arguments: %q", args)
return nil, nil, fmt.Errorf("Too few arguments: %q\nUse one of these: %q", args, listFlags())
}
for _, c := range commands {
@@ -518,13 +543,7 @@ func getCommand(args []string) (*command, []string, error) {
return &c, args[2:], nil
}
}
// command not found
flags := make([]string, len(commands))
for i, c := range commands {
flags[i] = c.flag
}
return nil, nil, fmt.Errorf("Command not found: %q\nDid you mean one of these: %q", args, flags)
return nil, nil, fmt.Errorf("Command not found: %q\nDid you mean one of these: %q", args[1], listFlags())
}
// For Bazel support, this moves files and directories from e.g. out/dist/$f to DIST_DIR/$f if necessary.

View File

@@ -201,7 +201,20 @@ func Build(ctx Context, config Config) {
buildLock := BecomeSingletonOrFail(ctx, config)
defer buildLock.Unlock()
logArgsOtherThan := func(specialTargets ...string) {
var ignored []string
for _, a := range config.Arguments() {
if !inList(a, specialTargets) {
ignored = append(ignored, a)
}
}
if len(ignored) > 0 {
ctx.Printf("ignoring arguments %q", ignored)
}
}
if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) {
logArgsOtherThan("clean", "clobber")
clean(ctx, config)
return
}
@@ -279,6 +292,7 @@ func Build(ctx Context, config Config) {
if inList("installclean", config.Arguments()) ||
inList("install-clean", config.Arguments()) {
logArgsOtherThan("installclean", "install-clean")
installClean(ctx, config)
ctx.Println("Deleted images and staging directories.")
return
@@ -286,6 +300,7 @@ func Build(ctx Context, config Config) {
if inList("dataclean", config.Arguments()) ||
inList("data-clean", config.Arguments()) {
logArgsOtherThan("dataclean", "data-clean")
dataClean(ctx, config)
ctx.Println("Deleted data files.")
return