Skip to content

Commit

Permalink
Merge "Correct abspath implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Apr 20, 2022
2 parents 0339142 + 426c744 commit 9ec1a7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
24 changes: 19 additions & 5 deletions core/product_config.rbc
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,26 @@ def _soong_config_get(g, nsname, var):
"""Gets to the value of the variable in the namespace."""
return g.get(_soong_config_namespaces_key, {}).get(nsname, {}).get(var, None)


def _abspath(path):
def _abspath(paths):
"""Provided for compatibility, to be removed later."""
if type(path) == "list":
path = " ".join(path)
return rblf_shell("realpath "+path)
cwd = rblf_shell('pwd')
results = []
for path in __words(paths):
if path[0] != "/":
path = cwd + "/" + path

resultparts = []
for part in path.split('/'):
if part == "." or part == "":
continue
elif part == "..":
if resultparts:
resultparts.pop()
else:
resultparts.append(part)
results.append("/" + "/".join(resultparts))

return " ".join(results)


def _addprefix(prefix, string_or_list):
Expand Down
8 changes: 8 additions & 0 deletions tests/run.rbc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
assert_eq("", rblf.notdir("/"))
assert_eq("", rblf.notdir(""))

cwd = rblf_shell('pwd')
assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar"))
assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar"))
assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//"))
assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz"))
assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz"))
assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz"))

assert_eq(
["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
rblf.expand_wildcard("build/make/tests/board*.rbc")
Expand Down

0 comments on commit 9ec1a7a

Please sign in to comment.