def force_update(): with misc.ChDir(os.path.join(misc.BUILDBOT_PATH, os.pardir)): # Run "gclient" before doing anything else to ensure that we get the # necessary stuff installed. gclient_utils.GClient() # Be sure that we sync to the most recent commit. buildbot_revision = None try: output = git_utils.GetRemoteMasterHash(BUILDBOT_GIT_URL) if output: buildbot_revision = shlex.split(output)[0] except shell_utils.CommandFailedException: pass if not buildbot_revision: buildbot_revision = 'origin/master' gclient_utils.Sync(revisions=[('buildbot', buildbot_revision)], verbose=True, force=True) got_revision = gclient_utils.GetCheckedOutHash() print GOT_REVISION_PATTERN % got_revision return gclient_utils.GetCheckedOutHash()
def Sync(skia_revision=SKIA_REV_MASTER, chrome_revision=CHROME_REV_LKGR, fetch_target=DEFAULT_FETCH_TARGET, gyp_defines=None, gyp_generators=None): """ Create and sync a checkout of Skia inside a checkout of Chrome. Returns a tuple containing the actually-obtained revision of Skia and the actually- obtained revision of Chrome. skia_revision: revision of Skia to sync. Should be a commit hash or one of (SKIA_REV_DEPS, SKIA_REV_MASTER). chrome_revision: revision of Chrome to sync. Should be a commit hash or one of (CHROME_REV_LKGR, CHROME_REV_MASTER). fetch_target: string; Calls the fetch tool in depot_tools with the specified argument. Default is DEFAULT_FETCH_TARGET. gyp_defines: optional string; GYP_DEFINES to be passed to Gyp. gyp_generators: optional string; which GYP_GENERATORS to use. """ # Figure out what revision of Skia we should use. if skia_revision == SKIA_REV_MASTER: output = GetRemoteMasterHash(SKIA_GIT_URL) if output: skia_revision = shlex.split(output)[0] if not skia_revision: raise Exception('Could not determine current Skia revision!') skia_revision = str(skia_revision) # Use Chrome LKGR, since gclient_utils will force a sync to origin/master. if chrome_revision == CHROME_REV_LKGR: chrome_revision = urllib2.urlopen(CHROME_LKGR_URL).read() elif chrome_revision == CHROME_REV_MASTER: chrome_revision = shlex.split( GetRemoteMasterHash(CHROME_GIT_URL))[0] # Run "fetch chromium". The initial run is allowed to fail after it does some # work. At the least, we expect the .gclient file to be present when it # finishes. if not os.path.isfile(GCLIENT_FILE): try: shell_utils.run([FETCH, fetch_target, '--nosvn=True']) except shell_utils.CommandFailedException: pass if not os.path.isfile(GCLIENT_FILE): raise Exception('Could not fetch %s!' % fetch_target) # Run "gclient sync" revisions = [('src', chrome_revision)] if skia_revision != SKIA_REV_DEPS: revisions.append(('src/third_party/skia', skia_revision)) try: # Hack: We have to set some GYP_DEFINES, or upstream scripts will complain. os.environ['GYP_DEFINES'] = os.environ.get('GYP_DEFINES') or '' gclient_utils.Sync( revisions=revisions, jobs=1, no_hooks=True, force=True) except shell_utils.CommandFailedException as e: # We frequently see sync failures because a lock file wasn't deleted. In # that case, delete the lock file and try again. pattern = r".*fatal: Unable to create '(\S+)': File exists\..*" match = re.search(pattern, e.output) if not match: raise e file_to_delete = match.groups()[0] try: print 'Attempting to remove %s' % file_to_delete os.remove(file_to_delete) except OSError: # If the file no longer exists, just try again. pass gclient_utils.Sync( revisions=revisions, jobs=1, no_hooks=True, force=True) # Find the actually-obtained Chrome revision. os.chdir('src') actual_chrome_rev = shell_utils.run([GIT, 'rev-parse', 'HEAD'], log_in_real_time=False).rstrip() # Find the actually-obtained Skia revision. with misc.ChDir(os.path.join('third_party', 'skia')): actual_skia_rev = shell_utils.run([GIT, 'rev-parse', 'HEAD'], log_in_real_time=False).rstrip() # Run gclient hooks gclient_utils.RunHooks(gyp_defines=gyp_defines, gyp_generators=gyp_generators) # Fix the submodules so that they don't show up in "git status" # This fails on Windows... if os.name != 'nt': submodule_cmd = ('\'git config -f ' '$toplevel/.git/config submodule.$name.ignore all\'') shell_utils.run(' '.join([GIT, 'submodule', 'foreach', submodule_cmd]), shell=True) # Verify that we got the requested revisions of Chrome and Skia. if (skia_revision != actual_skia_rev[:len(skia_revision)] and skia_revision != SKIA_REV_DEPS): raise Exception('Requested Skia revision %s but got %s!' % ( skia_revision, actual_skia_rev)) if (chrome_revision and chrome_revision != actual_chrome_rev[:len(chrome_revision)]): raise Exception('Requested Chrome revision %s but got %s!' % ( chrome_revision, actual_chrome_rev)) return (actual_skia_rev, actual_chrome_rev)