blob: 92573372a134fb9b1a74256ccc3e1292defb7704 [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
asharif911bd272013-02-15 09:04:48 +000014import multiprocessing
bjanakiraman7f4a4852013-02-15 04:35:28 +000015import optparse
raymesbfb57992013-02-15 04:35:45 +000016import os
bjanakiraman7f4a4852013-02-15 04:35:28 +000017import sys
raymes01959ae2013-02-15 04:50:07 +000018from utils import command_executer
bjanakiraman7f4a4852013-02-15 04:35:28 +000019
raymesbfb57992013-02-15 04:35:45 +000020GCLIENT_FILE = """solutions = [
21 { "name" : "CHROME_DEPS",
22 "url" :
23 "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s",
24 "custom_deps" : {
25 "src/third_party/WebKit/LayoutTests": None,
26 "src-pdf": None,
27 "src/pdf": None,
28 },
29 "safesync_url": "",
30 },
31]
32"""
33
bjanakiraman7f4a4852013-02-15 04:35:28 +000034# Common initializations
asharif5a9bb462013-02-15 04:50:57 +000035cmd_executer = None
bjanakiraman7f4a4852013-02-15 04:35:28 +000036
37GIT_TAGS_CMD = ("git ls-remote --tags "
38 "ssh://git@gitrw.chromium.org:9222/chromiumos-overlay.git | "
39 "grep refs/tags/ | grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | "
raymesd1eed802013-02-15 04:36:08 +000040 "cut -d '/' -f 3")
bjanakiraman7f4a4852013-02-15 04:35:28 +000041
42
raymesbfb57992013-02-15 04:35:45 +000043def StoreFile(filename, contents):
44 f = open(filename, "w")
45 f.write(contents)
46 f.close()
47
48
bjanakiraman7f4a4852013-02-15 04:35:28 +000049def Usage(parser):
50 parser.print_help()
51 sys.exit(0)
52
53
54def GetTags():
raymes01959ae2013-02-15 04:50:07 +000055 res = cmd_executer.RunCommand(GIT_TAGS_CMD, True)
bjanakiraman7f4a4852013-02-15 04:35:28 +000056 return res[1].strip().split("\n")
57
58
raymesd1eed802013-02-15 04:36:08 +000059def GetLatestTag(tags):
60 latest = tags[0]
61 for tag in tags:
62 current_components = tag.split(".")
63 latest_components = latest.split(".")
64 for i in range(len(current_components)):
65 if int(current_components[i]) > int(latest_components[i]):
66 latest = tag
67 break
68 elif int(current_components[i]) < int(latest_components[i]):
69 break
70
71 return latest
72
73
asharif0d3535a2013-02-15 04:50:33 +000074def Main(argv):
bjanakiraman7f4a4852013-02-15 04:35:28 +000075 """Checkout the ChromeOS source."""
asharif5a9bb462013-02-15 04:50:57 +000076 global cmd_executer
77 cmd_executer = command_executer.GetCommandExecuter()
bjanakiraman7f4a4852013-02-15 04:35:28 +000078 parser = optparse.OptionParser()
79 parser.add_option("--dir", dest="directory",
80 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000081 parser.add_option("--version", dest="version", default="latest",
bjanakiraman7f4a4852013-02-15 04:35:28 +000082 help="""ChromeOS version. Can be: (1) A release version
83in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
84'top' for top of trunk. Default is 'latest'""")
raymes01959ae2013-02-15 04:50:07 +000085 parser.add_option("--minilayout", dest="minilayout", default=False,
asharifdff61342013-02-15 04:50:46 +000086 action="store_true",
raymes01959ae2013-02-15 04:50:07 +000087 help="""Whether to checkout the minilayout
88(smaller checkout).'""")
bjanakiraman7f4a4852013-02-15 04:35:28 +000089
asharif0d3535a2013-02-15 04:50:33 +000090 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000091
raymesd1eed802013-02-15 04:36:08 +000092 tags = GetTags()
93
bjanakiraman7f4a4852013-02-15 04:35:28 +000094 if options.version == "latest":
raymesd1eed802013-02-15 04:36:08 +000095 version = GetLatestTag(tags)
bjanakiraman7f4a4852013-02-15 04:35:28 +000096 print version
97 elif options.version == "top":
raymes04164a12013-02-15 04:36:03 +000098 version = "top"
bjanakiraman7f4a4852013-02-15 04:35:28 +000099 elif options.version is None:
raymesd1eed802013-02-15 04:36:08 +0000100 print "No version specified"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000101 Usage(parser)
102 else:
103 version = options.version.strip()
104
raymes04164a12013-02-15 04:36:03 +0000105 if not version in tags and version != "top":
bjanakiraman7f4a4852013-02-15 04:35:28 +0000106 print "Version: '" + version + "' does not exist"
107 Usage(parser)
108
109 if options.directory is None:
110 print "Please give a valid directory"
111 Usage(parser)
112
113 directory = options.directory.strip()
114
raymese91a6e62013-02-15 04:35:51 +0000115 # 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 "
asharif911bd272013-02-15 09:04:48 +0000126 "ssh://git@gitrw.chromium.org:9222/manifest-internal"
127 + minilayout)
128 commands.append("repo sync -j" + str(multiprocessing.cpu_count() + 1))
129 if version != "top":
130 commands.append("repo forall -c 'git checkout -f %s'" % version)
raymes01959ae2013-02-15 04:50:07 +0000131 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000132
raymese91a6e62013-02-15 04:35:51 +0000133 # Setup svn credentials for use inside the chroot
asharifca35b772013-02-15 04:56:41 +0000134 if getpass.getuser() == "mobiletc-prebuild":
135 chromium_username = "raymes"
136 else:
137 chromium_username = "$USER"
raymes01959ae2013-02-15 04:50:07 +0000138 cmd_executer.RunCommand("svn ls --config-option config:auth:password-stores= "
139 "--config-option "
140 "servers:global:store-plaintext-passwords=yes "
asharifca35b772013-02-15 04:56:41 +0000141 "--username " + chromium_username + "@google.com "
raymes01959ae2013-02-15 04:50:07 +0000142 "svn://svn.chromium.org/leapfrog-internal "
143 "svn://svn.chromium.org/chrome "
144 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000145
raymese91a6e62013-02-15 04:35:51 +0000146 if checkout_chrome_outside_chroot:
147 # Find Chrome browser version
raymes01959ae2013-02-15 04:50:07 +0000148 chrome_version = cmd_executer.RunCommand("%s/src/scripts/"
149 "chromeos_version.sh | "
150 "grep CHROME_BUILD"
151 % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000152
raymese91a6e62013-02-15 04:35:51 +0000153 chrome_version = chrome_version[1].strip().split("=")
154 if len(chrome_version) == 2:
155 chrome_version = chrome_version[1]
156 else:
157 chrome_version = ""
158
159 # Checkout chrome
raymes01959ae2013-02-15 04:50:07 +0000160 cmd_executer.RunCommand("mkdir -p %s/chrome_browser/" % directory)
raymese91a6e62013-02-15 04:35:51 +0000161 gclient_file = GCLIENT_FILE % chrome_version
162 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
163 % directory), gclient_file)
164 commands = []
165 commands.append("cd " + options.directory)
166 commands.append("cd chrome_browser")
167 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
raymes01959ae2013-02-15 04:50:07 +0000168 cmd_executer.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000169
bjanakiraman7f4a4852013-02-15 04:35:28 +0000170 print "Done"
171
172
173if __name__ == "__main__":
asharif0d3535a2013-02-15 04:50:33 +0000174 Main(sys.argv)