diff options
author | Patrice Arruda <patricearruda@google.com> | 2019-05-21 17:46:23 -0700 |
---|---|---|
committer | Luca Stefani <luca.stefani.ge1@gmail.com> | 2019-09-04 15:32:11 +0200 |
commit | 0b02a5c7107477d3ad88fb84538e8e758477a27c (patch) | |
tree | d54322859d3632d0abf738aa361bb8f1f58d1783 | |
parent | 5b6688cf3e99b8c3a15d4e0cdb260b9ffc0be19f (diff) | |
download | build_soong-0b02a5c7107477d3ad88fb84538e8e758477a27c.tar.gz build_soong-0b02a5c7107477d3ad88fb84538e8e758477a27c.tar.bz2 build_soong-0b02a5c7107477d3ad88fb84538e8e758477a27c.zip |
soong_ui: Add --build-mode flag in soong_ui
The --build-mode flag is a new flag in soong_ui that accepts a build
action (m, mm, mmm, mma, mmma), the directory where the build action
is occuring and an optional list of build arguments and invokes the
build option. This is to deprecate the build actions behavior in
envsetup.sh and start using the one defined in soong_ui.
Bug: b/130049705
Test: Ran lunch and ran all the build action commands in soong_ui.
Ran a bunch of invalid commands such as no Android.mk file in
a specific directory, invalid target name, etc...
Change-Id: I88e9e59f47f8c5cdc872fb83a0f3f0a0919885b6
-rw-r--r-- | cmd/soong_ui/main.go | 98 |
1 files changed, 94 insertions, 4 deletions
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 8781dcf0..0d5ed444 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -61,10 +61,8 @@ var commands []command = []command{ config: func(ctx build.Context, args ...string) build.Config { return build.NewConfig(ctx, args...) }, - stdio: func() terminal.StdioInterface { - return terminal.StdioImpl{} - }, - run: make, + stdio: stdio, + run: make, }, { flag: "--dumpvar-mode", description: "print the value of the legacy make variable VAR to stdout", @@ -77,6 +75,12 @@ var commands []command = []command{ config: dumpVarConfig, stdio: customStdio, run: dumpVars, + }, { + flag: "--build-mode", + description: "build modules based on the specified build action", + config: buildActionConfig, + stdio: stdio, + run: make, }, } @@ -318,6 +322,10 @@ func dumpVars(ctx build.Context, config build.Config, args []string, _ string) { } } +func stdio() terminal.StdioInterface { + return terminal.StdioImpl{} +} + func customStdio() terminal.StdioInterface { return terminal.NewCustomStdio(os.Stdin, os.Stderr, os.Stderr) } @@ -327,6 +335,88 @@ func dumpVarConfig(ctx build.Context, args ...string) build.Config { return build.NewConfig(ctx) } +func buildActionConfig(ctx build.Context, args ...string) build.Config { + flags := flag.NewFlagSet("build-mode", flag.ContinueOnError) + 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") + fmt.Fprintln(ctx.Writer, "action. The --dir flag is required to determine what is needed to") + fmt.Fprintln(ctx.Writer, "build in the source tree based on the build action. See below for") + fmt.Fprintln(ctx.Writer, "the list of acceptable build action flags.") + fmt.Fprintln(ctx.Writer, "") + flags.PrintDefaults() + } + + buildActionFlags := []struct { + name string + description string + action build.BuildAction + buildDependencies bool + set bool + }{{ + name: "all-modules", + description: "Build action: build from the top of the source tree.", + action: build.BUILD_MODULES_IN_A_DIRECTORY, + buildDependencies: true, + }, { + name: "modules-in-a-dir-no-deps", + description: "Build action: builds all of the modules in the current directory without their dependencies.", + action: build.BUILD_MODULES_IN_A_DIRECTORY, + buildDependencies: false, + }, { + name: "modules-in-dirs-no-deps", + description: "Build action: builds all of the modules in the supplied directories without their dependencies.", + action: build.BUILD_MODULES_IN_DIRECTORIES, + buildDependencies: false, + }, { + name: "modules-in-a-dir", + description: "Build action: builds all of the modules in the current directory and their dependencies.", + action: build.BUILD_MODULES_IN_A_DIRECTORY, + buildDependencies: true, + }, { + name: "modules-in-dirs", + description: "Build action: builds all of the modules in the supplied directories and their dependencies.", + action: build.BUILD_MODULES_IN_DIRECTORIES, + buildDependencies: true, + }} + for i, flag := range buildActionFlags { + flags.BoolVar(&buildActionFlags[i].set, flag.name, false, flag.description) + } + dir := flags.String("dir", "", "Directory of the executed build command.") + + // Only interested in the first two args which defines the build action and the directory. + // The remaining arguments are passed down to the config. + const numBuildActionFlags = 2 + if len(args) < numBuildActionFlags { + flags.Usage() + ctx.Fatalln("Improper build action arguments.") + } + 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 + var buildAction build.BuildAction + buildDependency := false + for _, flag := range buildActionFlags { + if flag.set { + buildActionCount++ + buildAction = flag.action + buildDependency = flag.buildDependencies + } + } + if buildActionCount != 1 { + ctx.Fatalln("Build action not defined.") + } + if *dir == "" { + ctx.Fatalln("-dir not specified.") + } + + // Remove the build action flags from the args as they are not recognized by the config. + args = args[numBuildActionFlags:] + return build.NewBuildActionConfig(buildAction, *dir, buildDependency, ctx, args...) +} + func make(ctx build.Context, config build.Config, _ []string, logsDir string) { if config.IsVerbose() { writer := ctx.Writer |