Merge "Remove unneeded rbcrun features" am: 872023376e am: 9840061379 am: 512662b325

Original change: https://android-review.googlesource.com/c/platform/build/+/2580473

Change-Id: I22bceef5fc680e44bbdd67d7a0e05c087a3de022
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-05-09 10:04:17 +00:00 committed by Automerger Merge Worker
commit b03cf2a481
9 changed files with 39 additions and 152 deletions

View file

@ -256,7 +256,7 @@ else
endif endif
$(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_board_config_results.mk \ $(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_board_config_results.mk \
$(OUT_DIR)/rbcrun RBC_OUT="make" $(OUT_DIR)/rbc/boardlauncher.rbc) $(OUT_DIR)/rbcrun $(OUT_DIR)/rbc/boardlauncher.rbc)
ifneq ($(.SHELLSTATUS),0) ifneq ($(.SHELLSTATUS),0)
$(error board configuration runner failed: $(.SHELLSTATUS)) $(error board configuration runner failed: $(.SHELLSTATUS))
endif endif

View file

@ -247,7 +247,7 @@ else
endif endif
$(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_product_config_results.mk \ $(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_product_config_results.mk \
$(OUT_DIR)/rbcrun RBC_OUT="make,global" $(OUT_DIR)/rbc/launcher.rbc) $(OUT_DIR)/rbcrun $(OUT_DIR)/rbc/launcher.rbc)
ifneq ($(.SHELLSTATUS),0) ifneq ($(.SHELLSTATUS),0)
$(error product configuration runner failed: $(.SHELLSTATUS)) $(error product configuration runner failed: $(.SHELLSTATUS))
endif endif

View file

