| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Tool to update the version of the (binary) network service used (prebuilt | |
| 7 from the Chromium tree). See: | |
| 8 https://github.com/domokit/mojo/wiki/Rolling-code-between-chromium-and-mojo#roll
ing-the-network-service | |
| 9 """ | |
| 10 | |
| 11 import argparse | |
| 12 import os | |
| 13 import re | |
| 14 import subprocess | |
| 15 import sys | |
| 16 import tempfile | |
| 17 import urllib2 | |
| 18 import zipfile | |
| 19 | |
| 20 from update_from_chromium import chromium_rev_number | |
| 21 from utils import commit | |
| 22 from utils import mojo_root_dir | |
| 23 from utils import system | |
| 24 | |
| 25 import patch | |
| 26 | |
| 27 sys.path.insert(0, os.path.join(mojo_root_dir, "mojo/public/tools/pylib")) | |
| 28 # pylint: disable=F0401 | |
| 29 import gs | |
| 30 | |
| 31 def roll(target_version, custom_build): | |
| 32 find_depot_tools_path = os.path.join(mojo_root_dir, "tools") | |
| 33 sys.path.insert(0, find_depot_tools_path) | |
| 34 # pylint: disable=F0401 | |
| 35 import find_depot_tools | |
| 36 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | |
| 37 | |
| 38 if custom_build: | |
| 39 match = re.search( | |
| 40 "^custom_build_base_([^_]+)_issue_([0-9]+)_patchset_([0-9]+)$", | |
| 41 target_version) | |
| 42 if not match: | |
| 43 print "Failed to parse the version name." | |
| 44 return 1 | |
| 45 chromium_commit_hash = match.group(1) | |
| 46 rietveld_issue = match.group(2) | |
| 47 rietveld_patchset = match.group(3) | |
| 48 else: | |
| 49 chromium_commit_hash = target_version | |
| 50 | |
| 51 try: | |
| 52 chromium_rev = chromium_rev_number(chromium_commit_hash) | |
| 53 except urllib2.HTTPError: | |
| 54 print ("Failed to identify a Chromium revision associated with %s. " | |
| 55 "Ensure that it is a Chromium origin/master " | |
| 56 "commit.") % (chromium_commit_hash) | |
| 57 return 1 | |
| 58 | |
| 59 mojoms_gs_path = "gs://mojo/network_service/%s/mojoms.zip" % (target_version,) | |
| 60 network_service_path = os.path.join( | |
| 61 mojo_root_dir, "mojo", "services", "network") | |
| 62 mojoms_path = os.path.join(network_service_path, "public", "interfaces") | |
| 63 mojo_public_tools_path = os.path.join( | |
| 64 mojo_root_dir, "mojo", "public", "tools") | |
| 65 version_path = os.path.join(mojo_public_tools_path, "NETWORK_SERVICE_VERSION") | |
| 66 | |
| 67 try: | |
| 68 with tempfile.NamedTemporaryFile() as temp_zip_file: | |
| 69 gs.download_from_public_bucket(mojoms_gs_path, temp_zip_file.name, | |
| 70 depot_tools_path) | |
| 71 | |
| 72 try: | |
| 73 system(["git", "rm", "-r", mojoms_path], cwd=mojo_root_dir) | |
| 74 except subprocess.CalledProcessError: | |
| 75 print ("Could not remove %s. " | |
| 76 "Ensure your local tree is in a clean state." % mojoms_path) | |
| 77 return 1 | |
| 78 | |
| 79 with zipfile.ZipFile(temp_zip_file.name) as z: | |
| 80 z.extractall(mojoms_path) | |
| 81 # pylint: disable=C0302,bare-except | |
| 82 except: | |
| 83 print ("Failed to download the mojom files associated with %s. Ensure that " | |
| 84 "the corresponding network service artifacts were uploaded to " | |
| 85 "Google Storage.") % (target_version) | |
| 86 return 1 | |
| 87 | |
| 88 with open(version_path, 'w') as stamp_file: | |
| 89 stamp_file.write(target_version) | |
| 90 | |
| 91 system(["git", "add", "public"], cwd=network_service_path) | |
| 92 system(["git", "add", "NETWORK_SERVICE_VERSION"], cwd=mojo_public_tools_path) | |
| 93 | |
| 94 if custom_build: | |
| 95 commit_message = ("Roll the network service to a custom build created from " | |
| 96 "https://crrev.com/%s/#ps%s") % (rietveld_issue, | |
| 97 rietveld_patchset) | |
| 98 else: | |
| 99 commit_message = ("Roll the network service to " | |
| 100 "https://crrev.com/%s") % chromium_rev | |
| 101 commit(commit_message, cwd=mojo_root_dir) | |
| 102 return 0 | |
| 103 | |
| 104 def main(): | |
| 105 parser = argparse.ArgumentParser( | |
| 106 description="Update the pinned version of the network service " + | |
| 107 "and the corresponding checked out mojoms.") | |
| 108 parser.add_argument( | |
| 109 "--custom-build", action="store_true", | |
| 110 help="Indicates that this is a build with change that is not committed. " | |
| 111 "The change must be uploaded to Rietveld.") | |
| 112 parser.add_argument( | |
| 113 "version", | |
| 114 help="Version to roll to. If --custom-build is not specified, this " | |
| 115 "should be a Chromium origin/master commit; otherwise, this should " | |
| 116 "be in the format of custom_build_base_<base_commit>_" | |
| 117 "issue_<rietveld_issue>_patchset_<rietveld_patchset>.") | |
| 118 args = parser.parse_args() | |
| 119 | |
| 120 roll(args.version, args.custom_build) | |
| 121 | |
| 122 try: | |
| 123 patch.patch("network_service_patches") | |
| 124 except subprocess.CalledProcessError: | |
| 125 print "ERROR: Roll failed due to a patch not applying" | |
| 126 print "Fix the patch to apply, commit the result, and re-run this script" | |
| 127 return 1 | |
| 128 | |
| 129 return 0 | |
| 130 | |
| 131 if __name__ == "__main__": | |
| 132 sys.exit(main()) | |
| OLD | NEW |