Remove regex functionality from rbcrun

As a first step to making .rbc files compatible with bazel,
remove regex support since bazel doesn't have it.

Fixes: 227384703
Test: ./out/rbcrun ./build/make/tests/run.rbc
Change-Id: I8b946c20cc42897a47a5516a167732f4e16b6158
This commit is contained in:
Cole Faust
2022-03-29 15:48:45 -07:00
parent d3a9957616
commit 62878a2cef
5 changed files with 40 additions and 57 deletions

View File

@@ -20,7 +20,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"go.starlark.net/starlark"
@@ -125,23 +124,6 @@ func fileExists(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
return starlark.True, nil
}
// regexMatch(pattern, s) returns True if s matches pattern (a regex)
func regexMatch(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
kwargs []starlark.Tuple) (starlark.Value, error) {
var pattern, s string
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 2, &pattern, &s); err != nil {
return starlark.None, err
}
match, err := regexp.MatchString(pattern, s)
if err != nil {
return starlark.None, err
}
if match {
return starlark.True, nil
}
return starlark.False, nil
}
// 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,
@@ -291,8 +273,6 @@ func setup(env []string) {
"rblf_file_exists": starlark.NewBuiltin("rblf_file_exists", fileExists),
// To convert find-copy-subdir and product-copy-files-by pattern
"rblf_find_files": starlark.NewBuiltin("rblf_find_files", find),
// To convert makefile's $(filter ...)/$(filter-out)
"rblf_regex": starlark.NewBuiltin("rblf_regex", regexMatch),
// To convert makefile's $(shell cmd)
"rblf_shell": starlark.NewBuiltin("rblf_shell", shell),
// Output to stderr

View File

@@ -147,10 +147,6 @@ func TestLoad(t *testing.T) {
}
}
func TestRegex(t *testing.T) {
exerciseStarlarkTestFile(t, "testdata/regex.star")
}
func TestShell(t *testing.T) {
if err := os.Setenv("TEST_DATA_DIR", dataDir()); err != nil {
t.Fatal(err)

View File

@@ -1,13 +0,0 @@
# Tests rblf_regex
load("assert.star", "assert")
def test():
pattern = "^(foo.*bar|abc.*d|1.*)$"
for w in ("foobar", "fooxbar", "abcxd", "123"):
assert.true(rblf_regex(pattern, w), "%s should match %s" % (w, pattern))
for w in ("afoobar", "abcde"):
assert.true(not rblf_regex(pattern, w), "%s should not match %s" % (w, pattern))
test()