Last active
August 29, 2015 13:57
-
-
Save simonlindholm/9830844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import shutil | |
import argparse | |
if len(sys.argv) == 1: | |
program = os.path.basename(sys.argv[0]) | |
print("Sample usage:") | |
print("$ git bisect start HEAD HEAD~10") | |
print("$ " + program + " -b firefox-nightly tests/content/console/4658/issue4658.js") | |
print("$ git bisect reset") | |
print("") | |
print("Pass -h for information on options.") | |
sys.exit() | |
parser = argparse.ArgumentParser() | |
parser.add_argument('path', help="path to .js file") | |
parser.add_argument('-b', dest='binary', help="path to Firefox binary", default='firefox') | |
parser.add_argument('-u', dest='url', help="URL to firebug.html") | |
parser.add_argument('-x', dest='fbtestxpi', help="path to FBTest XPI") | |
args = parser.parse_args() | |
filename = args.path | |
if not filename.endswith('.js'): | |
print("error: filename has to end with .js") | |
sys.exit() | |
filename = os.path.realpath(filename) | |
def norm(path): | |
return path.replace('/', os.sep) | |
sep = norm('/firebug/tests/content/') | |
ind = filename.rfind(sep) | |
if ind == -1: | |
print("error: .js file must point to a test") | |
sys.exit() | |
fbtestxpi = args.fbtestxpi | |
if fbtestxpi: | |
fbtestxpi = os.path.realpath(fbtestxpi) | |
if not os.access(fbtestxpi, os.R_OK): | |
print("error: FBTest XPI does not exist") | |
sys.exit() | |
firebugdir = filename[0:ind + len(norm('/firebug/'))] | |
basedir = filename[0:ind + len(sep)] | |
# set up a temporary profile | |
shutil.rmtree(basedir + 'temp-profile', ignore_errors=True) | |
os.mkdir(basedir + 'temp-profile') | |
os.mkdir(basedir + norm('temp-profile/extensions')) | |
with open(basedir + norm('temp-profile/extensions/firebug@software.joehewitt.com'), 'w') as f: | |
f.write(firebugdir + norm('extension/')) | |
if fbtestxpi: | |
shutil.copyfile(fbtestxpi, basedir + norm('temp-profile/extensions/fbtest@mozilla.com.xpi')) | |
else: | |
with open(basedir + norm('temp-profile/extensions/fbtest@mozilla.com'), 'w') as f: | |
f.write(firebugdir + norm('tests/FBTest/')) | |
with open(basedir + norm('temp-profile/prefs.js'), 'w') as f: | |
f.write('user_pref("browser.shell.checkDefaultBrowser", false);\n') | |
f.write('user_pref("browser.dom.window.dump.enabled", true);\n') | |
f.write('user_pref("browser.startup.homepage_override.mstone", "ignore");\n') | |
f.write('user_pref("browser.rights.3.shown", true);\n') | |
f.write('user_pref("app.update.enabled", false);\n') | |
f.write('user_pref("toolkit.telemetry.prompted", 2);\n') | |
f.write('user_pref("toolkit.telemetry.rejected", true);\n') | |
f.write('user_pref("extensions.autoDisableScopes", 14);\n') | |
f.write('user_pref("extensions.firebug.showFirstRunPage", false);\n') | |
fxpath = args.binary | |
url = args.url or 'file://' + basedir + 'firebug.html' | |
testpath = filename[len(basedir):] | |
# cd into the toplevel directory so that git bisect works | |
os.chdir(firebugdir) | |
cmd = 'git bisect run sh -c "{} -no-remote -profile {}temp-profile -runFBTests \'{}#{}\' -quitAfterRun | grep PASS"'.format(fxpath, basedir, url, testpath) | |
os.system(cmd) | |
shutil.rmtree(basedir + 'temp-profile') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment