Skip to content

Commit 9ec1a7a

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Correct abspath implementation"
2 parents 0339142 + 426c744 commit 9ec1a7a

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
@@ -405,12 +405,26 @@ def _soong_config_get(g, nsname, var):
405405
"""Gets to the value of the variable in the namespace."""
406406
return g.get(_soong_config_namespaces_key, {}).get(nsname, {}).get(var, None)
407407

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

415429

416430
def _addprefix(prefix, string_or_list):

tests/run.rbc

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

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

0 commit comments

Comments
 (0)