Merge "Sort rblf_wildcard results and remove file existence functions"
This commit is contained in:
commit
76413f4c58
4 changed files with 11 additions and 27 deletions
|
@ -536,8 +536,11 @@ def _copy_if_exists(path_pair):
|
|||
"""If from file exists, returns [from:to] pair."""
|
||||
value = path_pair.split(":", 2)
|
||||
|
||||
if value[0].find('*') != -1:
|
||||
fail("copy_if_exists: input file cannot contain *")
|
||||
|
||||
# Check that l[0] exists
|
||||
return [":".join(value)] if rblf_file_exists(value[0]) else []
|
||||
return [":".join(value)] if rblf_wildcard(value[0]) else []
|
||||
|
||||
def _enforce_product_packages_exist(handle, pkg_string_or_list=[]):
|
||||
"""Makes including non-existent modules in PRODUCT_PACKAGES an error."""
|
||||
|
@ -552,10 +555,6 @@ def _add_product_dex_preopt_module_config(handle, modules, config):
|
|||
_setdefault(handle, "PRODUCT_DEX_PREOPT_MODULE_CONFIGS")
|
||||
handle.cfg["PRODUCT_DEX_PREOPT_MODULE_CONFIGS"] += [m + "=" + config for m in modules]
|
||||
|
||||
def _file_wildcard_exists(file_pattern):
|
||||
"""Return True if there are files matching given bash pattern."""
|
||||
return len(rblf_wildcard(file_pattern)) > 0
|
||||
|
||||
def _find_and_copy(pattern, from_dir, to_dir):
|
||||
"""Return a copy list for the files matching the pattern."""
|
||||
return sorted([("%s/%s:%s/%s" % (from_dir, f, to_dir, f))
|
||||
|
@ -859,8 +858,6 @@ rblf = struct(
|
|||
dir = _dir,
|
||||
enforce_product_packages_exist = _enforce_product_packages_exist,
|
||||
expand_wildcard = _expand_wildcard,
|
||||
file_exists = rblf_file_exists,
|
||||
file_wildcard_exists = _file_wildcard_exists,
|
||||
filter = _filter,
|
||||
filter_out = _filter_out,
|
||||
find_and_copy = _find_and_copy,
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"go.starlark.net/starlark"
|
||||
|
@ -111,19 +112,6 @@ func loader(thread *starlark.Thread, module string) (starlark.StringDict, error)
|
|||
return e.globals, e.err
|
||||
}
|
||||
|
||||
// fileExists returns True if file with given name exists.
|
||||
func fileExists(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
|
||||
kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||
var path string
|
||||
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 1, &path); err != nil {
|
||||
return starlark.None, err
|
||||
}
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return starlark.False, nil
|
||||
}
|
||||
return starlark.True, 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,
|
||||
|
@ -150,6 +138,10 @@ func wildcard(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
|
|||
files[i] = strings.TrimPrefix(files[i], prefix)
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
return makeStringList(files), nil
|
||||
}
|
||||
|
||||
|
@ -269,8 +261,6 @@ func setup(env []string) {
|
|||
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
|
||||
"rblf_cli": structFromEnv(env),
|
||||
"rblf_env": structFromEnv(os.Environ()),
|
||||
// To convert makefile's $(wildcard foo)
|
||||
"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 $(shell cmd)
|
||||
|
|
3
tools/rbcrun/testdata/file_ops.star
vendored
3
tools/rbcrun/testdata/file_ops.star
vendored
|
@ -4,9 +4,6 @@ load("assert.star", "assert")
|
|||
|
||||
def test():
|
||||
myname = "file_ops.star"
|
||||
assert.true(rblf_file_exists("."), "./ exists ")
|
||||
assert.true(rblf_file_exists(myname), "the file %s does exist" % myname)
|
||||
assert.true(not rblf_file_exists("no_such_file"), "the file no_such_file does not exist")
|
||||
files = rblf_wildcard("*.star")
|
||||
assert.true(myname in files, "expected %s in %s" % (myname, files))
|
||||
files = rblf_wildcard("*.star", rblf_env.TEST_DATA_DIR)
|
||||
|
|
4
tools/rbcrun/testdata/module1.star
vendored
4
tools/rbcrun/testdata/module1.star
vendored
|
@ -2,6 +2,6 @@
|
|||
load("assert.star", "assert")
|
||||
|
||||
# Make sure that builtins are defined for the loaded module, too
|
||||
assert.true(rblf_file_exists("module1.star"))
|
||||
assert.true(not rblf_file_exists("no_such file"))
|
||||
assert.true(rblf_wildcard("module1.star"))
|
||||
assert.true(not rblf_wildcard("no_such file"))
|
||||
test = "module1"
|
||||
|
|
Loading…
Reference in a new issue