diff options
-rw-r--r-- | meta/lib/oe/path.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index 082972457b..c8d8ad05b9 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py | |||
@@ -320,3 +320,24 @@ def which_wild(pathname, path=None, mode=os.F_OK, *, reverse=False, candidates=F | |||
320 | 320 | ||
321 | return files | 321 | return files |
322 | 322 | ||
323 | def canonicalize(paths, sep=','): | ||
324 | """Given a string with paths (separated by commas by default), expand | ||
325 | each path using os.path.realpath() and return the resulting paths as a | ||
326 | string (separated using the same separator a the original string). | ||
327 | """ | ||
328 | # Ignore paths containing "$" as they are assumed to be unexpanded bitbake | ||
329 | # variables. Normally they would be ignored, e.g., when passing the paths | ||
330 | # through the shell they would expand to empty strings. However, when they | ||
331 | # are passed through os.path.realpath(), it will cause them to be prefixed | ||
332 | # with the absolute path to the current directory and thus not be empty | ||
333 | # anymore. | ||
334 | # | ||
335 | # Also maintain trailing slashes, as the paths may actually be used as | ||
336 | # prefixes in sting compares later on, where the slashes then are important. | ||
337 | canonical_paths = [] | ||
338 | for path in (paths or '').split(sep): | ||
339 | if '$' not in path: | ||
340 | trailing_slash = path.endswith('/') and '/' or '' | ||
341 | canonical_paths.append(os.path.realpath(path) + trailing_slash) | ||
342 | |||
343 | return sep.join(canonical_paths) | ||