blob: 4e5c3c681eb8d6c08f325d9ed6588d85f3237ed3 [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
14import sys
15from utils import utils
16
17# Common initializations
18(rootdir, basename) = utils.GetRoot(sys.argv[0])
19utils.InitLogger(rootdir, basename)
20
21
22GIT_TAGS_CMD = ("git ls-remote --tags "
23 "ssh://git@gitrw.chromium.org:9222/chromiumos-overlay.git | "
24 "grep refs/tags/ | grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | "
25 "cut -d '/' -f 3 | sort -nr")
26
27
28def Usage(parser):
29 parser.print_help()
30 sys.exit(0)
31
32
33def GetTags():
34 res = utils.DoCommand(GIT_TAGS_CMD)
35 return res[1].strip().split("\n")
36
37
38def Main():
39 """Checkout the ChromeOS source."""
40 parser = optparse.OptionParser()
41 parser.add_option("--dir", dest="directory",
42 help="Target directory for ChromeOS installation.")
43 parser.add_option("--version", dest="version",
44 help="""ChromeOS version. Can be: (1) A release version
45in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3)
46'top' for top of trunk. Default is 'latest'""")
47
48 tags = GetTags()
49
50 options = parser.parse_args()[0]
51
52 if options.version == "latest":
53 version = tags[0]
54 print version
55 elif options.version == "top":
56 version = ""
57 elif options.version is None:
58 Usage(parser)
59 else:
60 version = options.version.strip()
61
62 if not version in tags:
63 print "Version: '" + version + "' does not exist"
64 Usage(parser)
65
66 if options.directory is None:
67 print "Please give a valid directory"
68 Usage(parser)
69
70 directory = options.directory.strip()
71
72 branch = ".".join(version.split(".")[0:-1]) + ".B"
73
74 commands = []
75 commands.append("mkdir -p " + directory)
76 commands.append("cd " + directory)
77 commands.append("repo init -u "
78 "ssh://git@gitrw.chromium.org:9222/manifest-internal -b "
79 + branch)
80 commands.append("repo sync -j10")
81 commands.append("repo forall -c 'git checkout -f -b %s %s'"
82 % (branch, version))
83 utils.RunCommands(commands)
84
85 commands = []
86 commands.append("cd " + directory + "/src/scripts")
87 commands.append("./get_svn_repos.sh")
88 utils.RunCommands(commands)
89
90 print "Done"
91
92
93if __name__ == "__main__":
94 Main()