blob: 1938d7d0e2937be823e12e0fc7659f3f09256352 [file] [log] [blame]
shenhanb7ff88b2013-02-19 20:42:48 +00001#!/usr/bin/python
bjanakiraman7f4a4852013-02-15 04:35:28 +00002#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Script to checkout the ChromeOS source.
6
7This script sets up the ChromeOS source in the given directory, matching a
8particular release of ChromeOS.
9"""
10
11__author__ = "raymes@google.com (Raymes Khoury)"
12
llozano9efafde2013-02-23 01:37:04 +000013from datetime import datetime
asharifca35b772013-02-15 04:56:41 +000014import getpass
bjanakiraman7f4a4852013-02-15 04:35:28 +000015import optparse
yunlian3802fbf2013-02-19 19:58:44 +000016import os
llozano9efafde2013-02-23 01:37:04 +000017import pickle
bjanakiraman7f4a4852013-02-15 04:35:28 +000018import sys
yunlian3802fbf2013-02-19 19:58:44 +000019import tempfile
20import time
raymes01959ae2013-02-15 04:50:07 +000021from utils import command_executer
raymes69c8d722013-02-15 17:55:36 +000022from utils import logger
bjanakiraman7f4a4852013-02-15 04:35:28 +000023
raymesbfb57992013-02-15 04:35:45 +000024GCLIENT_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
llozano9efafde2013-02-23 01:37:04 +000038# List of stable versions used for common team image
39# Sheriff must update this list when a new common version becomes available
40COMMON_VERSIONS = "/home/mobiletc-prebuild/common_images/common_list.txt"
41
bjanakiraman7f4a4852013-02-15 04:35:28 +000042def Usage(parser):
43 parser.print_help()
44 sys.exit(0)
45
46
yunlian3802fbf2013-02-19 19:58:44 +000047def 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
llozano9efafde2013-02-23 01:37:04 +000070def 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
asharif0d3535a2013-02-15 04:50:33 +000084def Main(argv):
bjanakiraman7f4a4852013-02-15 04:35:28 +000085 """Checkout the ChromeOS source."""
86 parser = optparse.OptionParser()
87 parser.add_option("--dir", dest="directory",
88 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000089 parser.add_option("--version", dest="version", default="latest",
llozano9efafde2013-02-23 01:37:04 +000090 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
97Default is 'latest_lkgm'.""")
yunlian3802fbf2013-02-19 19:58:44 +000098 parser.add_option("--timestamp", dest="timestamp", default=None,
99 help="""Timestamps in epoch format. It will check out the
llozano9efafde2013-02-23 01:37:04 +0000100latest LKGM or the latest COMMON version of ChromeOS before the timestamp.
101Use in combination with --version=latest or --version=common. Use
102'date -d <date string> +%s' to find epoch time""")
raymes01959ae2013-02-15 04:50:07 +0000103 parser.add_option("--minilayout", dest="minilayout", default=False,
asharifdff61342013-02-15 04:50:46 +0000104 action="store_true",
llozano9efafde2013-02-23 01:37:04 +0000105 help="""Whether to checkout the minilayout
raymes01959ae2013-02-15 04:50:07 +0000106(smaller checkout).'""")
raymes69c8d722013-02-15 17:55:36 +0000107 parser.add_option("--jobs", "-j", dest="jobs", default="1",
108 help="Number of repo sync threads to use.")
asharifbf6899d2013-02-15 21:42:35 +0000109 parser.add_option("--public", "-p", dest="public", default=False,
110 action="store_true",
111 help="Use the public checkout instead of the private one.")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000112
asharif0d3535a2013-02-15 04:50:33 +0000113 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +0000114
asharifbf6899d2013-02-15 21:42:35 +0000115 if not options.version:
116 parser.print_help()
117 logger.GetLogger().LogFatal("No version specified.")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000118 else:
119 version = options.version.strip()
120
yunlian3802fbf2013-02-19 19:58:44 +0000121 if not options.timestamp:
122 timestamp = ""
123 else:
124 timestamp = options.timestamp.strip()
llozano9efafde2013-02-23 01:37:04 +0000125 if version not in ("lkgm", "common"):
126 parser.print_help()
127 logger.GetLogger().LogFatal("timestamp option only applies for "
128 "versions \"lkgm\" or \"common\"")
yunlian3802fbf2013-02-19 19:58:44 +0000129
asharifbf6899d2013-02-15 21:42:35 +0000130 if not options.directory:
131 parser.print_help()
132 logger.GetLogger().LogFatal("No directory specified.")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000133
134 directory = options.directory.strip()
135
asharifbf6899d2013-02-15 21:42:35 +0000136 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
yunlian3802fbf2013-02-19 19:58:44 +0000145 if version == "top":
asharifbf6899d2013-02-15 21:42:35 +0000146 init = "repo init -u %s" % manifest_repo
llozano9efafde2013-02-23 01:37:04 +0000147 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))
raymes69c8d722013-02-15 17:55:36 +0000182 else:
llozano9efafde2013-02-23 01:37:04 +0000183 # user specified a specific version number
shenhan9c39a842013-02-16 03:14:07 +0000184 version, manifest = version.split(".", 1)
llozano54bef9a2013-02-19 19:42:41 +0000185 init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % (
llozano9efafde2013-02-23 01:37:04 +0000186 versions_repo, version, manifest))
187
yunlian3802fbf2013-02-19 19:58:44 +0000188 if options.minilayout:
yunlian992a4902013-02-19 20:19:25 +0000189 init += " -g minilayout"
yunlian3802fbf2013-02-19 19:58:44 +0000190
asharif731e2932013-02-15 21:20:10 +0000191 init += " --repo-url=http://git.chromium.org/external/repo.git"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000192
asharifbf6899d2013-02-15 21:42:35 +0000193 commands = ["mkdir -p %s" % directory,
194 "cd %s" % directory,
195 init,
shenhanb7ff88b2013-02-19 20:42:48 +0000196 # crosbug#31837 - "Sources need to be world-readable to properly
197 # function inside the chroot"
198 "umask 022 && repo sync -j %s" % options.jobs]
asharifbf6899d2013-02-15 21:42:35 +0000199 cmd_executer = command_executer.GetCommandExecuter()
200 ret = cmd_executer.RunCommands(commands)
201 if ret:
202 return ret
bjanakiraman7f4a4852013-02-15 04:35:28 +0000203
raymese91a6e62013-02-15 04:35:51 +0000204 # Setup svn credentials for use inside the chroot
asharifca35b772013-02-15 04:56:41 +0000205 if getpass.getuser() == "mobiletc-prebuild":
206 chromium_username = "raymes"
207 else:
208 chromium_username = "$USER"
raymesbfb57992013-02-15 04:35:45 +0000209
asharifbf6899d2013-02-15 21:42:35 +0000210 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")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000218
219
220if __name__ == "__main__":
asharif2198c512013-02-15 09:21:35 +0000221 retval = Main(sys.argv)
222 sys.exit(retval)