blob: 73d1a7ce17a141fed4416c1bbd830d5665dcef20 [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
16from utils import utils
17
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
33(rootdir, basename) = utils.GetRoot(sys.argv[0])
34utils.InitLogger(rootdir, basename)
35
36
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]*' | "
40 "cut -d '/' -f 3 | sort -nr")
41
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():
raymes5154d7f2013-02-15 04:35:37 +000055 res = utils.RunCommand(GIT_TAGS_CMD, True)
bjanakiraman7f4a4852013-02-15 04:35:28 +000056 return res[1].strip().split("\n")
57
58
59def Main():
60 """Checkout the ChromeOS source."""
61 parser = optparse.OptionParser()
62 parser.add_option("--dir", dest="directory",
63 help="Target directory for ChromeOS installation.")
64 parser.add_option("--version", dest="version",
65 help="""ChromeOS version. Can be: (1) A release version
66in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
67'top' for top of trunk. Default is 'latest'""")
68
69 tags = GetTags()
70
71 options = parser.parse_args()[0]
72
73 if options.version == "latest":
74 version = tags[0]
75 print version
76 elif options.version == "top":
raymes04164a12013-02-15 04:36:03 +000077 version = "top"
bjanakiraman7f4a4852013-02-15 04:35:28 +000078 elif options.version is None:
79 Usage(parser)
80 else:
81 version = options.version.strip()
82
raymes04164a12013-02-15 04:36:03 +000083 if not version in tags and version != "top":
bjanakiraman7f4a4852013-02-15 04:35:28 +000084 print "Version: '" + version + "' does not exist"
85 Usage(parser)
86
87 if options.directory is None:
88 print "Please give a valid directory"
89 Usage(parser)
90
91 directory = options.directory.strip()
92
raymes04164a12013-02-15 04:36:03 +000093 if version == "top":
raymese91a6e62013-02-15 04:35:51 +000094 branch = "master"
95 else:
96 branch = ".".join(version.split(".")[0:-1]) + ".B"
97
98 # Don't checkout chrome sources outside the chroot at the moment.
99 # If we check them out outside, we can't do some things, like build tests.
100 checkout_chrome_outside_chroot = False
bjanakiraman7f4a4852013-02-15 04:35:28 +0000101
102 commands = []
103 commands.append("mkdir -p " + directory)
104 commands.append("cd " + directory)
105 commands.append("repo init -u "
106 "ssh://git@gitrw.chromium.org:9222/manifest-internal -b "
107 + branch)
108 commands.append("repo sync -j10")
raymes04164a12013-02-15 04:36:03 +0000109 if branch != "master":
110 commands.append("repo forall -c 'git checkout -f -b %s %s'"
111 % (branch, version))
bjanakiraman7f4a4852013-02-15 04:35:28 +0000112 utils.RunCommands(commands)
113
114 commands = []
115 commands.append("cd " + directory + "/src/scripts")
116 commands.append("./get_svn_repos.sh")
117 utils.RunCommands(commands)
118
raymese91a6e62013-02-15 04:35:51 +0000119 # Setup svn credentials for use inside the chroot
120 utils.RunCommand("svn ls --config-option config:auth:password-stores= "
121 "--config-option "
122 "servers:global:store-plaintext-passwords=yes "
123 "--username $USER@google.com "
124 "svn://svn.chromium.org/leapfrog-internal "
125 "svn://svn.chromium.org/chrome "
126 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000127
raymese91a6e62013-02-15 04:35:51 +0000128 if checkout_chrome_outside_chroot:
129 # Find Chrome browser version
130 chrome_version = utils.RunCommand("%s/src/scripts/chromeos_version.sh | "
131 "grep CHROME_BUILD" % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000132
raymese91a6e62013-02-15 04:35:51 +0000133 chrome_version = chrome_version[1].strip().split("=")
134 if len(chrome_version) == 2:
135 chrome_version = chrome_version[1]
136 else:
137 chrome_version = ""
138
139 # Checkout chrome
140 utils.RunCommand("mkdir -p %s/chrome_browser/" % directory)
141 gclient_file = GCLIENT_FILE % chrome_version
142 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
143 % directory), gclient_file)
144 commands = []
145 commands.append("cd " + options.directory)
146 commands.append("cd chrome_browser")
147 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
148 utils.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000149
bjanakiraman7f4a4852013-02-15 04:35:28 +0000150 print "Done"
151
152
153if __name__ == "__main__":
154 Main()