On Thu, Jul 02, 2026 at 04:01:21PM +0200, Gabriele Monaco wrote:
> On Thu, 2026-07-02 at 15:53 +0200, Nam Cao wrote:
> > Gabriele Monaco <[email protected]> writes:
> > > The RVGenerator class can find the RV directory (kernel/trace/rv) in the
> > > kernel tree to do some auto patching. This works by assuming PWD is
> > > either the kernel tree or tools/verification, which isn't always the
> > > case (e.g. when running from selftests).
> > > 
> > > Make discovery more robust by relying on the absolute path of the
> > > current script and traversing backwards the right number of times.
> > > This should work from any location if rvgen is in the kernel tree.
> > 
> > Agree.
> > 
> > > +        # find the kernel tree root relative to this file's location
> > > +        current_dir = os.path.dirname(os.path.abspath(__file__))
> > > +        kernel_root = os.path.abspath(os.path.join(current_dir,
> > > "../../../.."))
> > 
> > 
> > The  "../../../.." makes me sad.
> > 
> > We can find the git project root instead. For example:
> > 
> > def getGitRoot():
> >     return subprocess.Popen(['git', 'rev-parse', '--show-toplevel'],
> > stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')
> > 
> > (stolen from
> > https://stackoverflow.com/questions/22081209/find-the-root-of-the-git-repository-where-the-file-lives
> > )
> > 
> > But that's not important, up to you.
> 
> Mmh good point, but what if we're running from a tarball?
> 
> I could still fall back to something that uses directory parents (maybe
> something arguably nicer like
> 
>   os.path.join(current_dir, *([".."] * 4))
> 
> But that may not be more readable..

current_dir = pathlib.Path(__file__).abspath()
kernel_root = current_dir.parents[4]

pathlib is generally nicer than os.path.


Thomas

Reply via email to