bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.6 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to checkout the ChromeOS source. |
| 6 | |
| 7 | This script sets up the ChromeOS source in the given directory, matching a |
| 8 | particular release of ChromeOS. |
| 9 | """ |
| 10 | |
| 11 | __author__ = "raymes@google.com (Raymes Khoury)" |
| 12 | |
| 13 | import optparse |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 14 | import os |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 15 | import sys |
| 16 | from utils import utils |
| 17 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 18 | GCLIENT_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 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 32 | # Common initializations |
| 33 | (rootdir, basename) = utils.GetRoot(sys.argv[0]) |
| 34 | utils.InitLogger(rootdir, basename) |
| 35 | |
| 36 | |
| 37 | GIT_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 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 43 | def StoreFile(filename, contents): |
| 44 | f = open(filename, "w") |
| 45 | f.write(contents) |
| 46 | f.close() |
| 47 | |
| 48 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 49 | def Usage(parser): |
| 50 | parser.print_help() |
| 51 | sys.exit(0) |
| 52 | |
| 53 | |
| 54 | def GetTags(): |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 55 | res = utils.RunCommand(GIT_TAGS_CMD, True) |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 56 | return res[1].strip().split("\n") |
| 57 | |
| 58 | |
| 59 | def 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 |
| 66 | in 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 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 93 | 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 |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 101 | |
| 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 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 118 | # 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") |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 126 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 127 | 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) |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 131 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 132 | 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) |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 148 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 149 | print "Done" |
| 150 | |
| 151 | |
| 152 | if __name__ == "__main__": |
| 153 | Main() |