summaryrefslogtreecommitdiff
path: root/piglit
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2014-06-12 11:16:16 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2014-06-16 14:42:20 -0700
commit4cf0576ab1a7cb564b14979be6cb2b75d242ec82 (patch)
treebb1fbbadcaf016e43045cc64791bcc52d72b7d3c /piglit
parent72df4e6103c84af543dd22a4d52f0b80c487184e (diff)
piglit (executable): Make PIGLIT_SOURCE_DIR detection more robust
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@gmail.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Diffstat (limited to 'piglit')
-rwxr-xr-xpiglit45
1 files changed, 33 insertions, 12 deletions
diff --git a/piglit b/piglit
index bf53876c3..ea7326831 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