shenhan | b7ff88b | 2013-02-19 20:42:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to checkout the ChromeOS source. |
| 6 | |
| 7 | This script sets up the ChromeOS source in the given directory, matching a |
| 8 | particular release of ChromeOS. |
| 9 | """ |
| 10 | |
| 11 | __author__ = "raymes@google.com (Raymes Khoury)" |
| 12 | |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 13 | from datetime import datetime |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 14 | import getpass |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 15 | import optparse |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 16 | import os |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 17 | import pickle |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 18 | import sys |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 19 | import tempfile |
| 20 | import time |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 21 | from utils import command_executer |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 22 | from utils import logger |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 23 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 24 | GCLIENT_FILE = """solutions = [ |
| 25 | { "name" : "CHROME_DEPS", |
| 26 | "url" : |
| 27 | "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s", |
| 28 | "custom_deps" : { |
| 29 | "src/third_party/WebKit/LayoutTests": None, |
| 30 | "src-pdf": None, |
| 31 | "src/pdf": None, |
| 32 | }, |
| 33 | "safesync_url": "", |
| 34 | }, |
| 35 | ] |
| 36 | """ |
| 37 | |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 38 | # List of stable versions used for common team image |
| 39 | # Sheriff must update this list when a new common version becomes available |
| 40 | COMMON_VERSIONS = "/home/mobiletc-prebuild/common_images/common_list.txt" |
| 41 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 42 | def Usage(parser): |
| 43 | parser.print_help() |
| 44 | sys.exit(0) |
| 45 | |
| 46 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 47 | def TimeToVersion(my_time, versions_git): |
| 48 | """Convert timestamp to version number.""" |
| 49 | cur_time = time.mktime(time.gmtime()) |
| 50 | des_time = float(my_time) |
| 51 | if cur_time - des_time > 7000000: |
| 52 | logger.GetLogger().LogFatal("The time you specify is too early.") |
| 53 | temp = tempfile.mkdtemp() |
| 54 | commands = ["cd {0}".format(temp), "git clone {0}".format(versions_git), |
| 55 | "cd manifest-versions", "git checkout -f $(git rev-list" + |
| 56 | " --max-count=1 --before={0} origin/master)".format(my_time)] |
| 57 | cmd_executer = command_executer.GetCommandExecuter() |
| 58 | ret = cmd_executer.RunCommands(commands) |
| 59 | if ret: |
| 60 | return None |
| 61 | path = os.path.realpath("{0}/manifest-versions/LKGM/lkgm.xml".format(temp)) |
| 62 | pp = path.split("/") |
| 63 | small = os.path.basename(path).split(".xml")[0] |
| 64 | version = pp[-2] + "." + small |
| 65 | commands = ["rm -rf {0}".format(temp)] |
| 66 | cmd_executer.RunCommands(commands) |
| 67 | return version |
| 68 | |
| 69 | |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 70 | def TimeToCommonVersion(timestamp): |
| 71 | """Convert timestamp to common image version.""" |
| 72 | tdt = datetime.fromtimestamp(float(timestamp)) |
| 73 | with open(COMMON_VERSIONS, "r") as f: |
| 74 | common_list = pickle.load(f) |
| 75 | for sv in common_list: |
| 76 | sdt = datetime.strptime(sv["date"], "%Y-%m-%d %H:%M:%S.%f") |
| 77 | if tdt >= sdt: |
| 78 | return "%s.%s" % (sv["chrome_major_version"], sv["chromeos_version"]) |
| 79 | # should never reach here |
| 80 | logger.GetLogger().LogFatal("No common version for timestamp") |
| 81 | return None |
| 82 | |
| 83 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 84 | def Main(argv): |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 85 | """Checkout the ChromeOS source.""" |
| 86 | parser = optparse.OptionParser() |
| 87 | parser.add_option("--dir", dest="directory", |
| 88 | help="Target directory for ChromeOS installation.") |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 89 | parser.add_option("--version", dest="version", default="latest", |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 90 | help="""ChromeOS version. Can be: |
| 91 | (1) A release version in the format: 'X.X.X.X' |
| 92 | (2) 'top' for top of trunk |
| 93 | (3) 'latest_lkgm' for the latest lkgm version |
| 94 | (4) 'lkgm' for the lkgm release before timestamp |
| 95 | (5) 'latest_common' for the latest team common stable version |
| 96 | (6) 'common' for the team common stable version before timestamp |
| 97 | Default is 'latest_lkgm'.""") |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 98 | parser.add_option("--timestamp", dest="timestamp", default=None, |
| 99 | help="""Timestamps in epoch format. It will check out the |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 100 | latest LKGM or the latest COMMON version of ChromeOS before the timestamp. |
| 101 | Use in combination with --version=latest or --version=common. Use |
| 102 | 'date -d <date string> +%s' to find epoch time""") |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 103 | parser.add_option("--minilayout", dest="minilayout", default=False, |
asharif | dff6134 | 2013-02-15 04:50:46 +0000 | [diff] [blame] | 104 | action="store_true", |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 105 | help="""Whether to checkout the minilayout |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 106 | (smaller checkout).'""") |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 107 | parser.add_option("--jobs", "-j", dest="jobs", default="1", |
| 108 | help="Number of repo sync threads to use.") |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 109 | parser.add_option("--public", "-p", dest="public", default=False, |
| 110 | action="store_true", |
| 111 | help="Use the public checkout instead of the private one.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 112 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 113 | options = parser.parse_args(argv)[0] |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 114 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 115 | if not options.version: |
| 116 | parser.print_help() |
| 117 | logger.GetLogger().LogFatal("No version specified.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 118 | else: |
| 119 | version = options.version.strip() |
| 120 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 121 | if not options.timestamp: |
| 122 | timestamp = "" |
| 123 | else: |
| 124 | timestamp = options.timestamp.strip() |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 125 | if version not in ("lkgm", "common"): |
| 126 | parser.print_help() |
| 127 | logger.GetLogger().LogFatal("timestamp option only applies for " |
| 128 | "versions \"lkgm\" or \"common\"") |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 129 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 130 | if not options.directory: |
| 131 | parser.print_help() |
| 132 | logger.GetLogger().LogFatal("No directory specified.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 133 | |
| 134 | directory = options.directory.strip() |
| 135 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 136 | if options.public: |
| 137 | manifest_repo = "http://git.chromium.org/chromiumos/manifest.git" |
| 138 | versions_repo = "http://git.chromium.org/chromiumos/manifest-versions.git" |
| 139 | else: |
| 140 | manifest_repo = ( |
| 141 | "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git") |
| 142 | versions_repo = ( |
| 143 | "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-versions.git") |
| 144 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 145 | if version == "top": |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 146 | init = "repo init -u %s" % manifest_repo |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 147 | elif version == "latest_lkgm": |
| 148 | version = TimeToVersion(time.mktime(time.gmtime()), versions_repo) |
| 149 | version, manifest = version.split(".", 1) |
| 150 | logger.GetLogger().LogOutput("found version %s.%s for latest LKGM" % ( |
| 151 | version, manifest)) |
| 152 | init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % ( |
| 153 | versions_repo, version, manifest)) |
| 154 | elif version == "lkgm": |
| 155 | if not timestamp: |
| 156 | parser.print_help() |
| 157 | logger.GetLogger().LogFatal("No timestamp specified for version=lkgm") |
| 158 | version = TimeToVersion(timestamp, versions_repo) |
| 159 | version, manifest = version.split(".", 1) |
| 160 | logger.GetLogger().LogOutput("found version %s.%s for LKGM at timestamp %s" |
| 161 | % (version, manifest, timestamp)) |
| 162 | init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % ( |
| 163 | versions_repo, version, manifest)) |
| 164 | elif version == "latest_common": |
| 165 | version = TimeToCommonVersion(time.mktime(time.gmtime())) |
| 166 | version, manifest = version.split(".", 1) |
| 167 | logger.GetLogger().LogOutput("found version %s.%s for latest Common image" % |
| 168 | (version, manifest)) |
| 169 | init = ("repo init -u %s -m buildspecs/%s/%s.xml" % ( |
| 170 | versions_repo, version, manifest)) |
| 171 | elif version == "common": |
| 172 | if not timestamp: |
| 173 | parser.print_help() |
| 174 | logger.GetLogger().LogFatal("No timestamp specified for version=lkgm") |
| 175 | version = TimeToCommonVersion(timestamp) |
| 176 | version, manifest = version.split(".", 1) |
| 177 | logger.GetLogger().LogOutput("found version %s.%s for latest common image " |
| 178 | "at timestamp %s" % ( |
| 179 | version, manifest, timestamp)) |
| 180 | init = ("repo init -u %s -m buildspecs/%s/%s.xml" % ( |
| 181 | versions_repo, version, manifest)) |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 182 | else: |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 183 | # user specified a specific version number |
shenhan | 9c39a84 | 2013-02-16 03:14:07 +0000 | [diff] [blame] | 184 | version, manifest = version.split(".", 1) |
llozano | 54bef9a | 2013-02-19 19:42:41 +0000 | [diff] [blame] | 185 | init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % ( |
llozano | 9efafde | 2013-02-23 01:37:04 +0000 | [diff] [blame^] | 186 | versions_repo, version, manifest)) |
| 187 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 188 | if options.minilayout: |
yunlian | 992a490 | 2013-02-19 20:19:25 +0000 | [diff] [blame] | 189 | init += " -g minilayout" |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 190 | |
asharif | 731e293 | 2013-02-15 21:20:10 +0000 | [diff] [blame] | 191 | init += " --repo-url=http://git.chromium.org/external/repo.git" |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 192 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 193 | commands = ["mkdir -p %s" % directory, |
| 194 | "cd %s" % directory, |
| 195 | init, |
shenhan | b7ff88b | 2013-02-19 20:42:48 +0000 | [diff] [blame] | 196 | # crosbug#31837 - "Sources need to be world-readable to properly |
| 197 | # function inside the chroot" |
| 198 | "umask 022 && repo sync -j %s" % options.jobs] |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 199 | cmd_executer = command_executer.GetCommandExecuter() |
| 200 | ret = cmd_executer.RunCommands(commands) |
| 201 | if ret: |
| 202 | return ret |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 203 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 204 | # Setup svn credentials for use inside the chroot |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 205 | if getpass.getuser() == "mobiletc-prebuild": |
| 206 | chromium_username = "raymes" |
| 207 | else: |
| 208 | chromium_username = "$USER" |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 209 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 210 | return cmd_executer.RunCommand( |
| 211 | "svn ls --config-option config:auth:password-stores= " |
| 212 | "--config-option " |
| 213 | "servers:global:store-plaintext-passwords=yes " |
| 214 | "--username " + chromium_username + "@google.com " |
| 215 | "svn://svn.chromium.org/leapfrog-internal " |
| 216 | "svn://svn.chromium.org/chrome " |
| 217 | "svn://svn.chromium.org/chrome-internal > /dev/null") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 218 | |
| 219 | |
| 220 | if __name__ == "__main__": |
asharif | 2198c51 | 2013-02-15 09:21:35 +0000 | [diff] [blame] | 221 | retval = Main(sys.argv) |
| 222 | sys.exit(retval) |