From 426c7441b0ce4c5d04149074328af53e30515f7f Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 19 Apr 2022 11:17:28 -0700 Subject: [PATCH] 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 --- core/product_config.rbc | 24 +++++++++++++++++++----- tests/run.rbc | 8 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/core/product_config.rbc b/core/product_config.rbc index 928cc557c0..226c488773 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -400,12 +400,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): diff --git a/tests/run.rbc b/tests/run.rbc index 56ba39413b..454562d3f9 100644 --- a/tests/run.rbc +++ b/tests/run.rbc @@ -72,6 +72,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")