blob: bc4107a16145623ec5a3c710e6d81e551e9fe3ef [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
asharifca35b772013-02-15 04:56:41 +000013import getpass
bjanakiraman7f4a4852013-02-15 04:35:28 +000014import optparse
yunlian3802fbf2013-02-19 19:58:44 +000015import os
bjanakiraman7f4a4852013-02-15 04:35:28 +000016import sys
yunlian3802fbf2013-02-19 19:58:44 +000017import tempfile
18import time
raymes01959ae2013-02-15 04:50:07 +000019from utils import command_executer
raymes69c8d722013-02-15 17:55:36 +000020from utils import logger
bjanakiraman7f4a4852013-02-15 04:35:28 +000021
raymesbfb57992013-02-15 04:35:45 +000022GCLIENT_FILE = """solutions = [
23 { "name" : "CHROME_DEPS",
24 "url" :
25 "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s",
26 "custom_deps" : {
27 "src/third_party/WebKit/LayoutTests": None,
28 "src-pdf": None,
29 "src/pdf": None,
30 },
31 "safesync_url": "",
32 },
33]
34"""
35
bjanakiraman7f4a4852013-02-15 04:35:28 +000036def Usage(parser):
37 parser.print_help()
38 sys.exit(0)
39
40
yunlian3802fbf2013-02-19 19:58:44 +000041def TimeToVersion(my_time, versions_git):
42 """Convert timestamp to version number."""
43 cur_time = time.mktime(time.gmtime())
44 des_time = float(my_time)
45 if cur_time - des_time > 7000000:
46 logger.GetLogger().LogFatal("The time you specify is too early.")
47 temp = tempfile.mkdtemp()
48 commands = ["cd {0}".format(temp), "git clone {0}".format(versions_git),
49 "cd manifest-versions", "git checkout -f $(git rev-list" +
50 " --max-count=1 --before={0} origin/master)".format(my_time)]
51 cmd_executer = command_executer.GetCommandExecuter()
52 ret = cmd_executer.RunCommands(commands)
53 if ret:
54 return None
55 path = os.path.realpath("{0}/manifest-versions/LKGM/lkgm.xml".format(temp))
56 pp = path.split("/")
57 small = os.path.basename(path).split(".xml")[0]
58 version = pp[-2] + "." + small
59 commands = ["rm -rf {0}".format(temp)]
60 cmd_executer.RunCommands(commands)
61 return version
62
63
asharif0d3535a2013-02-15 04:50:33 +000064def Main(argv):
bjanakiraman7f4a4852013-02-15 04:35:28 +000065 """Checkout the ChromeOS source."""
66 parser = optparse.OptionParser()
67 parser.add_option("--dir", dest="directory",
68 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000069 parser.add_option("--version", dest="version", default="latest",
bjanakiraman7f4a4852013-02-15 04:35:28 +000070 help="""ChromeOS version. Can be: (1) A release version
71in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
72'top' for top of trunk. Default is 'latest'""")
yunlian3802fbf2013-02-19 19:58:44 +000073 parser.add_option("--timestamp", dest="timestamp", default=None,
74 help="""Timestamps in epoch format. It will check out the
75latest LKGM version of ChromeOS before the timestamp. It will also overide
76the version option.""")
raymes01959ae2013-02-15 04:50:07 +000077 parser.add_option("--minilayout", dest="minilayout", default=False,
asharifdff61342013-02-15 04:50:46 +000078 action="store_true",
raymes01959ae2013-02-15 04:50:07 +000079 help="""Whether to checkout the minilayout
80(smaller checkout).'""")
raymes69c8d722013-02-15 17:55:36 +000081 parser.add_option("--jobs", "-j", dest="jobs", default="1",
82 help="Number of repo sync threads to use.")
asharifbf6899d2013-02-15 21:42:35 +000083 parser.add_option("--public", "-p", dest="public", default=False,
84 action="store_true",
85 help="Use the public checkout instead of the private one.")
bjanakiraman7f4a4852013-02-15 04:35:28 +000086
asharif0d3535a2013-02-15 04:50:33 +000087 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000088
asharifbf6899d2013-02-15 21:42:35 +000089 if not options.version:
90 parser.print_help()
91 logger.GetLogger().LogFatal("No version specified.")
bjanakiraman7f4a4852013-02-15 04:35:28 +000092 else:
93 version = options.version.strip()
94
yunlian3802fbf2013-02-19 19:58:44 +000095 if not options.timestamp:
96 timestamp = ""
97 else:
98 timestamp = options.timestamp.strip()
99
asharifbf6899d2013-02-15 21:42:35 +0000100 if not options.directory:
101 parser.print_help()
102 logger.GetLogger().LogFatal("No directory specified.")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000103
104 directory = options.directory.strip()
105
asharifbf6899d2013-02-15 21:42:35 +0000106 if options.public:
107 manifest_repo = "http://git.chromium.org/chromiumos/manifest.git"
108 versions_repo = "http://git.chromium.org/chromiumos/manifest-versions.git"
109 else:
110 manifest_repo = (
111 "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git")
112 versions_repo = (
113 "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-versions.git")
114
yunlian3802fbf2013-02-19 19:58:44 +0000115 if timestamp:
116 my_version = TimeToVersion(timestamp, versions_repo)
117 if my_version:
118 version = my_version
119
120 if version == "top":
asharifbf6899d2013-02-15 21:42:35 +0000121 init = "repo init -u %s" % manifest_repo
raymes69c8d722013-02-15 17:55:36 +0000122 else:
yunlian3802fbf2013-02-19 19:58:44 +0000123 if version =="latest":
124 version = TimeToVersion(time.mktime(time.gmtime()), versions_repo)
shenhan9c39a842013-02-16 03:14:07 +0000125 version, manifest = version.split(".", 1)
llozano54bef9a2013-02-19 19:42:41 +0000126 init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % (
yunlian3802fbf2013-02-19 19:58:44 +0000127 versions_repo, version, manifest))
128 if options.minilayout:
yunlian992a4902013-02-19 20:19:25 +0000129 init += " -g minilayout"
yunlian3802fbf2013-02-19 19:58:44 +0000130
asharif731e2932013-02-15 21:20:10 +0000131 init += " --repo-url=http://git.chromium.org/external/repo.git"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000132
asharifbf6899d2013-02-15 21:42:35 +0000133 commands = ["mkdir -p %s" % directory,
134 "cd %s" % directory,
135 init,
shenhanb7ff88b2013-02-19 20:42:48 +0000136 # crosbug#31837 - "Sources need to be world-readable to properly
137 # function inside the chroot"
138 "umask 022 && repo sync -j %s" % options.jobs]
asharifbf6899d2013-02-15 21:42:35 +0000139 cmd_executer = command_executer.GetCommandExecuter()
140 ret = cmd_executer.RunCommands(commands)
141 if ret:
142 return ret
bjanakiraman7f4a4852013-02-15 04:35:28 +0000143
raymese91a6e62013-02-15 04:35:51 +0000144 # Setup svn credentials for use inside the chroot
asharifca35b772013-02-15 04:56:41 +0000145 if getpass.getuser() == "mobiletc-prebuild":
146 chromium_username = "raymes"
147 else:
148 chromium_username = "$USER"
raymesbfb57992013-02-15 04:35:45 +0000149
asharifbf6899d2013-02-15 21:42:35 +0000150 return cmd_executer.RunCommand(
151 "svn ls --config-option config:auth:password-stores= "
152 "--config-option "
153 "servers:global:store-plaintext-passwords=yes "
154 "--username " + chromium_username + "@google.com "
155 "svn://svn.chromium.org/leapfrog-internal "
156 "svn://svn.chromium.org/chrome "
157 "svn://svn.chromium.org/chrome-internal > /dev/null")
bjanakiraman7f4a4852013-02-15 04:35:28 +0000158
159
160if __name__ == "__main__":
asharif2198c512013-02-15 09:21:35 +0000161 retval = Main(sys.argv)
162 sys.exit(retval)