Cosmetic: More helpful error message
Test: various invocations of ./build/soong/soong_ui.bash Bug: N/A Change-Id: I7be5b84330bc7525b5633314a111e5e1fa9fc844
This commit is contained in:
@@ -268,6 +268,8 @@ func fixBadDanglingLink(ctx build.Context, name string) {
|
|||||||
|
|
||||||
func dumpVar(ctx build.Context, config build.Config, args []string, _ string) {
|
func dumpVar(ctx build.Context, config build.Config, args []string, _ string) {
|
||||||
flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)
|
flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)
|
||||||
|
flags.SetOutput(ctx.Writer)
|
||||||
|
|
||||||
flags.Usage = func() {
|
flags.Usage = func() {
|
||||||
fmt.Fprintf(ctx.Writer, "usage: %s --dumpvar-mode [--abs] <VAR>\n\n", os.Args[0])
|
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")
|
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) {
|
func dumpVars(ctx build.Context, config build.Config, args []string, _ string) {
|
||||||
flags := flag.NewFlagSet("dumpvars", flag.ExitOnError)
|
flags := flag.NewFlagSet("dumpvars", flag.ExitOnError)
|
||||||
|
flags.SetOutput(ctx.Writer)
|
||||||
|
|
||||||
flags.Usage = func() {
|
flags.Usage = func() {
|
||||||
fmt.Fprintf(ctx.Writer, "usage: %s --dumpvars-mode [--vars=\"VAR VAR ...\"]\n\n", os.Args[0])
|
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")
|
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 {
|
func buildActionConfig(ctx build.Context, args ...string) build.Config {
|
||||||
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
|
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
|
||||||
|
flags.SetOutput(ctx.Writer)
|
||||||
|
|
||||||
flags.Usage = func() {
|
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.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")
|
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
|
const numBuildActionFlags = 2
|
||||||
if len(args) < numBuildActionFlags {
|
if len(args) < numBuildActionFlags {
|
||||||
flags.Usage()
|
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
|
// The next block of code is to validate that exactly one build action is set and the dir flag
|
||||||
// is specified.
|
// is specified.
|
||||||
buildActionCount := 0
|
buildActionFound := false
|
||||||
var buildAction build.BuildAction
|
var buildAction build.BuildAction
|
||||||
for _, flag := range buildActionFlags {
|
for _, f := range buildActionFlags {
|
||||||
if flag.set {
|
if f.set {
|
||||||
buildActionCount++
|
if buildActionFound {
|
||||||
buildAction = flag.action
|
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.")
|
ctx.Fatalln("Build action not defined.")
|
||||||
}
|
}
|
||||||
if *dir == "" {
|
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]
|
// getCommand finds the appropriate command based on args[1] flag. args[0]
|
||||||
// is the soong_ui filename.
|
// is the soong_ui filename.
|
||||||
func getCommand(args []string) (*command, []string, error) {
|
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 {
|
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 {
|
for _, c := range commands {
|
||||||
@@ -518,13 +543,7 @@ func getCommand(args []string) (*command, []string, error) {
|
|||||||
return &c, args[2:], nil
|
return &c, args[2:], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil, nil, fmt.Errorf("Command not found: %q\nDid you mean one of these: %q", args[1], listFlags())
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Bazel support, this moves files and directories from e.g. out/dist/$f to DIST_DIR/$f if necessary.
|
// For Bazel support, this moves files and directories from e.g. out/dist/$f to DIST_DIR/$f if necessary.
|
||||||
|
@@ -201,7 +201,20 @@ func Build(ctx Context, config Config) {
|
|||||||
buildLock := BecomeSingletonOrFail(ctx, config)
|
buildLock := BecomeSingletonOrFail(ctx, config)
|
||||||
defer buildLock.Unlock()
|
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()) {
|
if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) {
|
||||||
|
logArgsOtherThan("clean", "clobber")
|
||||||
clean(ctx, config)
|
clean(ctx, config)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -279,6 +292,7 @@ func Build(ctx Context, config Config) {
|
|||||||
|
|
||||||
if inList("installclean", config.Arguments()) ||
|
if inList("installclean", config.Arguments()) ||
|
||||||
inList("install-clean", config.Arguments()) {
|
inList("install-clean", config.Arguments()) {
|
||||||
|
logArgsOtherThan("installclean", "install-clean")
|
||||||
installClean(ctx, config)
|
installClean(ctx, config)
|
||||||
ctx.Println("Deleted images and staging directories.")
|
ctx.Println("Deleted images and staging directories.")
|
||||||
return
|
return
|
||||||
@@ -286,6 +300,7 @@ func Build(ctx Context, config Config) {
|
|||||||
|
|
||||||
if inList("dataclean", config.Arguments()) ||
|
if inList("dataclean", config.Arguments()) ||
|
||||||
inList("data-clean", config.Arguments()) {
|
inList("data-clean", config.Arguments()) {
|
||||||
|
logArgsOtherThan("dataclean", "data-clean")
|
||||||
dataClean(ctx, config)
|
dataClean(ctx, config)
|
||||||
ctx.Println("Deleted data files.")
|
ctx.Println("Deleted data files.")
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user