blob: 1ee5dfd2a5e8fffee4a43194fb34e8784e861df1 [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
asharifca35b772013-02-15 04:56:41 +000013import getpass
bjanakiraman7f4a4852013-02-15 04:35:28 +000014import optparse
raymesbfb57992013-02-15 04:35:45 +000015import os
bjanakiraman7f4a4852013-02-15 04:35:28 +000016import sys
raymes01959ae2013-02-15 04:50:07 +000017from utils import command_executer
bjanakiraman7f4a4852013-02-15 04:35:28 +000018
raymesbfb57992013-02-15 04:35:45 +000019GCLIENT_FILE = """solutions = [
20 { "name" : "CHROME_DEPS",
21 "url" :
22 "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s",
23 "custom_deps" : {
24 "src/third_party/WebKit/LayoutTests": None,
25 "src-pdf": None,
26 "src/pdf": None,
27 },
28 "safesync_url": "",
29 },
30]
31"""
32
bjanakiraman7f4a4852013-02-15 04:35:28 +000033# Common initializations
asharif5a9bb462013-02-15 04:50:57 +000034cmd_executer = None
bjanakiraman7f4a4852013-02-15 04:35:28 +000035
36GIT_TAGS_CMD = ("git ls-remote --tags "
37 "ssh://git@gitrw.chromium.org:9222/chromiumos-overlay.git | "
38 "grep refs/tags/ | grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | "
raymesd1eed802013-02-15 04:36:08 +000039 "cut -d '/' -f 3")
bjanakiraman7f4a4852013-02-15 04:35:28 +000040
41
raymesbfb57992013-02-15 04:35:45 +000042def StoreFile(filename, contents):
43 f = open(filename, "w")
44 f.write(contents)
45 f.close()
46
47
bjanakiraman7f4a4852013-02-15 04:35:28 +000048def Usage(parser):
49 parser.print_help()
50 sys.exit(0)
51
52
53def GetTags():
raymes01959ae2013-02-15 04:50:07 +000054 res = cmd_executer.RunCommand(GIT_TAGS_CMD, True)
bjanakiraman7f4a4852013-02-15 04:35:28 +000055 return res[1].strip().split("\n")
56
57
raymesd1eed802013-02-15 04:36:08 +000058def GetLatestTag(tags):
59 latest = tags[0]
60 for tag in tags:
61 current_components = tag.split(".")
62 latest_components = latest.split(".")
63 for i in range(len(current_components)):
64 if int(current_components[i]) > int(latest_components[i]):
65 latest = tag
66 break
67 elif int(current_components[i]) < int(latest_components[i]):
68 break
69
70 return latest
71
72
asharif0d3535a2013-02-15 04:50:33 +000073def Main(argv):
bjanakiraman7f4a4852013-02-15 04:35:28 +000074 """Checkout the ChromeOS source."""
asharif5a9bb462013-02-15 04:50:57 +000075 global cmd_executer
76 cmd_executer = command_executer.GetCommandExecuter()
bjanakiraman7f4a4852013-02-15 04:35:28 +000077 parser = optparse.OptionParser()
78 parser.add_option("--dir", dest="directory",
79 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000080 parser.add_option("--version", dest="version", default="latest",
bjanakiraman7f4a4852013-02-15 04:35:28 +000081 help="""ChromeOS version. Can be: (1) A release version
82in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
83'top' for top of trunk. Default is 'latest'""")
raymes01959ae2013-02-15 04:50:07 +000084 parser.add_option("--minilayout", dest="minilayout", default=False,
asharifdff61342013-02-15 04:50:46 +000085 action="store_true",
raymes01959ae2013-02-15 04:50:07 +000086 help="""Whether to checkout the minilayout
87(smaller checkout).'""")
bjanakiraman7f4a4852013-02-15 04:35:28 +000088
asharif0d3535a2013-02-15 04:50:33 +000089 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000090
raymesd1eed802013-02-15 04:36:08 +000091 tags = GetTags()
92
bjanakiraman7f4a4852013-02-15 04:35:28 +000093 if options.version == "latest":
raymesd1eed802013-02-15 04:36:08 +000094 version = GetLatestTag(tags)
bjanakiraman7f4a4852013-02-15 04:35:28 +000095 print version
96 elif options.version == "top":
raymes04164a12013-02-15 04:36:03 +000097 version = "top"
bjanakiraman7f4a4852013-02-15 04:35:28 +000098 elif options.version is None:
raymesd1eed802013-02-15 04:36:08 +000099 print "No version specified"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000100 Usage(parser)
101 else:
102 version = options.version.strip()
103
raymes04164a12013-02-15 04:36:03 +0000104 if not version in tags and version != "top":
bjanakiraman7f4a4852013-02-15 04:35:28 +0000105 print "Version: '" + version + "' does not exist"
106 Usage(parser)
107
108 if options.directory is None:
109 print "Please give a valid directory"
110 Usage(parser)
111
112 directory = options.directory.strip()
113
raymes04164a12013-02-15 04:36:03 +0000114 if version == "top":
raymese91a6e62013-02-15 04:35:51 +0000115 branch = "master"
116 else:
117 branch = ".".join(version.split(".")[0:-1]) + ".B"
118
119 # Don't checkout chrome sources outside the chroot at the moment.
120 # If we check them out outside, we can't do some things, like build tests.
121 checkout_chrome_outside_chroot = False
bjanakiraman7f4a4852013-02-15 04:35:28 +0000122
raymes01959ae2013-02-15 04:50:07 +0000123 minilayout = ""
124 if options.minilayout == True:
125 minilayout = " -m minilayout.xml"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000126 commands = []
127 commands.append("mkdir -p " + directory)
128 commands.append("cd " + directory)
129 commands.append("repo init -u "
130 "ssh://git@gitrw.chromium.org:9222/manifest-internal -b "
raymes01959ae2013-02-15 04:50:07 +0000131 + branch + minilayout)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000132 commands.append("repo sync -j10")
raymes04164a12013-02-15 04:36:03 +0000133 if branch != "master":
134 commands.append("repo forall -c 'git checkout -f -b %s %s'"
135 % (branch, version))
raymes01959ae2013-02-15 04:50:07 +0000136 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000137
138 commands = []
139 commands.append("cd " + directory + "/src/scripts")
140 commands.append("./get_svn_repos.sh")
raymes01959ae2013-02-15 04:50:07 +0000141 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000142
raymese91a6e62013-02-15 04:35:51 +0000143 # Setup svn credentials for use inside the chroot
asharifca35b772013-02-15 04:56:41 +0000144 if getpass.getuser() == "mobiletc-prebuild":
145 chromium_username = "raymes"
146 else:
147 chromium_username = "$USER"
raymes01959ae2013-02-15 04:50:07 +0000148 cmd_executer.RunCommand("svn ls --config-option config:auth:password-stores= "
149 "--config-option "
150 "servers:global:store-plaintext-passwords=yes "
asharifca35b772013-02-15 04:56:41 +0000151 "--username " + chromium_username + "@google.com "
raymes01959ae2013-02-15 04:50:07 +0000152 "svn://svn.chromium.org/leapfrog-internal "
153 "svn://svn.chromium.org/chrome "
154 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000155
raymese91a6e62013-02-15 04:35:51 +0000156 if checkout_chrome_outside_chroot:
157 # Find Chrome browser version
raymes01959ae2013-02-15 04:50:07 +0000158 chrome_version = cmd_executer.RunCommand("%s/src/scripts/"
159 "chromeos_version.sh | "
160 "grep CHROME_BUILD"
161 % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000162
raymese91a6e62013-02-15 04:35:51 +0000163 chrome_version = chrome_version[1].strip().split("=")
164 if len(chrome_version) == 2:
165 chrome_version = chrome_version[1]
166 else:
167 chrome_version = ""
168
169 # Checkout chrome
raymes01959ae2013-02-15 04:50:07 +0000170 cmd_executer.RunCommand("mkdir -p %s/chrome_browser/" % directory)
raymese91a6e62013-02-15 04:35:51 +0000171 gclient_file = GCLIENT_FILE % chrome_version
172 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
173 % directory), gclient_file)
174 commands = []
175 commands.append("cd " + options.directory)
176 commands.append("cd chrome_browser")
177 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
raymes01959ae2013-02-15 04:50:07 +0000178 cmd_executer.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000179
bjanakiraman7f4a4852013-02-15 04:35:28 +0000180 print "Done"
181
182
183if __name__ == "__main__":
asharif0d3535a2013-02-15 04:50:33 +0000184 Main(sys.argv)