Add build-flag-declarations tool
This will be used to gather build flag declarations Bug: 328495189 Test: manual, TH Change-Id: I155c26b1442347c4d433c9cbf22b94d944636702
This commit is contained in:
parent
b9519094d9
commit
fa4ba22a41
3 changed files with 141 additions and 0 deletions
28
bin/build-flag-declarations
Executable file
28
bin/build-flag-declarations
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash -eu
|
||||||
|
#
|
||||||
|
# Copyright 2017 Google Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
|
||||||
|
require_top
|
||||||
|
|
||||||
|
# Save the current PWD for use in soong_ui
|
||||||
|
export ORIGINAL_PWD=${PWD}
|
||||||
|
export TOP=$(gettop)
|
||||||
|
source ${TOP}/build/soong/scripts/microfactory.bash
|
||||||
|
|
||||||
|
soong_build_go build-flag-declarations android/soong/cmd/release_config/build_flag_declarations
|
||||||
|
|
||||||
|
cd ${TOP}
|
||||||
|
exec "$(getoutdir)/build-flag-declarations" "$@"
|
32
cmd/release_config/build_flag_declarations/Android.bp
Normal file
32
cmd/release_config/build_flag_declarations/Android.bp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
blueprint_go_binary {
|
||||||
|
name: "build-flag-declarations",
|
||||||
|
deps: [
|
||||||
|
"golang-protobuf-encoding-prototext",
|
||||||
|
"golang-protobuf-reflect-protoreflect",
|
||||||
|
"golang-protobuf-runtime-protoimpl",
|
||||||
|
"soong-cmd-release_config-proto",
|
||||||
|
"soong-cmd-release_config-lib",
|
||||||
|
],
|
||||||
|
srcs: [
|
||||||
|
"main.go",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap_go_package {
|
||||||
|
name: "soong-cmd-release_config-build_flag_declarations",
|
||||||
|
pkgPath: "android/soong/cmd/release_config/build_flag_declarations",
|
||||||
|
deps: [
|
||||||
|
"golang-protobuf-encoding-prototext",
|
||||||
|
"golang-protobuf-reflect-protoreflect",
|
||||||
|
"golang-protobuf-runtime-protoimpl",
|
||||||
|
"soong-cmd-release_config-proto",
|
||||||
|
"soong-cmd-release_config-lib",
|
||||||
|
],
|
||||||
|
srcs: [
|
||||||
|
"main.go",
|
||||||
|
],
|
||||||
|
}
|
81
cmd/release_config/build_flag_declarations/main.go
Normal file
81
cmd/release_config/build_flag_declarations/main.go
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
rc_lib "android/soong/cmd/release_config/release_config_lib"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Flags struct {
|
||||||
|
// The path to the top of the workspace. Default: ".".
|
||||||
|
top string
|
||||||
|
|
||||||
|
// Output file.
|
||||||
|
output string
|
||||||
|
|
||||||
|
// Format for output file
|
||||||
|
format string
|
||||||
|
|
||||||
|
// List of flag_declaration files to add.
|
||||||
|
decls rc_lib.StringList
|
||||||
|
|
||||||
|
// List of flag_artifacts files to merge.
|
||||||
|
intermediates rc_lib.StringList
|
||||||
|
|
||||||
|
// Disable warning messages
|
||||||
|
quiet bool
|
||||||
|
|
||||||
|
// Panic on errors.
|
||||||
|
debug bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var flags Flags
|
||||||
|
topDir, err := rc_lib.GetTopDir()
|
||||||
|
|
||||||
|
// Handle the common arguments
|
||||||
|
flag.StringVar(&flags.top, "top", topDir, "path to top of workspace")
|
||||||
|
flag.Var(&flags.decls, "decl", "path to a flag_declaration file. May be repeated")
|
||||||
|
flag.Var(&flags.intermediates, "intermediate", "path to a flag_artifacts file (output from a prior run). May be repeated")
|
||||||
|
flag.StringVar(&flags.format, "format", "pb", "output file format")
|
||||||
|
flag.StringVar(&flags.output, "output", "build_flags.pb", "output file")
|
||||||
|
flag.BoolVar(&flags.debug, "debug", false, "turn on debugging output for errors")
|
||||||
|
flag.BoolVar(&flags.quiet, "quiet", false, "disable warning messages")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
errorExit := func(err error) {
|
||||||
|
if flags.debug {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.quiet {
|
||||||
|
rc_lib.DisableWarnings()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = os.Chdir(flags.top); err != nil {
|
||||||
|
errorExit(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
flagArtifacts := rc_lib.FlagArtifactsFactory("")
|
||||||
|
for _, intermediate := range flags.intermediates {
|
||||||
|
fas := rc_lib.FlagArtifactsFactory(intermediate)
|
||||||
|
for _, fa := range *fas {
|
||||||
|
(*flagArtifacts)[*fa.FlagDeclaration.Name] = fa
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, decl := range flags.decls {
|
||||||
|
fa := rc_lib.FlagArtifactFactory(decl)
|
||||||
|
(*flagArtifacts)[*fa.FlagDeclaration.Name] = fa
|
||||||
|
}
|
||||||
|
|
||||||
|
message := flagArtifacts.GenerateFlagArtifacts()
|
||||||
|
err = rc_lib.WriteFormattedMessage(flags.output, flags.format, message)
|
||||||
|
if err != nil {
|
||||||
|
errorExit(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue