[Piglit] [PATCH] piglit (executable): Make PIGLIT_SOURCE_DIR detection more robust

Jose Fonseca jfonseca at vmware.com
Fri Jun 13 09:13:55 PDT 2014


Looks OK to me FWIW.

Jose

----- Original Message -----
> The initial implementation I committed was a bit hackish and I knew it
> at the time, but it seemed to work for all the cases that I tested.
> However, there were corner cases. The biggest of these cases is problems
> running out of tree with piglit built in tree.
> ex: src/piglit/piglit run ...
> 
> This patch makes the handling more robust by explicitly searching for
> three distinct cases:
> 1) piglit is run from the source dir, built in the source dir
> 2) piglit is run from outside the source dir, built in the source dir
> 3) piglit has been installed out of tree
> 
> I have tested all three of these cases, and case 3 if piglit is
> installed as piglit.py.
> 
> Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> ---
>  piglit | 45 +++++++++++++++++++++++++++++++++------------
>  1 file changed, 33 insertions(+), 12 deletions(-)
> 
> diff --git a/piglit b/piglit
> index bf53876..ea73268 100755
> --- a/piglit
> +++ b/piglit
> @@ -36,18 +36,39 @@ import os.path as path
>  import sys
>  import argparse
>  
> -# If running in the source directory there will be a HACKING file, don't
> -# muck with things, if not we need to screw with the python path
> -if not path.exists('HACKING'):
> -    _binpath, _bin = path.split(__file__)
> -    _binname, _binext = path.splitext(_bin)
> -    if _binext == '.py':
> -        # Drop .py extension (used on Windows)
> -        _bin = _binname
> -    _libdir = path.abspath(path.join(_binpath, '..', 'lib', _bin))
> -    sys.path.append(_libdir)
> -    if 'PIGLIT_SOURCE_DIR' not in os.environ:
> -        os.environ['PIGLIT_SOURCE_DIR'] = _libdir
> +# Setting PIGLIT_SOURCE_DIR (and by extension sys.path) is actually pretty
> +# complicated, since there are three seperate uses we need to detect:
> +# 1) piglit is being run in the source directory, built in tree
> +# 2) piglit is being run from the source directory outside of it, built in
> tree
> +# 3) piglit has been built out of tree and installed, and is being run in or
> +#    out of the install directory
> +
> +# It is critical that this block be run before importing anything from
> +# framework (as there is no gaurantee that framework will be in python's
> path
> +# before this blck is run)
> +
> +# Case 1
> +if path.exists('framework/exectest.py'):
> +    os.environ['PIGLIT_SOURCE_DIR'] = path.abspath(path.curdir)
> +else:
> +    dirpath = path.dirname(path.abspath(__file__))
> +    # Case 2
> +    if path.exists(path.join(dirpath, 'framework/exectest.py')):
> +        os.environ['PIGLIT_SOURCE_DIR'] = dirpath
> +        sys.path.append(dirpath)
> +    # Case 3
> +    else:
> +        # In the case of windows piglit is called
> +        # piglit${the_date_of_install}.py, and the .py needs to be thrown
> away
> +        piglit = path.splitext(path.basename(__file__))[0]
> +
> +        # In the install case we have another problem, one could have
> multiple
> +        # piglits installed as piglit${the_date_of_install}, and we need to
> +        # detect that.
> +        install_path = path.abspath(path.join(dirpath, '..', 'lib', piglit))
> +
> +        os.environ['PIGLIT_SOURCE_DIR'] = install_path
> +        sys.path.append(install_path)
>  
>  import framework.programs.run as run
>  import framework.programs.summary as summary
> --
> 2.0.0
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/piglit&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=zJxOIRUrCdcP%2FBZM0lNB9GnvQKxHu2n%2FwrSpPQ0FwYc%3D%0A&s=0b19f1e796fc7254394b0d7aba19878053ba97c63bdc77aff1211290b4de8477
> 


More information about the Piglit mailing list