buildtools: remove assumption about current work dir

Message ID 20230614144728.481566-1-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series buildtools: remove assumption about current work dir |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch-unit-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Bruce Richardson June 14, 2023, 2:47 p.m. UTC
  According to meson documentation, we should not make any assumptions as
to what directory a script is called from[1]. The use of "relpath" when
processing the output of directory globbing is therefore unsafe, as it
was stripping off paths relative to the current directory - which just
happened to be the same as the root directory we were processing.

To improve safety, and support meson clones (like muon)  which
don't always run things from the currently processed path, we need to
explicitly specify that the start parameter for relpath() should be
"root" value.

[1] https://mesonbuild.com/Reference-manual_functions.html#run_command

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 buildtools/list-dir-globs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Tyler Retzlaff June 15, 2023, 8:24 p.m. UTC | #1
On Wed, Jun 14, 2023 at 03:47:28PM +0100, Bruce Richardson wrote:
> According to meson documentation, we should not make any assumptions as
> to what directory a script is called from[1]. The use of "relpath" when
> processing the output of directory globbing is therefore unsafe, as it
> was stripping off paths relative to the current directory - which just
> happened to be the same as the root directory we were processing.
> 
> To improve safety, and support meson clones (like muon)  which
> don't always run things from the currently processed path, we need to
> explicitly specify that the start parameter for relpath() should be
> "root" value.
> 
> [1] https://mesonbuild.com/Reference-manual_functions.html#run_command
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Thomas Monjalon June 27, 2023, 1:07 p.m. UTC | #2
15/06/2023 22:24, Tyler Retzlaff:
> On Wed, Jun 14, 2023 at 03:47:28PM +0100, Bruce Richardson wrote:
> > According to meson documentation, we should not make any assumptions as
> > to what directory a script is called from[1]. The use of "relpath" when
> > processing the output of directory globbing is therefore unsafe, as it
> > was stripping off paths relative to the current directory - which just
> > happened to be the same as the root directory we were processing.
> > 
> > To improve safety, and support meson clones (like muon)  which
> > don't always run things from the currently processed path, we need to
> > explicitly specify that the start parameter for relpath() should be
> > "root" value.
> > 
> > [1] https://mesonbuild.com/Reference-manual_functions.html#run_command
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
> Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Applied, thanks.
  

Patch

diff --git a/buildtools/list-dir-globs.py b/buildtools/list-dir-globs.py
index d824360d39..fb8619db64 100755
--- a/buildtools/list-dir-globs.py
+++ b/buildtools/list-dir-globs.py
@@ -17,4 +17,4 @@ 
     if path:
         for p in iglob(os.path.join(root, path)):
             if os.path.isdir(p):
-                print(os.path.relpath(p).replace('\\', '/'))
+                print(os.path.relpath(p, start=root).replace('\\', '/'))