Generate board-specific launchers in mk2rbc
Board config works slightly differently from product config. It requires the product config variables to be passed into it. Currently the only generic way to pass info into an RBC script is via the arguments to rbcrun, which get passed as global variables, not the product (cfg) variables. Add a new form of launcher that reads the product variables from a separate rbc file that is generated in make. The board configuration also doesn't need inheritance, so it doesn't call rblf.product_configuration() either. Bug: 201700692 Test: build/bazel/ci/rbc_product_config.sh -b sdk_phone_x86_64-userdebug Change-Id: I52fd65b33cf99b45a563284e2849da75a8af8688
This commit is contained in:
@@ -53,10 +53,12 @@ var (
|
|||||||
// TODO(asmundak): this option is for debugging
|
// TODO(asmundak): this option is for debugging
|
||||||
allInSource = flag.Bool("all", false, "convert all product config makefiles in the tree under //")
|
allInSource = flag.Bool("all", false, "convert all product config makefiles in the tree under //")
|
||||||
outputTop = flag.String("outdir", "", "write output files into this directory hierarchy")
|
outputTop = flag.String("outdir", "", "write output files into this directory hierarchy")
|
||||||
launcher = flag.String("launcher", "", "generated launcher path. If set, the non-flag argument is _product_name_")
|
launcher = flag.String("launcher", "", "generated launcher path.")
|
||||||
|
boardlauncher = flag.String("boardlauncher", "", "generated board configuration launcher path.")
|
||||||
printProductConfigMap = flag.Bool("print_product_config_map", false, "print product config map and exit")
|
printProductConfigMap = flag.Bool("print_product_config_map", false, "print product config map and exit")
|
||||||
cpuProfile = flag.String("cpu_profile", "", "write cpu profile to file")
|
cpuProfile = flag.String("cpu_profile", "", "write cpu profile to file")
|
||||||
traceCalls = flag.Bool("trace_calls", false, "trace function calls")
|
traceCalls = flag.Bool("trace_calls", false, "trace function calls")
|
||||||
|
inputVariables = flag.String("input_variables", "", "starlark file containing product config and global variables")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -87,8 +89,7 @@ func main() {
|
|||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
cmd := filepath.Base(os.Args[0])
|
cmd := filepath.Base(os.Args[0])
|
||||||
fmt.Fprintf(flag.CommandLine.Output(),
|
fmt.Fprintf(flag.CommandLine.Output(),
|
||||||
"Usage: %[1]s flags file...\n"+
|
"Usage: %[1]s flags file...\n", cmd)
|
||||||
"or: %[1]s flags --launcher=PATH PRODUCT\n", cmd)
|
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -177,14 +178,31 @@ func main() {
|
|||||||
versionDefaultsPath := outputFilePath(versionDefaultsMk)
|
versionDefaultsPath := outputFilePath(versionDefaultsMk)
|
||||||
err = writeGenerated(versionDefaultsPath, versionDefaults)
|
err = writeGenerated(versionDefaultsPath, versionDefaults)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s", files[0], err)
|
fmt.Fprintf(os.Stderr, "%s: %s", files[0], err)
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(files[0]), versionDefaultsPath,
|
err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(files[0]), versionDefaultsPath,
|
||||||
mk2rbc.MakePath2ModuleName(files[0])))
|
mk2rbc.MakePath2ModuleName(files[0])))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s", files[0], err)
|
fmt.Fprintf(os.Stderr, "%s: %s", files[0], err)
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if *boardlauncher != "" {
|
||||||
|
if len(files) != 1 {
|
||||||
|
quit(fmt.Errorf("a launcher can be generated only for a single product"))
|
||||||
|
}
|
||||||
|
if *inputVariables == "" {
|
||||||
|
quit(fmt.Errorf("the board launcher requires an input variables file"))
|
||||||
|
}
|
||||||
|
if !convertOne(*inputVariables) {
|
||||||
|
quit(fmt.Errorf("the board launcher input variables file failed to convert"))
|
||||||
|
}
|
||||||
|
err := writeGenerated(*boardlauncher, mk2rbc.BoardLauncher(
|
||||||
|
outputFilePath(files[0]), outputFilePath(*inputVariables)))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s: %s", files[0], err)
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,9 @@ const (
|
|||||||
// And here are the functions and variables:
|
// And here are the functions and variables:
|
||||||
cfnGetCfg = baseName + ".cfg"
|
cfnGetCfg = baseName + ".cfg"
|
||||||
cfnMain = baseName + ".product_configuration"
|
cfnMain = baseName + ".product_configuration"
|
||||||
|
cfnBoardMain = baseName + ".board_configuration"
|
||||||
cfnPrintVars = baseName + ".printvars"
|
cfnPrintVars = baseName + ".printvars"
|
||||||
|
cfnPrintGlobals = baseName + ".printglobals"
|
||||||
cfnWarning = baseName + ".warning"
|
cfnWarning = baseName + ".warning"
|
||||||
cfnLocalAppend = baseName + ".local_append"
|
cfnLocalAppend = baseName + ".local_append"
|
||||||
cfnLocalSetDefault = baseName + ".local_set_default"
|
cfnLocalSetDefault = baseName + ".local_set_default"
|
||||||
@@ -1702,6 +1704,17 @@ func Launcher(mainModuleUri, versionDefaultsUri, mainModuleName string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BoardLauncher(mainModuleUri string, inputVariablesUri string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fmt.Fprintf(&buf, "load(%q, %q)\n", baseUri, baseName)
|
||||||
|
fmt.Fprintf(&buf, "load(%q, \"init\")\n", mainModuleUri)
|
||||||
|
fmt.Fprintf(&buf, "load(%q, input_variables_init = \"init\")\n", inputVariablesUri)
|
||||||
|
fmt.Fprintf(&buf, "globals, cfg, globals_base = %s(init, input_variables_init)\n", cfnBoardMain)
|
||||||
|
fmt.Fprintf(&buf, "# TODO: Some product config variables need to be printed, but most are readonly so we can't just print cfg here.\n")
|
||||||
|
fmt.Fprintf(&buf, "%s(globals, globals_base)\n", cfnPrintGlobals)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
func MakePath2ModuleName(mkPath string) string {
|
func MakePath2ModuleName(mkPath string) string {
|
||||||
return strings.TrimSuffix(mkPath, filepath.Ext(mkPath))
|
return strings.TrimSuffix(mkPath, filepath.Ext(mkPath))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user