blob: 93f8aeff869bb3596fdf28fcba11c1eb2a5ff906 [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
asharif5a9bb462013-02-15 04:50:57 +000033cmd_executer = None
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."""
asharif5a9bb462013-02-15 04:50:57 +000074 global cmd_executer
75 cmd_executer = command_executer.GetCommandExecuter()
bjanakiraman7f4a4852013-02-15 04:35:28 +000076 parser = optparse.OptionParser()
77 parser.add_option("--dir", dest="directory",
78 help="Target directory for ChromeOS installation.")
raymesd1eed802013-02-15 04:36:08 +000079 parser.add_option("--version", dest="version", default="latest",
bjanakiraman7f4a4852013-02-15 04:35:28 +000080 help="""ChromeOS version. Can be: (1) A release version
81in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
82'top' for top of trunk. Default is 'latest'""")
raymes01959ae2013-02-15 04:50:07 +000083 parser.add_option("--minilayout", dest="minilayout", default=False,
asharifdff61342013-02-15 04:50:46 +000084 action="store_true",
raymes01959ae2013-02-15 04:50:07 +000085 help="""Whether to checkout the minilayout
86(smaller checkout).'""")
bjanakiraman7f4a4852013-02-15 04:35:28 +000087
asharif0d3535a2013-02-15 04:50:33 +000088 options = parser.parse_args(argv)[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000089
raymesd1eed802013-02-15 04:36:08 +000090 tags = GetTags()
91
bjanakiraman7f4a4852013-02-15 04:35:28 +000092 if options.version == "latest":
raymesd1eed802013-02-15 04:36:08 +000093 version = GetLatestTag(tags)
bjanakiraman7f4a4852013-02-15 04:35:28 +000094 print version
95 elif options.version == "top":
raymes04164a12013-02-15 04:36:03 +000096 version = "top"
bjanakiraman7f4a4852013-02-15 04:35:28 +000097 elif options.version is None:
raymesd1eed802013-02-15 04:36:08 +000098 print "No version specified"
bjanakiraman7f4a4852013-02-15 04:35:28 +000099 Usage(parser)
100 else:
101 version = options.version.strip()
102
raymes04164a12013-02-15 04:36:03 +0000103 if not version in tags and version != "top":
bjanakiraman7f4a4852013-02-15 04:35:28 +0000104 print "Version: '" + version + "' does not exist"
105 Usage(parser)
106
107 if options.directory is None:
108 print "Please give a valid directory"
109 Usage(parser)
110
111 directory = options.directory.strip()
112
raymes04164a12013-02-15 04:36:03 +0000113 if version == "top":
raymese91a6e62013-02-15 04:35:51 +0000114 branch = "master"
115 else:
116 branch = ".".join(version.split(".")[0:-1]) + ".B"
117
118 # Don't checkout chrome sources outside the chroot at the moment.
119 # If we check them out outside, we can't do some things, like build tests.
120 checkout_chrome_outside_chroot = False
bjanakiraman7f4a4852013-02-15 04:35:28 +0000121
raymes01959ae2013-02-15 04:50:07 +0000122 minilayout = ""
123 if options.minilayout == True:
124 minilayout = " -m minilayout.xml"
bjanakiraman7f4a4852013-02-15 04:35:28 +0000125 commands = []
126 commands.append("mkdir -p " + directory)
127 commands.append("cd " + directory)
128 commands.append("repo init -u "
129 "ssh://git@gitrw.chromium.org:9222/manifest-internal -b "
raymes01959ae2013-02-15 04:50:07 +0000130 + branch + minilayout)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000131 commands.append("repo sync -j10")
raymes04164a12013-02-15 04:36:03 +0000132 if branch != "master":
133 commands.append("repo forall -c 'git checkout -f -b %s %s'"
134 % (branch, version))
raymes01959ae2013-02-15 04:50:07 +0000135 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000136
137 commands = []
138 commands.append("cd " + directory + "/src/scripts")
139 commands.append("./get_svn_repos.sh")
raymes01959ae2013-02-15 04:50:07 +0000140 cmd_executer.RunCommands(commands)
bjanakiraman7f4a4852013-02-15 04:35:28 +0000141
raymese91a6e62013-02-15 04:35:51 +0000142 # Setup svn credentials for use inside the chroot
raymes01959ae2013-02-15 04:50:07 +0000143 cmd_executer.RunCommand("svn ls --config-option config:auth:password-stores= "
144 "--config-option "
145 "servers:global:store-plaintext-passwords=yes "
146 "--username $USER@google.com "
147 "svn://svn.chromium.org/leapfrog-internal "
148 "svn://svn.chromium.org/chrome "
149 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000150
raymese91a6e62013-02-15 04:35:51 +0000151 if checkout_chrome_outside_chroot:
152 # Find Chrome browser version
raymes01959ae2013-02-15 04:50:07 +0000153 chrome_version = cmd_executer.RunCommand("%s/src/scripts/"
154 "chromeos_version.sh | "
155 "grep CHROME_BUILD"
156 % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000157
raymese91a6e62013-02-15 04:35:51 +0000158 chrome_version = chrome_version[1].strip().split("=")
159 if len(chrome_version) == 2:
160 chrome_version = chrome_version[1]
161 else:
162 chrome_version = ""
163
164 # Checkout chrome
raymes01959ae2013-02-15 04:50:07 +0000165 cmd_executer.RunCommand("mkdir -p %s/chrome_browser/" % directory)
raymese91a6e62013-02-15 04:35:51 +0000166 gclient_file = GCLIENT_FILE % chrome_version
167 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
168 % directory), gclient_file)
169 commands = []
170 commands.append("cd " + options.directory)
171 commands.append("cd chrome_browser")
172 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
raymes01959ae2013-02-15 04:50:07 +0000173 cmd_executer.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000174
bjanakiraman7f4a4852013-02-15 04:35:28 +0000175 print "Done"
176
177
178if __name__ == "__main__":
asharif0d3535a2013-02-15 04:50:33 +0000179 Main(sys.argv)