From 276ee5387182ca865c00500013877b6cc2d5c77e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 2 Mar 2012 11:50:44 +0000 Subject: [PATCH 1/1] Use path to apitrace executable instead. --- CMakeLists.txt | 7 +-- README.markdown | 14 ++++-- apps/CMakeLists.txt | 2 +- driver.py | 102 ++++++++++++++++++++++++++------------------ 4 files changed, 72 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cd54f0..cd7f9d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,12 +64,7 @@ if (MSVC) add_definitions (-wd4244) # conversion' conversion from 'type1' to 'type2', possible loss of data endif () -if (NOT APITRACE_BINARY_DIR) - set (APITRACE_BINARY_DIR "${CMAKE_BINARY_DIR}/.." CACHE PATH "apitrace build directory") -endif () -if (NOT EXISTS ${APITRACE_BINARY_DIR}) - message (SEND_ERROR "Invalid APITRACE_BINARY_DIR") -endif () +find_program (APITRACE_EXECUTABLE apitrace DOC "apitrace executable") enable_testing() diff --git a/README.markdown b/README.markdown index 91ff21a..2820428 100644 --- a/README.markdown +++ b/README.markdown @@ -6,10 +6,16 @@ In addition to apitrace requirements, it also requires: * GLEW -To run the test suite do: +To run the test suite do on Unices: - cmake -DAPITRACE_BINARY_DIR=/path/to/apitrace/build/ . + cmake -DAPITRACE_EXECUTABLE=/path/to/apitrace -H. -B./build export CTEST_OUTPUT_ON_FAILURE=1 - make all test + make -C ./build all test -Detailed log will be written to `Testing/Temporary/LastTest.log`. +Or on Windows: + + cmake -G "Visual Studio 10" -H. -B.\build + cmake --build .\build --target ALL_BUILD + cmake --build .\build --target RUN_TESTS + +A detailed log will be written to `Testing/Temporary/LastTest.log`. diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 4d425f6..5736c21 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -14,7 +14,7 @@ function (ADD_APP_TEST) NAME app_${TEST_NAME} COMMAND python ${CMAKE_SOURCE_DIR}/driver.py - --build ${APITRACE_BINARY_DIR} + --apitrace ${APITRACE_EXECUTABLE} --api ${api} --ref-dump ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_REF} -- diff --git a/driver.py b/driver.py index 2eab23c..1d005b6 100755 --- a/driver.py +++ b/driver.py @@ -31,7 +31,6 @@ import optparse import os.path import platform import re -import shutil import subprocess import sys import time @@ -87,26 +86,52 @@ def popen(command, *args, **kwargs): return subprocess.Popen(command, *args, env=env, **kwargs) -def _get_build_path(path): - if options.build is not None: - path = os.path.abspath(os.path.join(options.build, path)) +def which(executable): + dirs = os.environ['PATH'].split(os.path.pathsep) + for dir in dirs: + path = os.path.join(dir, executable) + if os.path.exists(path): + return path + return None + + +def _get_bin_path(): + if os.path.exists(options.apitrace): + apitrace_abspath = os.path.abspath(options.apitrace) + else: + apitrace_abspath = which(options.apitrace) + if apitrace_abspath is None: + sys.stderr.write('error: could not determine the absolute path of\n' % options.apitrace) + sys.exit(1) + return os.path.dirname(apitrace_abspath) + + +def _get_build_program(program): + bin_path = _get_bin_path() + if platform.system() == 'Windows': + program += '.exe' + path = os.path.join(bin_path, program) if not os.path.exists(path): sys.stderr.write('error: %s does not exist\n' % path) sys.exit(1) return path -def _get_build_program(program): - if platform.system() == 'Windows': - program += '.exe' - return _get_build_path(program) - -def _get_source_path(path): - cache = _get_build_path('CMakeCache.txt') - for line in open(cache, 'rt'): - if line.startswith('CMAKE_HOME_DIRECTORY:INTERNAL='): - _, source_root = line.strip().split('=', 1) - return os.path.join(source_root, path) - return None +def _get_scripts_path(): + bin_path = _get_bin_path() + + try_paths = [ + 'scripts', + '../lib/scripts', + '../lib/apitrace/scripts', + ] + + for try_path in try_paths: + path = os.path.join(bin_path, try_path) + if os.path.exists(path): + return os.path.abspath(path) + + sys.stderr.write('error: could not find scripts directory\n') + sys.exit(1) class TraceChecker: @@ -263,36 +288,23 @@ class TestCase: cmd = self.cmd env = os.environ.copy() - system = platform.system() - local_wrapper = None - if system == 'Windows': - wrapper = _get_build_path('wrappers/opengl32.dll') - local_wrapper = os.path.join(os.path.dirname(self.cmd[0]), os.path.basename(wrapper)) - shutil.copy(wrapper, local_wrapper) - env['TRACE_FILE'] = str(self.trace_file) - else: - apitrace = _get_build_program('apitrace') - cmd = [ - apitrace, 'trace', - '--api', self.api_map[self.api], - '--output', self.trace_file, - '--' - ] + cmd + cmd = [ + options.apitrace, 'trace', + '--api', self.api_map[self.api], + '--output', self.trace_file, + '--' + ] + cmd if self.max_frames is not None: env['TRACE_FRAMES'] = str(self.max_frames) - try: - p = popen(cmd, env=env, cwd=self.cwd) - p.wait() - finally: - if local_wrapper is not None: - os.remove(local_wrapper) + p = popen(cmd, env=env, cwd=self.cwd) + p.wait() if not os.path.exists(self.trace_file): fail('no trace file generated\n') def checkTrace(self): - cmd = [_get_build_program('apitrace'), 'dump', '--color=never', self.trace_file] + cmd = [options.apitrace, 'dump', '--color=never', self.trace_file] p = popen(cmd, stdout=subprocess.PIPE) checker = TraceChecker(p.stdout, self.ref_dump, self.verbose) @@ -488,6 +500,10 @@ class TestCase: def main(): global options + default_apitrace = 'apitrace' + if platform.system() == 'Windows': + default_apitrace += '.exe' + # Parse command line options optparser = optparse.OptionParser( usage='\n\t%prog [options] -- [TRACE|PROGRAM] ...', @@ -502,9 +518,9 @@ def main(): type='string', dest='api', default='gl', help='api to trace') optparser.add_option( - '-B', '--build', metavar='PATH', - type='string', dest='build', default='..', - help='path to apitrace build') + '--apitrace', metavar='PROGRAM', + type='string', dest='apitrace', default=default_apitrace, + help='path to apitrace executable') optparser.add_option( '-C', '--directory', metavar='PATH', type='string', dest='cwd', default=None, @@ -525,7 +541,9 @@ def main(): if not os.path.exists(options.results): os.makedirs(options.results) - sys.path.insert(0, _get_source_path('scripts')) + print _get_scripts_path() + + sys.path.insert(0, _get_scripts_path()) test = TestCase() test.verbose = options.verbose -- 2.43.0