@ -54,11 +54,6 @@ def __print_attr(attr, value):
if value == None: if value == None:
return return
if type(value) == "list": if type(value) == "list":
if _options.rearrange:
value = __printvars_rearrange_list(value)
if _options.format == "pretty":
print(attr, "=", repr(value))
elif _options.format == "make":
value = list(value) value = list(value)
for i, x in enumerate(value): for i, x in enumerate(value):
if type(x) == "tuple" and len(x) == 1: if type(x) == "tuple" and len(x) == 1:
@ -66,13 +61,9 @@ def __print_attr(attr, value):
elif type(x) != "string": elif type(x) != "string":
fail("Wasn't a list of strings:", attr, " value:", value) fail("Wasn't a list of strings:", attr, " value:", value)
print(attr, ":=", " ".join(value)) print(attr, ":=", " ".join(value))
elif _options.format == "pretty": else:
print(attr, "=", repr(value))
elif _options.format == "make":
# Trim all spacing to a single space # Trim all spacing to a single space
print(attr, ":=", _mkstrip(value)) print(attr, ":=", _mkstrip(value))
else:
fail("bad output format", _options.format)
def _printvars(state): def _printvars(state):
"""Prints configuration and global variables.""" """Prints configuration and global variables."""
@ -83,7 +74,6 @@ def _printvars(state):
for nsname, nsvars in sorted(val.items()): for nsname, nsvars in sorted(val.items()):
# Define SOONG_CONFIG_<ns> for Make, othewise # Define SOONG_CONFIG_<ns> for Make, othewise
# it cannot be added to .KATI_READONLY list # it cannot be added to .KATI_READONLY list
if _options.format == "make":
print("SOONG_CONFIG_" + nsname, ":=", " ".join(nsvars.keys())) print("SOONG_CONFIG_" + nsname, ":=", " ".join(nsvars.keys()))
for var, val in sorted(nsvars.items()): for var, val in sorted(nsvars.items()):
if val: if val:
@ -105,11 +95,6 @@ def _printvars(state):
elif attr not in globals_base or globals_base[attr] != val: elif attr not in globals_base or globals_base[attr] != val:
__print_attr(attr, val) __print_attr(attr, val)
def __printvars_rearrange_list(value_list):
"""Rearrange value list: return only distinct elements, maybe sorted."""
seen = {item: 0 for item in value_list}
return sorted(seen.keys()) if _options.rearrange == "sort" else seen.keys()
def __sort_pcm_names(pcm_names): def __sort_pcm_names(pcm_names):
# We have to add an extension back onto the pcm names when sorting, # We have to add an extension back onto the pcm names when sorting,
# or else the sort order could be wrong when one is a prefix of another. # or else the sort order could be wrong when one is a prefix of another.
@ -695,17 +680,9 @@ def _mkwarning(file, message = ""):
rblf_log(file, "warning", message, sep = ':') rblf_log(file, "warning", message, sep = ':')
def _mk2rbc_error(loc, message): def _mk2rbc_error(loc, message):
"""Prints a message about conversion error and stops. """Prints a message about conversion error and stops."""
If RBC_MK2RBC_CONTINUE environment variable is set,
the execution will continue after the message is printed.
"""
if _options.mk2rbc_continue:
rblf_log(loc, message, sep = ':')
else:
_mkerror(loc, message) _mkerror(loc, message)
def _mkinfo(file, message = ""): def _mkinfo(file, message = ""):
"""Prints info.""" """Prints info."""
rblf_log(message) rblf_log(message)
@ -877,39 +854,12 @@ def _clear_var_list(g, h, var_list):
# Cause the variable to appear set like the make version does # Cause the variable to appear set like the make version does
g[v] = "" g[v] = ""
# Settings used during debugging.
def __get_options(): _options = struct(
"""Returns struct containing runtime global settings."""
settings = dict(
format = "pretty",
rearrange = "",
trace_modules = False, trace_modules = False,
trace_variables = [], trace_variables = [],
mk2rbc_continue = False, )
)
for x in getattr(rblf_cli, "RBC_OUT", "").split(","):
if x == "sort" or x == "unique":
if settings["rearrange"]:
fail("RBC_OUT: either sort or unique is allowed (and sort implies unique)")
settings["rearrange"] = x
elif x == "pretty" or x == "make":
settings["format"] = x
elif x == "global":
# TODO: Remove this, kept for backwards compatibility
pass
elif x != "":
fail("RBC_OUT: got %s, should be one of: [pretty|make] [sort|unique]" % x)
for x in getattr(rblf_cli, "RBC_DEBUG", "").split(","):
if x == "!trace":
settings["trace_modules"] = True
elif x != "":
settings["trace_variables"].append(x)
if getattr(rblf_cli, "RBC_MK2RBC_CONTINUE", ""):
settings["mk2rbc_continue"] = True
return struct(**settings)
# Settings used during debugging.
_options = __get_options()
rblf = struct( rblf = struct(
soong_config_namespace = _soong_config_namespace, soong_config_namespace = _soong_config_namespace,
soong_config_append = _soong_config_append, soong_config_append = _soong_config_append,

View file

@ -223,16 +223,6 @@ func makeStringList(items []string) *starlark.List {
return starlark.NewList(elems) return starlark.NewList(elems)
} }
// propsetFromEnv constructs a propset from the array of KEY=value strings
func structFromEnv(env []string) *starlarkstruct.Struct {
sd := make(map[string]starlark.Value, len(env))
for _, x := range env {
kv := strings.SplitN(x, "=", 2)
sd[kv[0]] = starlark.String(kv[1])
}
return starlarkstruct.FromStringDict(starlarkstruct.Default, sd)
}
func log(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { func log(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
sep := " " sep := " "
if err := starlark.UnpackArgs("print", nil, kwargs, "sep?", &sep); err != nil { if err := starlark.UnpackArgs("print", nil, kwargs, "sep?", &sep); err != nil {
@ -255,12 +245,10 @@ func log(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwa
return starlark.None, nil return starlark.None, nil
} }
func setup(env []string) { func setup() {
// Create the symbols that aid makefile conversion. See README.md // Create the symbols that aid makefile conversion. See README.md
builtins = starlark.StringDict{ builtins = starlark.StringDict{
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make), "struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
"rblf_cli": structFromEnv(env),
"rblf_env": structFromEnv(os.Environ()),
// To convert find-copy-subdir and product-copy-files-by pattern // To convert find-copy-subdir and product-copy-files-by pattern
"rblf_find_files": starlark.NewBuiltin("rblf_find_files", find), "rblf_find_files": starlark.NewBuiltin("rblf_find_files", find),
// To convert makefile's $(shell cmd) // To convert makefile's $(shell cmd)
@ -285,11 +273,8 @@ func setup(env []string) {
// and the name that appears in error messages; // and the name that appears in error messages;
// * src is an optional source of bytes to use instead of filename // * src is an optional source of bytes to use instead of filename
// (it can be a string, or a byte array, or an io.Reader instance) // (it can be a string, or a byte array, or an io.Reader instance)
// * commandVars is an array of "VAR=value" items. They are accessible from func Run(filename string, src interface{}) error {
// the starlark script as members of the `rblf_cli` propset. setup()
func Run(filename string, src interface{}, commandVars []string) error {
setup(commandVars)
mainThread := &starlark.Thread{ mainThread := &starlark.Thread{
Name: "main", Name: "main",
Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) }, Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) },

View file

@ -53,8 +53,8 @@ func starlarktestSetup() {
} }
// Common setup for the tests: create thread, change to the test directory // Common setup for the tests: create thread, change to the test directory
func testSetup(t *testing.T, env []string) *starlark.Thread { func testSetup(t *testing.T) *starlark.Thread {
setup(env) setup()
thread := &starlark.Thread{ thread := &starlark.Thread{
Load: func(thread *starlark.Thread, module string) (starlark.StringDict, error) { Load: func(thread *starlark.Thread, module string) (starlark.StringDict, error) {
if module == "assert.star" { if module == "assert.star" {
@ -72,14 +72,16 @@ func testSetup(t *testing.T, env []string) *starlark.Thread {
func dataDir() string { func dataDir() string {
_, thisSrcFile, _, _ := runtime.Caller(0) _, thisSrcFile, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(thisSrcFile), "testdata") return filepath.Join(filepath.Dir(thisSrcFile), "testdata")
} }
func exerciseStarlarkTestFile(t *testing.T, starFile string) { func exerciseStarlarkTestFile(t *testing.T, starFile string) {
// In order to use "assert.star" from go/starlark.net/starlarktest in the tests, provide: // In order to use "assert.star" from go/starlark.net/starlarktest in the tests, provide:
// * load function that handles "assert.star" // * load function that handles "assert.star"
// * starlarktest.DataFile function that finds its location // * starlarktest.DataFile function that finds its location
setup(nil) setup()
if err := os.Chdir(dataDir()); err != nil {
t.Fatal(err)
}
thread := &starlark.Thread{ thread := &starlark.Thread{
Load: func(thread *starlark.Thread, module string) (starlark.StringDict, error) { Load: func(thread *starlark.Thread, module string) (starlark.StringDict, error) {
if module == "assert.star" { if module == "assert.star" {
@ -98,26 +100,9 @@ func exerciseStarlarkTestFile(t *testing.T, starFile string) {
} }
} }
func TestCliAndEnv(t *testing.T) {
// TODO(asmundak): convert this to use exerciseStarlarkTestFile
if err := os.Setenv("TEST_ENVIRONMENT_FOO", "test_environment_foo"); err != nil {
t.Fatal(err)
}
thread := testSetup(t, []string{"CLI_FOO=foo"})
if _, err := starlark.ExecFile(thread, "cli_and_env.star", nil, builtins); err != nil {
if err, ok := err.(*starlark.EvalError); ok {
t.Fatal(err.Backtrace())
}
t.Fatal(err)
}
}
func TestFileOps(t *testing.T) { func TestFileOps(t *testing.T) {
// TODO(asmundak): convert this to use exerciseStarlarkTestFile // TODO(asmundak): convert this to use exerciseStarlarkTestFile
if err := os.Setenv("TEST_DATA_DIR", dataDir()); err != nil { thread := testSetup(t)
t.Fatal(err)
}
thread := testSetup(t, nil)
if _, err := starlark.ExecFile(thread, "file_ops.star", nil, builtins); err != nil { if _, err := starlark.ExecFile(thread, "file_ops.star", nil, builtins); err != nil {
if err, ok := err.(*starlark.EvalError); ok { if err, ok := err.(*starlark.EvalError); ok {
t.Fatal(err.Backtrace()) t.Fatal(err.Backtrace())
@ -128,7 +113,7 @@ func TestFileOps(t *testing.T) {
func TestLoad(t *testing.T) { func TestLoad(t *testing.T) {
// TODO(asmundak): convert this to use exerciseStarlarkTestFile // TODO(asmundak): convert this to use exerciseStarlarkTestFile
thread := testSetup(t, nil) thread := testSetup(t)
thread.Load = func(thread *starlark.Thread, module string) (starlark.StringDict, error) { thread.Load = func(thread *starlark.Thread, module string) (starlark.StringDict, error) {
if module == "assert.star" { if module == "assert.star" {
return starlarktest.LoadAssertModule() return starlarktest.LoadAssertModule()
@ -148,8 +133,5 @@ func TestLoad(t *testing.T) {
} }
func TestShell(t *testing.T) { func TestShell(t *testing.T) {
if err := os.Setenv("TEST_DATA_DIR", dataDir()); err != nil {
t.Fatal(err)
}
exerciseStarlarkTestFile(t, "testdata/shell.star") exerciseStarlarkTestFile(t, "testdata/shell.star")
} }

View file

@ -20,44 +20,25 @@ import (
"go.starlark.net/starlark" "go.starlark.net/starlark"
"os" "os"
"rbcrun" "rbcrun"
"strings"
) )
var ( var (
execprog = flag.String("c", "", "execute program `prog`")
rootdir = flag.String("d", ".", "the value of // for load paths") rootdir = flag.String("d", ".", "the value of // for load paths")
file = flag.String("f", "", "file to execute")
perfFile = flag.String("perf", "", "save performance data") perfFile = flag.String("perf", "", "save performance data")
) )
func main() { func main() {
flag.Parse() flag.Parse()
filename := *file filename := ""
var src interface{}
var env []string
rc := 0
for _, arg := range flag.Args() { for _, arg := range flag.Args() {
if strings.Contains(arg, "=") { if filename == "" {
env = append(env, arg)
} else if filename == "" {
filename = arg filename = arg
} else { } else {
quit("only one file can be executed\n") quit("only one file can be executed\n")
} }
} }
if *execprog != "" {
if filename != "" {
quit("either -c or file name should be present\n")
}
filename = "<cmdline>"
src = *execprog
}
if filename == "" { if filename == "" {
if len(env) > 0 {
fmt.Fprintln(os.Stderr,
"no file to run -- if your file's name contains '=', use -f to specify it")
}
flag.Usage() flag.Usage()
os.Exit(1) os.Exit(1)
} }
@ -75,7 +56,8 @@ func main() {
} }
} }
rbcrun.LoadPathRoot = *rootdir rbcrun.LoadPathRoot = *rootdir
err := rbcrun.Run(filename, src, env) err := rbcrun.Run(filename, nil)
rc := 0
if *perfFile != "" { if *perfFile != "" {
if err2 := starlark.StopProfile(); err2 != nil { if err2 := starlark.StopProfile(); err2 != nil {
fmt.Fprintln(os.Stderr, err2) fmt.Fprintln(os.Stderr, err2)

View file

@ -1,11 +0,0 @@
# Tests rblf_env access
load("assert.star", "assert")
def test():
assert.eq(rblf_env.TEST_ENVIRONMENT_FOO, "test_environment_foo")
assert.fails(lambda: rblf_env.FOO_BAR_BAZ, ".*struct has no .FOO_BAR_BAZ attribute$")
assert.eq(rblf_cli.CLI_FOO, "foo")
test()

View file

@ -1,22 +1,21 @@
# Tests file ops builtins # Tests file ops builtins
load("assert.star", "assert") load("assert.star", "assert")
def test(): def test():
myname = "file_ops.star" myname = "file_ops.star"
files = rblf_wildcard("*.star") files = rblf_wildcard("*.star")
assert.true(myname in files, "expected %s in %s" % (myname, files)) assert.true(myname in files, "expected %s in %s" % (myname, files))
files = rblf_wildcard("*.star", rblf_env.TEST_DATA_DIR) files = rblf_wildcard("*.star")
assert.true(myname in files, "expected %s in %s" % (myname, files)) assert.true(myname in files, "expected %s in %s" % (myname, files))
files = rblf_wildcard("*.xxx") files = rblf_wildcard("*.xxx")
assert.true(len(files) == 0, "expansion should be empty but contains %s" % files) assert.true(len(files) == 0, "expansion should be empty but contains %s" % files)
mydir = "testdata" mydir = "testdata"
myrelname = "%s/%s" % (mydir, myname) myrelname = "%s/%s" % (mydir, myname)
files = rblf_find_files(rblf_env.TEST_DATA_DIR + "/../", "*") files = rblf_find_files("../", "*")
assert.true(mydir in files and myrelname in files, "expected %s and %s in %s" % (mydir, myrelname, files)) assert.true(mydir in files and myrelname in files, "expected %s and %s in %s" % (mydir, myrelname, files))
files = rblf_find_files(rblf_env.TEST_DATA_DIR + "/../", "*", only_files=1) files = rblf_find_files("../", "*", only_files=1)
assert.true(mydir not in files, "did not expect %s in %s" % (mydir, files)) assert.true(mydir not in files, "did not expect %s in %s" % (mydir, files))
assert.true(myrelname in files, "expected %s in %s" % (myrelname, files)) assert.true(myrelname in files, "expected %s in %s" % (myrelname, files))
files = rblf_find_files(rblf_env.TEST_DATA_DIR + "/../", "*.star") files = rblf_find_files("../", "*.star")
assert.true(myrelname in files, "expected %s in %s" % (myrelname, files)) assert.true(myrelname in files, "expected %s in %s" % (myrelname, files))
test() test()

View file

@ -1,5 +1,5 @@
# Tests "queue" data type # Tests "queue" data type
load("assert.star", "assert") load("assert.star", "assert")
assert.eq("load.star shell.star", rblf_shell("cd %s && ls -1 shell.star load.star 2>&1" % rblf_env.TEST_DATA_DIR)) assert.eq("load.star shell.star", rblf_shell("ls -1 shell.star load.star 2>&1"))
assert.eq("shell.star", rblf_shell("cd %s && echo shell.sta*" % rblf_env.TEST_DATA_DIR)) assert.eq("shell.star", rblf_shell("echo shell.sta*"))