Separate output from diagnostics in Starlark product configuration.
Some of the product configuration makefiles use `info` and `warning` Make's
builtins for diagnostics. As running Starlark configuration generates the makefile
as its output, this diagnostics has to go elsewhere. Implement `rblf_log` as
the functional equivalent of `print` that writes to stderr instead of stdout
and use it to implement `info` and `warning` counterparts.
Fixes: 201073196
Test: manual
Change-Id: Ib4d9c10566f9b20310fbee41eda67f0a621b0a84
diff --git a/tools/rbcrun/host.go b/tools/rbcrun/host.go
index 7f4f72d..4915de9 100644
--- a/tools/rbcrun/host.go
+++ b/tools/rbcrun/host.go
@@ -259,6 +259,28 @@
return starlarkstruct.FromStringDict(starlarkstruct.Default, sd)
}
+func log(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
+ sep := " "
+ if err := starlark.UnpackArgs("print", nil, kwargs, "sep?", &sep); err != nil {
+ return nil, err
+ }
+ for i, v := range args {
+ if i > 0 {
+ fmt.Fprint(os.Stderr, sep)
+ }
+ if s, ok := starlark.AsString(v); ok {
+ fmt.Fprint(os.Stderr, s)
+ } else if b, ok := v.(starlark.Bytes); ok {
+ fmt.Fprint(os.Stderr, string(b))
+ } else {
+ fmt.Fprintf(os.Stderr, "%s", v)
+ }
+ }
+
+ fmt.Fprintln(os.Stderr)
+ return starlark.None, nil
+}
+
func setup(env []string) {
// Create the symbols that aid makefile conversion. See README.md
builtins = starlark.StringDict{
@@ -273,6 +295,8 @@
"rblf_regex": starlark.NewBuiltin("rblf_regex", regexMatch),
// To convert makefile's $(shell cmd)
"rblf_shell": starlark.NewBuiltin("rblf_shell", shell),
+ // Output to stderr
+ "rblf_log": starlark.NewBuiltin("rblf_log", log),
// To convert makefile's $(wildcard foo*)
"rblf_wildcard": starlark.NewBuiltin("rblf_wildcard", wildcard),
}