Only allow .scl files to load other .scl files
.scl files are starlark configuraiont language files, which is starlark
without any of the bazel buildin symbols.
This is to match bazel's behavior, and it doesn't make sense for
scl files to load bzl files.
We should change all the release config bzl files to scl, and then
also make it so that when using executionModeScl you can only load
scl files.
Test: go test
Change-Id: I196bcf3a4548118791ed1d47c2d37e46a1ef86c4
diff --git a/tools/rbcrun/host_test.go b/tools/rbcrun/host_test.go
index 10ce55e..468a620 100644
--- a/tools/rbcrun/host_test.go
+++ b/tools/rbcrun/host_test.go
@@ -19,6 +19,7 @@
"os"
"path/filepath"
"runtime"
+ "strings"
"testing"
"go.starlark.net/resolve"
@@ -126,7 +127,7 @@
t.Fatal(err)
}
thread.SetLocal(allowExternalEntrypointKey, false)
- thread.SetLocal(callerDirKey, dir)
+ thread.SetLocal(callingFileKey, "testdata/load.star")
thread.SetLocal(executionModeKey, ExecutionModeRbc)
if _, err := starlark.ExecFile(thread, "testdata/load.star", nil, rbcBuiltins); err != nil {
if err, ok := err.(*starlark.EvalError); ok {
@@ -136,6 +137,55 @@
}
}
+func TestBzlLoadsScl(t *testing.T) {
+ moduleCache = make(map[string]*modentry)
+ dir := dataDir()
+ if err := os.Chdir(filepath.Dir(dir)); err != nil {
+ t.Fatal(err)
+ }
+ vars, _, err := Run("testdata/bzl_loads_scl.bzl", nil, ExecutionModeScl, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if val, ok := vars["foo"]; !ok {
+ t.Fatalf("Failed to load foo variable")
+ } else if val.(starlark.String) != "bar" {
+ t.Fatalf("Expected \"bar\", got %q", val)
+ }
+}
+
+func TestNonEntrypointBzlLoadsScl(t *testing.T) {
+ moduleCache = make(map[string]*modentry)
+ dir := dataDir()
+ if err := os.Chdir(filepath.Dir(dir)); err != nil {
+ t.Fatal(err)
+ }
+ vars, _, err := Run("testdata/bzl_loads_scl_2.bzl", nil, ExecutionModeScl, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if val, ok := vars["foo"]; !ok {
+ t.Fatalf("Failed to load foo variable")
+ } else if val.(starlark.String) != "bar" {
+ t.Fatalf("Expected \"bar\", got %q", val)
+ }
+}
+
+func TestSclLoadsBzl(t *testing.T) {
+ moduleCache = make(map[string]*modentry)
+ dir := dataDir()
+ if err := os.Chdir(filepath.Dir(dir)); err != nil {
+ t.Fatal(err)
+ }
+ _, _, err := Run("testdata/scl_incorrectly_loads_bzl.scl", nil, ExecutionModeScl, false)
+ if err == nil {
+ t.Fatal("Expected failure")
+ }
+ if !strings.Contains(err.Error(), ".scl files can only load other .scl files") {
+ t.Fatalf("Expected error to contain \".scl files can only load other .scl files\": %q", err.Error())
+ }
+}
+
func TestShell(t *testing.T) {
exerciseStarlarkTestFile(t, "testdata/shell.star")
}