diff --git a/core/product_config.rbc b/core/product_config.rbc index 018932366e..d95837db55 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -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)) @@ -856,8 +855,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, diff --git a/tools/rbcrun/host.go b/tools/rbcrun/host.go index c6e89f02c8..32afa458b9 100644 --- a/tools/rbcrun/host.go +++ b/tools/rbcrun/host.go @@ -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) diff --git a/tools/rbcrun/testdata/file_ops.star b/tools/rbcrun/testdata/file_ops.star index 50e39bfa15..2ee78fcc7e 100644 --- a/tools/rbcrun/testdata/file_ops.star +++ b/tools/rbcrun/testdata/file_ops.star @@ -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) diff --git a/tools/rbcrun/testdata/module1.star b/tools/rbcrun/testdata/module1.star index 913fb7d7cb..be04f75b04 100644 --- a/tools/rbcrun/testdata/module1.star +++ b/tools/rbcrun/testdata/module1.star @@ -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"