blob: ea824fbd3b94bb3e7de97a99994fc1d91844ee92 [file] [log] [blame]
bjanakiraman7f4a4852013-02-15 04:35:28 +00001#!/usr/bin/python2.6
2#
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
13import optparse
raymesbfb57992013-02-15 04:35:45 +000014import os
bjanakiraman7f4a4852013-02-15 04:35:28 +000015import sys
raymes01959ae2013-02-15 04:50:07 +000016from utils import command_executer
bjanakiraman7f4a4852013-02-15 04:35:28 +000017
raymesbfb57992013-02-15 04:35:45 +000018GCLIENT_FILE = """solutions = [
19 { "name" : "CHROME_DEPS",
20 "url" :
21 "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s",
22 "custom_deps" : {
23 "src/third_party/WebKit/LayoutTests": None,
24 "src-pdf": None,
25 "src/pdf": None,
26 },
27 "safesync_url": "",
28 },
29]
30"""
31
bjanakiraman7f4a4852013-02-15 04:35:28 +000032# Common initializations
raymes01959ae2013-02-15 04:50:07 +000033cmd_executer = command_executer.GetCommandExecuter()
bjanakiraman7f4a4852013-02-15 04:35:28 +000034
35GIT_TAGS_CMD = ("git ls-remote --tags "
36 "ssh://git@gitrw.chromium.org:9222/chromiumos-overlay.git | "
37 "grep refs/tags/ | grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | "
raymesd1eed802013-02-15 04:36:08 +000038 "cut -d '/' -f 3")
bjanakiraman7f4a4852013-02-15 04:35:28 +000039
40
raymesbfb57992013-02-15 04:35:45 +000041def StoreFile(filename, contents):
42 f = open(filename, "w")
43 f.write(contents)
44 f.close()
45
46
bjanakiraman7f4a4852013-02-15 04:35:28 +000047def Usage(parser):
48 parser.print_help()
49 sys.exit(0)
50
51
52def GetTags():
raymes01959ae2013-02-15 04:50:07 +000053 res = cmd_executer.RunCommand(GIT_TAGS_CMD, True)
bjanakiraman7f4a4852013-02-15 04:35:28 +000054 return res[1].strip().split("\n")
55
56
raymesd1eed802013-02-15 04:36:08 +000057def GetLatestTag(tags):
58 latest = tags[0]
59 for tag in tags:
60 current_components = tag.split(".")
61 latest_components = latest.split(".")
62 for i in range(len(current_components)):
63 if int(current_components[i]) > int(latest_components[i]):
64 latest = tag
65 break
66 elif int(current_components[i]) < int(latest_components[i]):
67 break
68
69 return latest
70
71
asharif0d3535a2013-02-15 04:50:33 +000072def Main(argv):
bjanakiraman7f4a4852013-02-15 04:35:28 +000073 """Checkout the ChromeOS source."""
74 parser = optparse.OptionParser()
75 parser.add_option("--dir", dest="directory",
76 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000077 parser.add_option("--version", dest="version", default="latest",
bjanakiraman7f4a4852013-02-15 04:35:28 +000078 help="""ChromeOS version. Can be: (1) A release version
79in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
80'top' for top of trunk. Default is 'latest'""")
raymes01959ae2013-02-15 04:50:07 +000081 parser.add_option("--minilayout", dest="minilayout", default=False,
82 help="""Whether to checkout the minilayout
83(smaller checkout).'""")
bjanakiraman7f4a4852013-02-15 04:35:28 +000084
asharif0d3535a2013-02-15 04:50:33 +000085 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000086
raymesd1eed802013-02-15 04:36:08 +000087 tags = GetTags()
88
bjanakiraman7f4a4852013-02-15 04:35:28 +000089 if options.version == "latest":
raymesd1eed802013-02-15 04:36:08 +000090 version = GetLatestTag(tags)
bjanakiraman7f4a4852013-02-15 04:35:28 +000091 print version
92 elif options.version == "top":
raymes04164a12013-02-15 04:36:03 +000093 version = "top"
bjanakiraman7f4a4852013-02-15 04:35:28 +000094 elif options.version is None:
raymesd1eed802013-02-15 04:36:08 +000095 print "No version specified"
bjanakiraman7f4a4852013-02-15 04:35:28 +000096 Usage(parser)
97 else:
98 version = options.version.strip()
99
raymes04164a12013-02-15 04:36:03 +0000100 if not version in tags and version != "top":
bjanakiraman7f4a4852013-02-15 04:35:28 +0000101 print "Version: '" + version + "' does not exist"
102 Usage(parser)
103
104 if options.directory is None:
105 print "Please give a valid directory"
106 Usage(parser)
107
108 directory = options.directory.strip()
109
raymes04164a12013-02-15 04:36:03 +0000110 if version == "top":
raymese91a6e62013-02-15 04:35:51 +0000111 branch = "master"
112 else:
113 branch = ".".join(version.split(".")[0:-1]) + ".B"
114
115 # Don't checkout chrome sources outside the chroot at the moment.
116 # If we check them out outside, we can't do some things, like build tests.
117 checkout_chrome_outside_chroot = False
bjanakiraman7f4a4852013-02-15 04:35:28 +0000118
raymes01959ae2013-02-15 04:50:07 +0000119 minilayout = ""
120 if options.minilayout == True:
121 minilayout = " -m minilayout.xml"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000122 commands = []
123 commands.append("mkdir -p " + directory)
124 commands.append("cd " + directory)
125 commands.append("repo init -u "
126 "ssh://git@gitrw.chromium.org:9222/manifest-internal -b "
raymes01959ae2013-02-15 04:50:07 +0000127 + branch + minilayout)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000128 commands.append("repo sync -j10")
raymes04164a12013-02-15 04:36:03 +0000129 if branch != "master":
130 commands.append("repo forall -c 'git checkout -f -b %s %s'"
131 % (branch, version))
raymes01959ae2013-02-15 04:50:07 +0000132 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000133
134 commands = []
135 commands.append("cd " + directory + "/src/scripts")
136 commands.append("./get_svn_repos.sh")
raymes01959ae2013-02-15 04:50:07 +0000137 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000138
raymese91a6e62013-02-15 04:35:51 +0000139 # Setup svn credentials for use inside the chroot
raymes01959ae2013-02-15 04:50:07 +0000140 cmd_executer.RunCommand("svn ls --config-option config:auth:password-stores= "
141 "--config-option "
142 "servers:global:store-plaintext-passwords=yes "
143 "--username $USER@google.com "
144 "svn://svn.chromium.org/leapfrog-internal "
145 "svn://svn.chromium.org/chrome "
146 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000147
raymese91a6e62013-02-15 04:35:51 +0000148 if checkout_chrome_outside_chroot:
149 # Find Chrome browser version
raymes01959ae2013-02-15 04:50:07 +0000150 chrome_version = cmd_executer.RunCommand("%s/src/scripts/"
151 "chromeos_version.sh | "
152 "grep CHROME_BUILD"
153 % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000154
raymese91a6e62013-02-15 04:35:51 +0000155 chrome_version = chrome_version[1].strip().split("=")
156 if len(chrome_version) == 2:
157 chrome_version = chrome_version[1]
158 else:
159 chrome_version = ""
160
161 # Checkout chrome
raymes01959ae2013-02-15 04:50:07 +0000162 cmd_executer.RunCommand("mkdir -p %s/chrome_browser/" % directory)
raymese91a6e62013-02-15 04:35:51 +0000163 gclient_file = GCLIENT_FILE % chrome_version
164 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
165 % directory), gclient_file)
166 commands = []
167 commands.append("cd " + options.directory)
168 commands.append("cd chrome_browser")
169 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
raymes01959ae2013-02-15 04:50:07 +0000170 cmd_executer.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000171
bjanakiraman7f4a4852013-02-15 04:35:28 +0000172 print "Done"
173
174
175if __name__ == "__main__":
asharif0d3535a2013-02-15 04:50:33 +0000176 Main(sys.argv)