App: Support --topdir-format "relative"
The global --topdir-format option governs how a project's root directory is represented in paths output by various queries. "absolute" means as absolute path, "unaltered" means verbatim as specified via --topdir, make:xyz means replaced by the string $(xyz), for later expansion in a makefile variable.
This commit adds another variant: "relative" yields the shortest possible output format of the output path in question relative to --topdir, with "shortest possible" in this context meaning canonicalized and leading "./" stripped.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
0d18ee8ec1
commit
b35d61311c
1 changed files with 9 additions and 2 deletions
|
|
@ -83,6 +83,8 @@ class App(Base):
|
|||
match fmt:
|
||||
case 'unaltered':
|
||||
return path
|
||||
case 'relative':
|
||||
return os.path.relpath(path)
|
||||
case None | 'absolute':
|
||||
return os.path.abspath(path)
|
||||
case _:
|
||||
|
|
@ -135,6 +137,8 @@ class App(Base):
|
|||
return os.path.abspath(pd)
|
||||
if self.__topdir_fmt == 'unaltered':
|
||||
return pd
|
||||
if self.__topdir_fmt == 'relative':
|
||||
return os.path.relpath(pd, self.__pretty_topdir)
|
||||
if name == self.__top_name:
|
||||
return self.__pretty_topdir
|
||||
raise NotImplementedError(
|
||||
|
|
@ -151,7 +155,10 @@ class App(Base):
|
|||
if os.path.isdir(path):
|
||||
ret = format_pd(name, pd, pretty)
|
||||
if sd and sd[0] != '/':
|
||||
ret += '/'
|
||||
if ret == '.':
|
||||
ret = ''
|
||||
else:
|
||||
ret += '/'
|
||||
ret += sd
|
||||
return ret
|
||||
for ret in search_absdirs:
|
||||
|
|
@ -345,7 +352,7 @@ class App(Base):
|
|||
default = 'absolute',
|
||||
help = (
|
||||
'Output references to topdir as one of "make:<var-name>", '
|
||||
'"unaltered", "absolute". Absolute topdir by default'
|
||||
'"unaltered", "relative", "absolute". Absolute topdir by default'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue