Bug 1533282 - Restore the debugging options in wrench/script/headless.py. r=kvark,kats
authorNicolas Silva <nsilva@mozilla.com>
Fri, 08 Mar 2019 11:15:32 +0100
changeset 521058 c8f81797dbae
parent 521003 2aa82e63f173
child 521059 97f72b9e4d74
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark, kats
bugs1533282
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533282 - Restore the debugging options in wrench/script/headless.py. r=kvark,kats Differential Revision: https://phabricator.services.mozilla.com/D22458
gfx/wr/wrench/script/headless.py
--- a/gfx/wr/wrench/script/headless.py
+++ b/gfx/wr/wrench/script/headless.py
@@ -44,38 +44,87 @@ def is_windows():
 def is_macos():
     return sys.platform == 'darwin'
 
 
 def is_linux():
     return sys.platform.startswith('linux')
 
 
+def debugger():
+    if "DEBUGGER" in os.environ:
+        return os.environ["DEBUGGER"]
+    return None
+
+
+def use_gdb():
+    return debugger() in ['gdb', 'cgdb', 'rust-gdb']
+
+
+def use_rr():
+    return debugger() == 'rr'
+
+
+def optimized_build():
+    if "OPTIMIZED" in os.environ:
+        opt = os.environ["OPTIMIZED"]
+        return opt not in ["0", "false"]
+    return True
+
+
 def set_osmesa_env(bin_path):
     """Set proper LD_LIBRARY_PATH and DRIVE for software rendering on Linux and OSX"""
     if is_linux():
         osmesa_path = path.join(find_dep_path_newest('osmesa-src', bin_path), "out", "lib", "gallium")
         print(osmesa_path)
         os.environ["LD_LIBRARY_PATH"] = osmesa_path
         os.environ["GALLIUM_DRIVER"] = "softpipe"
     elif is_macos():
         osmesa_path = path.join(find_dep_path_newest('osmesa-src', bin_path),
                                 "out", "src", "gallium", "targets", "osmesa", ".libs")
         glapi_path = path.join(find_dep_path_newest('osmesa-src', bin_path),
                                "out", "src", "mapi", "shared-glapi", ".libs")
         os.environ["DYLD_LIBRARY_PATH"] = osmesa_path + ":" + glapi_path
         os.environ["GALLIUM_DRIVER"] = "softpipe"
 
 
-target_folder = os.getenv('WRENCH_HEADLESS_TARGET', None)
-if not target_folder:
-    extra_flags = os.getenv('CARGOFLAGS', None)
-    extra_flags = extra_flags.split(' ') if extra_flags else []
-    subprocess.check_call(['cargo', 'build'] + extra_flags + ['--release', '--verbose', '--features', 'headless'])
+extra_flags = os.getenv('CARGOFLAGS', None)
+extra_flags = extra_flags.split(' ') if extra_flags else []
+
+wrench_headless_target = os.getenv('WRENCH_HEADLESS_TARGET', None)
+
+if wrench_headless_target:
+    target_folder = wrench_headless_target
+else:
     target_folder = '../target/'
 
-set_osmesa_env(target_folder + 'release/')
+if optimized_build():
+    target_folder += 'release/'
+else:
+    target_folder += 'debug/'
+
+# For CI purposes, don't build if WRENCH_HEADLESS_TARGET is set.
+# This environment variable is used to point to the location of a cross-compiled
+# wrench for the CI on some platforms.
+if not wrench_headless_target:
+    build_cmd = ['cargo', 'build'] + extra_flags + ['--verbose', '--features', 'headless']
+    if optimized_build():
+        build_cmd += ['--release']
+    subprocess.check_call(build_cmd)
+
+dbg_cmd = []
+if use_rr():
+    dbg_cmd = ['rr', 'record']
+elif use_gdb():
+    dbg_cmd = [debugger(), '--args']
+elif debugger():
+    print("Unknown debugger: " + debugger())
+    sys.exit(1)
+
+set_osmesa_env(target_folder)
 # TODO(gw): We have an occasional accuracy issue or bug (could be WR or OSMesa)
 #           where the output of a previous test that uses intermediate targets can
 #           cause 1.0 / 255.0 pixel differences in a subsequent test. For now, we
 #           run tests with no-scissor mode, which ensures a complete target clear
 #           between test runs. But we should investigate this further...
-subprocess.check_call([target_folder + 'release/wrench', '--no-scissor', '-h'] + sys.argv[1:])
+cmd = dbg_cmd + [target_folder + 'wrench', '--no-scissor', '-h'] + sys.argv[1:]
+print('Running: `' + ' '.join(cmd) + '`')
+subprocess.check_call(cmd)