blob: cd2bf876a627268908d2f6bac05a75804f7be5c8 [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":
77 version = ""
78 elif options.version is None:
79 Usage(parser)
80 else:
81 version = options.version.strip()
82
83 if not version in tags:
84 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
raymese91a6e62013-02-15 04:35:51 +000093 if version == "":
94 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")
109 commands.append("repo forall -c 'git checkout -f -b %s %s'"
110 % (branch, version))
111 utils.RunCommands(commands)
112
113 commands = []
114 commands.append("cd " + directory + "/src/scripts")
115 commands.append("./get_svn_repos.sh")
116 utils.RunCommands(commands)
117
raymese91a6e62013-02-15 04:35:51 +0000118 # Setup svn credentials for use inside the chroot
119 utils.RunCommand("svn ls --config-option config:auth:password-stores= "
120 "--config-option "
121 "servers:global:store-plaintext-passwords=yes "
122 "--username $USER@google.com "
123 "svn://svn.chromium.org/leapfrog-internal "
124 "svn://svn.chromium.org/chrome "
125 "svn://svn.chromium.org/chrome-internal > /dev/null")
raymesbfb57992013-02-15 04:35:45 +0000126
raymese91a6e62013-02-15 04:35:51 +0000127 if checkout_chrome_outside_chroot:
128 # Find Chrome browser version
129 chrome_version = utils.RunCommand("%s/src/scripts/chromeos_version.sh | "
130 "grep CHROME_BUILD" % directory, True)
raymesbfb57992013-02-15 04:35:45 +0000131
raymese91a6e62013-02-15 04:35:51 +0000132 chrome_version = chrome_version[1].strip().split("=")
133 if len(chrome_version) == 2:
134 chrome_version = chrome_version[1]
135 else:
136 chrome_version = ""
137
138 # Checkout chrome
139 utils.RunCommand("mkdir -p %s/chrome_browser/" % directory)
140 gclient_file = GCLIENT_FILE % chrome_version
141 StoreFile(os.path.expanduser("%s/chrome_browser/.gclient"
142 % directory), gclient_file)
143 commands = []
144 commands.append("cd " + options.directory)
145 commands.append("cd chrome_browser")
146 commands.append("gclient sync -v --nohooks --delete_unversioned_trees")
147 utils.RunCommands(commands)
raymesbfb57992013-02-15 04:35:45 +0000148
bjanakiraman7f4a4852013-02-15 04:35:28 +0000149 print "Done"
150
151
152if __name__ == "__main__":
153 Main()