Commit c989674f authored by maruel@chromium.org's avatar maruel@chromium.org

Rewrite chrome-update.py and .bat.

Now reuse compile.py and almost make them platform agnostic.

TEST=none
BUG=none
Review URL: http://codereview.chromium.org/306031

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@59108 0039d316-1c4b-4281-b951-d872f2087c98
parent fa410372
...@@ -76,7 +76,6 @@ goto :END ...@@ -76,7 +76,6 @@ goto :END
:PYTHON_INSTALL :PYTHON_INSTALL
echo Installing python ... echo Installing python ...
:: Cleanup python directory if it was existing. :: Cleanup python directory if it was existing.
if exist "%WIN_TOOLS_ROOT_DIR%\python\." rd /q /s "%WIN_TOOLS_ROOT_DIR%\python"
if exist "%WIN_TOOLS_ROOT_DIR%\python_bin\." rd /q /s "%WIN_TOOLS_ROOT_DIR%\python_bin" if exist "%WIN_TOOLS_ROOT_DIR%\python_bin\." rd /q /s "%WIN_TOOLS_ROOT_DIR%\python_bin"
call svn co -q %WIN_TOOLS_ROOT_URL%/third_party/python_26 "%WIN_TOOLS_ROOT_DIR%\python_bin" call svn co -q %WIN_TOOLS_ROOT_URL%/third_party/python_26 "%WIN_TOOLS_ROOT_DIR%\python_bin"
if errorlevel 1 goto :PYTHON_FAIL if errorlevel 1 goto :PYTHON_FAIL
......
...@@ -35,7 +35,7 @@ echo. ...@@ -35,7 +35,7 @@ echo.
echo Creating %Out% echo Creating %Out%
echo>"%Out%" @echo off echo>"%Out%" @echo off
echo>>"%Out%" "%~dp0chrome-update.bat" "%Trunk%" ^> "%Trunk%\chrome-update-results.txt" echo>>"%Out%" "%~dp0chrome-update.bat" "%Trunk%" --solution chrome.sln --target Debug --build-dir src/chrome ^> "%Trunk%\chrome-update-results.txt"
:CreateTask :CreateTask
......
@echo off @echo off
:: This batch file assumes that the correct version of python can be found in
:: the current directory, and that you have Visual Studio 8 installed in the
:: default location. It will try to find Visual Studio in the default
:: installation paths for x86 and x64 versions of windows as well as through
:: the PATH environment variable.
setlocal setlocal
IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" ( :: This is required with cygwin only.
CALL "%ProgramFiles(x86)%\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" PATH=%~dp0;%PATH%
) ELSE IF EXIST "%ProgramFiles%\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" ( call python "%~dp0chrome-update.py" %*
CALL "%ProgramFiles%\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"
) ELSE (
:: See "HELP CALL" for information on how to use %~$PATH:1 to find a file in
:: the PATH.
CALL :FIND_IN_PATH "vcvars32.bat"
)
:: If vcvasr32.bat cannot be found or there was a problem, stop execution.
IF %ERRORLEVEL%==1 GOTO :EOF
python "%~dp0chrome-update.py" %*
GOTO :EOF
:FIND_IN_PATH
:: %~$PATH:1 works like "which" on linux; use it to see if the file exists and
:: call it if found. If it cannot be found print an error and set errorlevel
IF EXIST "%~$PATH:1" (
CALL "%~$PATH:1"
) ELSE (
ECHO Cannot find vcvars32.bat! (Do you have Visual Studio in your PATH?)
SET ERRORLEVEL=1
)
GOTO :EOF
...@@ -3,171 +3,85 @@ ...@@ -3,171 +3,85 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# Author: mpcomplete
#
# This script updates and does a clean build of chrome for you.
# Usage: python chrome-update.py C:\path\to\chrome\trunk
#
# It assumes the following:
# - You have gclient.bat and devenv.com in your path (use the wrapper batch
# file to ensure this).
import sys
import os import os
import subprocess
import httplib
import re import re
import shutil import subprocess
import optparse import sys
import urllib
def Message(str): IS_WIN = sys.platform.startswith('win')
"""Prints a status message.""" BASE_URL = 'http://src.chromium.org/svn/trunk/tools/buildbot/scripts/'
print "[chrome-update]", str COMPILE_URL = BASE_URL + 'slave/compile.py'
UTILS_URL = BASE_URL + 'common/chromium_utils.py'
def FixupPath(path):
"""Returns the OS-ified version of a windows path."""
return os.path.sep.join(path.split("\\"))
def GetRevision(): def Fetch(url, file):
if not os.path.exists(file):
urllib.urlretrieve(url, file)
def GetLastestRevision():
"""Returns the revision number of the last build that was archived, or """Returns the revision number of the last build that was archived, or
None on failure.""" None on failure."""
HOST = "build.chromium.org" url = 'http://build.chromium.org/buildbot/continuous/'
PATH = "/buildbot/continuous/LATEST/REVISION" if sys.platform.startswith('win'):
EXPR = r"(\d+)" url += 'win/'
elif sys.platform.startswith('linux'):
connection = httplib.HTTPConnection(HOST) url += 'linux/'
connection.request("GET", PATH) elif sys.platform.startswith('darwin'):
response = connection.getresponse() url += 'mac/'
text = response.read() else:
match = re.search(EXPR, text) # This path is actually win.
if match: pass
return int(match.group(1)) url += 'LATEST/REVISION'
text = urllib.urlopen(url).read()
if text:
match = re.search(r"(\d+)", text)
if match:
return int(match.group(1))
return None return None
def SetRevisionForUpdate(chrome_root):
"""Prepares environment so gclient syncs to a good revision, if possible."""
# Find a buildable revision.
rev = GetRevision()
if rev == None:
Message("WARNING: Failed to find a buildable revision. Syncing to trunk.")
return "trunk"
# Read the .gclient file.
gclient_file = chrome_root + FixupPath("\\.gclient")
if not os.path.exists(gclient_file):
Message("WARNING: Failed to find .gclient file. Syncing to trunk.")
return "trunk"
scope = {}
execfile(gclient_file, scope)
solutions = scope["solutions"]
# Edit the url of the chrome 'src' solution, unless the user wants a
# specific revision.
for solution in solutions:
if solution["name"] == "src":
splitter = solution["url"].split("@")
if len(splitter) == 1:
solution["url"] = splitter[0] + "@" + str(rev)
else:
rev = int(splitter[1])
break
# Write out the new .gclient file.
gclient_override = gclient_file + "-update-chrome"
f = open(gclient_override, "w")
f.write("solutions = " + str(solutions))
f.close()
# Set the env var that the gclient tool looks for.
os.environ["GCLIENT_FILE"] = gclient_override
return rev
def DoUpdate(chrome_root): def DoUpdate(chrome_root):
"""gclient sync to the latest build.""" """gclient sync to the latest build."""
# gclient sync cmd = ["gclient", "sync"]
rev = SetRevisionForUpdate(chrome_root) rev = GetLastestRevision()
if rev:
cmd = ["gclient.bat", "sync"] cmd.extend(['--revision', 'src@%d' % rev])
Message("Updating to %s: %s" % (rev, cmd)) return subprocess.call(cmd, cwd=chrome_root, shell=IS_WIN)
sys.stdout.flush()
return subprocess.call(cmd, cwd=chrome_root)
def DoBuild(chrome_root, args):
def DoClean(chrome_root, type): """Download compile.py and run it."""
"""Clean our build dir.""" compile = os.path.join(chrome_root, 'compile.py')
# rm -rf src/chrome/Debug Fetch(COMPILE_URL, compile)
rv = [0] Fetch(UTILS_URL, os.path.join(chrome_root, 'chromium_utils.py'))
def onError(func, path, excinfo): cmd = ['python', compile] + args
Message("Couldn't remove '%s': %s" % (path, excinfo)) return subprocess.call(cmd, cwd=chrome_root, shell=IS_WIN)
rv[0] = [1]
build_path = chrome_root + FixupPath("\\src\\chrome\\" + type) def Main(args):
Message("Cleaning: %s" % build_path) if len(args) < 3:
shutil.rmtree(build_path, False, onError) print('Usage: chrome-update.py <path> [options]')
return rv[0] print('See options from compile.py at')
print(' %s' % COMPILE_URL)
def DoBuild(chrome_root, chrome_sln, clean, type): print('\nFor more example, see the compile steps on the waterfall')
"""devenv /build what we just checked out.""" return 1
if clean:
rv = DoClean(chrome_root, type) chrome_root = args[1]
if rv != 0:
Message("WARNING: Clean failed. Doing a build without clean.")
# devenv chrome.sln /build Debug
cmd = ["devenv.com", chrome_sln, "/build", type]
Message("Building: %s" % cmd)
sys.stdout.flush()
return subprocess.call(cmd, cwd=chrome_root)
def Main():
parser = optparse.OptionParser()
parser.add_option("", "--clean", action="store_true", default=False,
help="wipe Debug output directory before building")
parser.add_option("", "--solution", default="src\\chrome\\chrome.sln",
help="path to the .sln file to build (absolute, or "
"relative to chrome trunk")
parser.add_option("", "--release", action="store_true", default=False,
help="build the release configuration in addition of the "
"debug configuration.")
parser.add_option("", "--nosync", action="store_true", default=False,
help="doesn't sync before building")
parser.add_option("", "--print-latest", action="store_true", default=False,
help="print the latest buildable revision and exit")
options, args = parser.parse_args(None)
if options.print_latest:
print GetRevision() or "HEAD"
sys.exit(0)
if not args:
Message("Usage: %s <path\\to\\chrome\\root> [options]" % sys.argv[0])
sys.exit(1)
chrome_root = args[0]
if not os.path.isdir(chrome_root): if not os.path.isdir(chrome_root):
Message("Path to chrome root (%s) not found." % repr(chrome_root)) print('Path to chrome root (%s) not found.' % chrome_root)
sys.exit(1) return 1
if not options.nosync:
rv = DoUpdate(chrome_root)
if rv != 0:
Message("Update Failed. Bailing.")
sys.exit(rv)
chrome_sln = FixupPath(options.solution) rv = DoUpdate(chrome_root)
rv = DoBuild(chrome_root, chrome_sln, options.clean, "Debug")
if rv != 0: if rv != 0:
Message("Debug build failed. Sad face :(") print('Update Failed. Bailing.')
return rv
if options.release: DoBuild(chrome_root, args[2:])
rv = DoBuild(chrome_root, chrome_sln, options.clean, "Release") print('Success!')
if rv != 0: return 0
Message("Release build failed. Sad face :(")
if rv != 0:
sys.exit(rv)
Message("Success!")
if __name__ == "__main__": if __name__ == "__main__":
Main() sys.exit(Main(sys.argv))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment