2020-10-26 23:43:21 +01:00
|
|
|
// Copyright 2021 Google LLC
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package rbcrun
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-19 01:32:19 +02:00
|
|
|
"io/fs"
|
2020-10-26 23:43:21 +01:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2022-04-26 21:03:19 +02:00
|
|
|
"sort"
|
2020-10-26 23:43:21 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.starlark.net/starlark"
|
|
|
|
"go.starlark.net/starlarkstruct"
|
|
|
|
)
|
|
|
|
|
2023-05-09 23:56:36 +02:00
|
|
|
type ExecutionMode int
|
|
|
|
const (
|
|
|
|
ExecutionModeRbc ExecutionMode = iota
|
2023-11-07 20:14:58 +01:00
|
|
|
ExecutionModeScl ExecutionMode = iota
|
2023-05-09 23:56:36 +02:00
|
|
|
)
|
2020-10-26 23:43:21 +01:00
|
|
|
|
2023-06-07 01:55:58 +02:00
|
|
|
const allowExternalEntrypointKey = "allowExternalEntrypoint"
|
2023-11-07 20:14:58 +01:00
|
|
|
const callingFileKey = "callingFile"
|
2023-05-09 23:56:36 +02:00
|
|
|
const executionModeKey = "executionMode"
|
2023-06-07 01:55:58 +02:00
|
|
|
const shellKey = "shell"
|
2020-10-26 23:43:21 +01:00
|
|
|
|
|
|
|
type modentry struct {
|
|
|
|
globals starlark.StringDict
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
var moduleCache = make(map[string]*modentry)
|
|
|
|
|
2023-05-09 23:56:36 +02:00
|
|
|
var rbcBuiltins starlark.StringDict = starlark.StringDict{
|
|
|
|
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
|
|
|
|
// To convert find-copy-subdir and product-copy-files-by pattern
|
|
|
|
"rblf_find_files": starlark.NewBuiltin("rblf_find_files", find),
|
|
|
|
// 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),
|
|
|
|
}
|
2020-10-26 23:43:21 +01:00
|
|
|
|
2023-11-07 20:14:58 +01:00
|
|
|
var sclBuiltins starlark.StringDict = starlark.StringDict{
|
2023-05-09 23:56:36 +02:00
|
|
|
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
|
|
|
|
}
|
|
|
|
|
2023-11-09 23:28:34 +01:00
|
|
|
func isSymlink(filepath string) (bool, error) {
|
|
|
|
if info, err := os.Lstat(filepath); err == nil {
|
|
|
|
return info.Mode() & os.ModeSymlink != 0, nil
|
|
|
|
} else {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 23:56:36 +02:00
|
|
|
// Takes a module name (the first argument to the load() function) and returns the path
|
|
|
|
// it's trying to load, stripping out leading //, and handling leading :s.
|
2023-06-07 01:55:58 +02:00
|
|
|
func cleanModuleName(moduleName string, callerDir string, allowExternalPaths bool) (string, error) {
|
2023-05-09 23:56:36 +02:00
|
|
|
if strings.Count(moduleName, ":") > 1 {
|
|
|
|
return "", fmt.Errorf("at most 1 colon must be present in starlark path: %s", moduleName)
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
2023-05-09 23:56:36 +02:00
|
|
|
|
|
|
|
// We don't have full support for external repositories, but at least support skylib's dicts.
|
|
|
|
if moduleName == "@bazel_skylib//lib:dicts.bzl" {
|
|
|
|
return "external/bazel-skylib/lib/dicts.bzl", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
localLoad := false
|
|
|
|
if strings.HasPrefix(moduleName, "@//") {
|
|
|
|
moduleName = moduleName[3:]
|
|
|
|
} else if strings.HasPrefix(moduleName, "//") {
|
|
|
|
moduleName = moduleName[2:]
|
2020-10-26 23:43:21 +01:00
|
|
|
} else if strings.HasPrefix(moduleName, ":") {
|
2023-05-09 23:56:36 +02:00
|
|
|
moduleName = moduleName[1:]
|
|
|
|
localLoad = true
|
2023-06-07 01:55:58 +02:00
|
|
|
} else if !allowExternalPaths {
|
2023-05-09 23:56:36 +02:00
|
|
|
return "", fmt.Errorf("load path must start with // or :")
|
|
|
|
}
|
|
|
|
|
|
|
|
if ix := strings.LastIndex(moduleName, ":"); ix >= 0 {
|
|
|
|
moduleName = moduleName[:ix] + string(os.PathSeparator) + moduleName[ix+1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
if filepath.Clean(moduleName) != moduleName {
|
|
|
|
return "", fmt.Errorf("load path must be clean, found: %s, expected: %s", moduleName, filepath.Clean(moduleName))
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
2023-06-07 01:55:58 +02:00
|
|
|
if !allowExternalPaths {
|
|
|
|
if strings.HasPrefix(moduleName, "../") {
|
|
|
|
return "", fmt.Errorf("load path must not start with ../: %s", moduleName)
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(moduleName, "/") {
|
|
|
|
return "", fmt.Errorf("load path starts with /, use // for a absolute path: %s", moduleName)
|
|
|
|
}
|
2023-05-09 23:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if localLoad {
|
|
|
|
return filepath.Join(callerDir, moduleName), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return moduleName, nil
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// loader implements load statement. The format of the loaded module URI is
|
|
|
|
// [//path]:base[|symbol]
|
|
|
|
// The file path is $ROOT/path/base if path is present, <caller_dir>/base otherwise.
|
|
|
|
// The presence of `|symbol` indicates that the loader should return a single 'symbol'
|
|
|
|
// bound to None if file is missing.
|
|
|
|
func loader(thread *starlark.Thread, module string) (starlark.StringDict, error) {
|
2023-05-09 23:56:36 +02:00
|
|
|
mode := thread.Local(executionModeKey).(ExecutionMode)
|
2023-06-07 01:55:58 +02:00
|
|
|
allowExternalEntrypoint := thread.Local(allowExternalEntrypointKey).(bool)
|
2020-10-26 23:43:21 +01:00
|
|
|
var defaultSymbol string
|
2023-05-09 23:56:36 +02:00
|
|
|
mustLoad := true
|
|
|
|
if mode == ExecutionModeRbc {
|
|
|
|
pipePos := strings.LastIndex(module, "|")
|
2023-06-07 01:55:58 +02:00
|
|
|
if pipePos >= 0 {
|
|
|
|
mustLoad = false
|
2023-05-09 23:56:36 +02:00
|
|
|
defaultSymbol = module[pipePos+1:]
|
|
|
|
module = module[:pipePos]
|
|
|
|
}
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
2023-11-07 20:14:58 +01:00
|
|
|
callingFile := thread.Local(callingFileKey).(string)
|
|
|
|
modulePath, err := cleanModuleName(module, filepath.Dir(callingFile), allowExternalEntrypoint)
|
2020-10-26 23:43:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
e, ok := moduleCache[modulePath]
|
|
|
|
if e == nil {
|
|
|
|
if ok {
|
|
|
|
return nil, fmt.Errorf("cycle in load graph")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a placeholder to indicate "load in progress".
|
|
|
|
moduleCache[modulePath] = nil
|
|
|
|
|
|
|
|
// Decide if we should load.
|
|
|
|
if !mustLoad {
|
|
|
|
if _, err := os.Stat(modulePath); err == nil {
|
|
|
|
mustLoad = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load or return default
|
|
|
|
if mustLoad {
|
2023-11-07 20:14:58 +01:00
|
|
|
if strings.HasSuffix(callingFile, ".scl") && !strings.HasSuffix(modulePath, ".scl") {
|
|
|
|
return nil, fmt.Errorf(".scl files can only load other .scl files: %q loads %q", callingFile, modulePath)
|
|
|
|
}
|
|
|
|
// Switch into scl mode from here on
|
|
|
|
if strings.HasSuffix(modulePath, ".scl") {
|
|
|
|
mode = ExecutionModeScl
|
|
|
|
}
|
2023-11-09 23:28:34 +01:00
|
|
|
|
|
|
|
if sym, err := isSymlink(modulePath); sym && err == nil {
|
|
|
|
return nil, fmt.Errorf("symlinks to starlark files are not allowed. Instead, load the target file and re-export its symbols: %s", modulePath)
|
|
|
|
} else if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:43:21 +01:00
|
|
|
childThread := &starlark.Thread{Name: "exec " + module, Load: thread.Load}
|
|
|
|
// Cheating for the sake of testing:
|
|
|
|
// propagate starlarktest's Reporter key, otherwise testing
|
|
|
|
// the load function may cause panic in starlarktest code.
|
|
|
|
const testReporterKey = "Reporter"
|
|
|
|
if v := thread.Local(testReporterKey); v != nil {
|
|
|
|
childThread.SetLocal(testReporterKey, v)
|
|
|
|
}
|
|
|
|
|
2023-06-07 01:55:58 +02:00
|
|
|
// Only the entrypoint starlark file allows external loads.
|
|
|
|
childThread.SetLocal(allowExternalEntrypointKey, false)
|
2023-11-07 20:14:58 +01:00
|
|
|
childThread.SetLocal(callingFileKey, modulePath)
|
2023-05-09 23:56:36 +02:00
|
|
|
childThread.SetLocal(executionModeKey, mode)
|
2023-06-07 01:55:58 +02:00
|
|
|
childThread.SetLocal(shellKey, thread.Local(shellKey))
|
2023-05-09 23:56:36 +02:00
|
|
|
if mode == ExecutionModeRbc {
|
|
|
|
globals, err := starlark.ExecFile(childThread, modulePath, nil, rbcBuiltins)
|
|
|
|
e = &modentry{globals, err}
|
2023-11-07 20:14:58 +01:00
|
|
|
} else if mode == ExecutionModeScl {
|
|
|
|
globals, err := starlark.ExecFile(childThread, modulePath, nil, sclBuiltins)
|
2023-05-09 23:56:36 +02:00
|
|
|
e = &modentry{globals, err}
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("unknown executionMode %d", mode)
|
|
|
|
}
|
2020-10-26 23:43:21 +01:00
|
|
|
} else {
|
|
|
|
e = &modentry{starlark.StringDict{defaultSymbol: starlark.None}, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the cache.
|
|
|
|
moduleCache[modulePath] = e
|
|
|
|
}
|
|
|
|
return e.globals, e.err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wildcard(pattern, top=None) expands shell's glob pattern. If 'top' is present,
|
|
|
|
// the 'top/pattern' is globbed and then 'top/' prefix is removed.
|
|
|
|
func wildcard(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
|
|
|
|
kwargs []starlark.Tuple) (starlark.Value, error) {
|
|
|
|
var pattern string
|
|
|
|
var top string
|
|
|
|
|
|
|
|
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 1, &pattern, &top); err != nil {
|
|
|
|
return starlark.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var files []string
|
|
|
|
var err error
|
|
|
|
if top == "" {
|
|
|
|
if files, err = filepath.Glob(pattern); err != nil {
|
|
|
|
return starlark.None, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prefix := top + string(filepath.Separator)
|
|
|
|
if files, err = filepath.Glob(prefix + pattern); err != nil {
|
|
|
|
return starlark.None, err
|
|
|
|
}
|
|
|
|
for i := range files {
|
|
|
|
files[i] = strings.TrimPrefix(files[i], prefix)
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 21:03:19 +02:00
|
|
|
// Kati uses glob(3) with no flags, which means it's sorted
|
|
|
|
// because GLOB_NOSORT is not passed. Go's glob is not
|
|
|
|
// guaranteed to sort the results.
|
|
|
|
sort.Strings(files)
|
2020-10-26 23:43:21 +01:00
|
|
|
return makeStringList(files), nil
|
|
|
|
}
|
|
|
|
|
2021-08-19 01:32:19 +02:00
|
|
|
// find(top, pattern, only_files = 0) returns all the paths under 'top'
|
|
|
|
// whose basename matches 'pattern' (which is a shell's glob pattern).
|
|
|
|
// If 'only_files' is non-zero, only the paths to the regular files are
|
|
|
|
// returned. The returned paths are relative to 'top'.
|
|
|
|
func find(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
|
|
|
|
kwargs []starlark.Tuple) (starlark.Value, error) {
|
|
|
|
var top, pattern string
|
|
|
|
var onlyFiles int
|
|
|
|
if err := starlark.UnpackArgs(b.Name(), args, kwargs,
|
|
|
|
"top", &top, "pattern", &pattern, "only_files?", &onlyFiles); err != nil {
|
|
|
|
return starlark.None, err
|
|
|
|
}
|
|
|
|
top = filepath.Clean(top)
|
|
|
|
pattern = filepath.Clean(pattern)
|
|
|
|
// Go's filepath.Walk is slow, consider using OS's find
|
|
|
|
var res []string
|
|
|
|
err := filepath.WalkDir(top, func(path string, d fs.DirEntry, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
if d != nil && d.IsDir() {
|
|
|
|
return fs.SkipDir
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
relPath := strings.TrimPrefix(path, top)
|
|
|
|
if len(relPath) > 0 && relPath[0] == os.PathSeparator {
|
|
|
|
relPath = relPath[1:]
|
|
|
|
}
|
|
|
|
// Do not return top-level dir
|
|
|
|
if len(relPath) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if matched, err := filepath.Match(pattern, d.Name()); err == nil && matched && (onlyFiles == 0 || d.Type().IsRegular()) {
|
|
|
|
res = append(res, relPath)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return makeStringList(res), err
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:43:21 +01:00
|
|
|
// shell(command) runs OS shell with given command and returns back
|
|
|
|
// its output the same way as Make's $(shell ) function. The end-of-lines
|
|
|
|
// ("\n" or "\r\n") are replaced with " " in the result, and the trailing
|
|
|
|
// end-of-line is removed.
|
2023-05-09 23:56:36 +02:00
|
|
|
func shell(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
|
2020-10-26 23:43:21 +01:00
|
|
|
kwargs []starlark.Tuple) (starlark.Value, error) {
|
|
|
|
var command string
|
|
|
|
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 1, &command); err != nil {
|
|
|
|
return starlark.None, err
|
|
|
|
}
|
2023-05-09 23:56:36 +02:00
|
|
|
shellPath := thread.Local(shellKey).(string)
|
2020-10-26 23:43:21 +01:00
|
|
|
if shellPath == "" {
|
|
|
|
return starlark.None,
|
2021-04-02 00:51:56 +02:00
|
|
|
fmt.Errorf("cannot run shell, /bin/sh is missing (running on Windows?)")
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
|
|
|
cmd := exec.Command(shellPath, "-c", command)
|
|
|
|
// We ignore command's status
|
|
|
|
bytes, _ := cmd.Output()
|
|
|
|
output := string(bytes)
|
|
|
|
if strings.HasSuffix(output, "\n") {
|
|
|
|
output = strings.TrimSuffix(output, "\n")
|
|
|
|
} else {
|
|
|
|
output = strings.TrimSuffix(output, "\r\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
return starlark.String(
|
|
|
|
strings.ReplaceAll(
|
|
|
|
strings.ReplaceAll(output, "\r\n", " "),
|
|
|
|
"\n", " ")), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeStringList(items []string) *starlark.List {
|
|
|
|
elems := make([]starlark.Value, len(items))
|
|
|
|
for i, item := range items {
|
|
|
|
elems[i] = starlark.String(item)
|
|
|
|
}
|
|
|
|
return starlark.NewList(elems)
|
|
|
|
}
|
|
|
|
|
2021-09-24 17:25:17 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:43:21 +01:00
|
|
|
// Parses, resolves, and executes a Starlark file.
|
|
|
|
// filename and src parameters are as for starlark.ExecFile:
|
|
|
|
// * filename is the name of the file to execute,
|
|
|
|
// and the name that appears in error messages;
|
|
|
|
// * 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)
|
2023-05-09 23:56:36 +02:00
|
|
|
// Returns the top-level starlark variables, the list of starlark files loaded, and an error
|
2023-06-07 01:55:58 +02:00
|
|
|
func Run(filename string, src interface{}, mode ExecutionMode, allowExternalEntrypoint bool) (starlark.StringDict, []string, error) {
|
2023-05-09 23:56:36 +02:00
|
|
|
// NOTE(asmundak): OS-specific. Behave similar to Linux `system` call,
|
|
|
|
// which always uses /bin/sh to run the command
|
|
|
|
shellPath := "/bin/sh"
|
|
|
|
if _, err := os.Stat(shellPath); err != nil {
|
|
|
|
shellPath = ""
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:43:21 +01:00
|
|
|
mainThread := &starlark.Thread{
|
|
|
|
Name: "main",
|
2023-05-09 23:56:36 +02:00
|
|
|
Print: func(_ *starlark.Thread, msg string) {
|
|
|
|
if mode == ExecutionModeRbc {
|
|
|
|
// In rbc mode, rblf_log is used to print to stderr
|
|
|
|
fmt.Println(msg)
|
2023-11-07 20:14:58 +01:00
|
|
|
} else if mode == ExecutionModeScl {
|
2023-05-09 23:56:36 +02:00
|
|
|
fmt.Fprintln(os.Stderr, msg)
|
|
|
|
}
|
|
|
|
},
|
2020-10-26 23:43:21 +01:00
|
|
|
Load: loader,
|
|
|
|
}
|
2023-05-09 23:56:36 +02:00
|
|
|
filename, err := filepath.Abs(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if wd, err := os.Getwd(); err == nil {
|
|
|
|
filename, err = filepath.Rel(wd, filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2023-06-07 01:55:58 +02:00
|
|
|
if !allowExternalEntrypoint && strings.HasPrefix(filename, "../") {
|
2023-05-09 23:56:36 +02:00
|
|
|
return nil, nil, fmt.Errorf("path could not be made relative to workspace root: %s", filename)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return nil, nil, err
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|
2023-05-09 23:56:36 +02:00
|
|
|
|
2023-11-09 23:28:34 +01:00
|
|
|
if sym, err := isSymlink(filename); sym && err == nil {
|
|
|
|
return nil, nil, fmt.Errorf("symlinks to starlark files are not allowed. Instead, load the target file and re-export its symbols: %s", filename)
|
|
|
|
} else if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 20:21:08 +01:00
|
|
|
if mode == ExecutionModeScl && !strings.HasSuffix(filename, ".scl") {
|
|
|
|
return nil, nil, fmt.Errorf("filename must end in .scl: %s", filename)
|
|
|
|
}
|
|
|
|
|
2023-05-09 23:56:36 +02:00
|
|
|
// Add top-level file to cache for cycle detection purposes
|
|
|
|
moduleCache[filename] = nil
|
|
|
|
|
|
|
|
var results starlark.StringDict
|
2023-06-07 01:55:58 +02:00
|
|
|
mainThread.SetLocal(allowExternalEntrypointKey, allowExternalEntrypoint)
|
2023-11-07 20:14:58 +01:00
|
|
|
mainThread.SetLocal(callingFileKey, filename)
|
2023-05-09 23:56:36 +02:00
|
|
|
mainThread.SetLocal(executionModeKey, mode)
|
2023-06-07 01:55:58 +02:00
|
|
|
mainThread.SetLocal(shellKey, shellPath)
|
2023-05-09 23:56:36 +02:00
|
|
|
if mode == ExecutionModeRbc {
|
|
|
|
results, err = starlark.ExecFile(mainThread, filename, src, rbcBuiltins)
|
2023-11-07 20:14:58 +01:00
|
|
|
} else if mode == ExecutionModeScl {
|
|
|
|
results, err = starlark.ExecFile(mainThread, filename, src, sclBuiltins)
|
2023-05-09 23:56:36 +02:00
|
|
|
} else {
|
|
|
|
return results, nil, fmt.Errorf("unknown executionMode %d", mode)
|
|
|
|
}
|
|
|
|
loadedStarlarkFiles := make([]string, 0, len(moduleCache))
|
|
|
|
for file := range moduleCache {
|
|
|
|
loadedStarlarkFiles = append(loadedStarlarkFiles, file)
|
|
|
|
}
|
|
|
|
sort.Strings(loadedStarlarkFiles)
|
|
|
|
|
|
|
|
return results, loadedStarlarkFiles, err
|
2020-10-26 23:43:21 +01:00
|
|
|
}
|