Skip to content

Commit 426c744

Browse files
committed
Correct abspath implementation
realpath doesn't return a path if the file doesn't exist, but $(abspath) in make does. Bug: 229132189 Test: ./out/rbcrun ./build/make/tests/run.rbc Change-Id: Ief7f634024cc52a9e8c5e478666b15512512f0d8
1 parent a9aa002 commit 426c744

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

core/product_config.rbc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,26 @@ def _soong_config_get(g, nsname, var):
400400
"""Gets to the value of the variable in the namespace."""
401401
return g.get(_soong_config_namespaces_key, {}).get(nsname, {}).get(var, None)
402402

403-
404-
def _abspath(path):
403+
def _abspath(paths):
405404
"""Provided for compatibility, to be removed later."""
406-
if type(path) == "list":
407-
path = " ".join(path)
408-
return rblf_shell("realpath "+path)
405+
cwd = rblf_shell('pwd')
406+
results = []
407+
for path in __words(paths):
408+
if path[0] != "/":
409+
path = cwd + "/" + path
410+
411+
resultparts = []
412+
for part in path.split('/'):
413+
if part == "." or part == "":
414+
continue
415+
elif part == "..":
416+
if resultparts:
417+
resultparts.pop()
418+
else:
419+
resultparts.append(part)
420+
results.append("/" + "/".join(resultparts))
421+
422+
return " ".join(results)
409423

410424

411425
def _addprefix(prefix, string_or_list):

tests/run.rbc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
7272
assert_eq("", rblf.notdir("/"))
7373
assert_eq("", rblf.notdir(""))
7474

75+
cwd = rblf_shell('pwd')
76+
assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar"))
77+
assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar"))
78+
assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//"))
79+
assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz"))
80+
assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz"))
81+
assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz"))
82+
7583
assert_eq(
7684
["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
7785
rblf.expand_wildcard("build/make/tests/board*.rbc")

0 commit comments

Comments
 (0)