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 | |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 13 | import getpass |
asharif | 911bd27 | 2013-02-15 09:04:48 +0000 | [diff] [blame^] | 14 | import multiprocessing |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 15 | import optparse |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 16 | import os |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 17 | import sys |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 18 | from utils import command_executer |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 19 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 20 | GCLIENT_FILE = """solutions = [ |
| 21 | { "name" : "CHROME_DEPS", |
| 22 | "url" : |
| 23 | "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s", |
| 24 | "custom_deps" : { |
| 25 | "src/third_party/WebKit/LayoutTests": None, |
| 26 | "src-pdf": None, |
| 27 | "src/pdf": None, |
| 28 | }, |
| 29 | "safesync_url": "", |
| 30 | }, |
| 31 | ] |
| 32 | """ |
| 33 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 34 | # Common initializations |
asharif | 5a9bb46 | 2013-02-15 04:50:57 +0000 | [diff] [blame] | 35 | cmd_executer = None |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 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]*' | " |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 40 | "cut -d '/' -f 3") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 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 | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 55 | res = cmd_executer.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 | |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 59 | def GetLatestTag(tags): |
| 60 | latest = tags[0] |
| 61 | for tag in tags: |
| 62 | current_components = tag.split(".") |
| 63 | latest_components = latest.split(".") |
| 64 | for i in range(len(current_components)): |
| 65 | if int(current_components[i]) > int(latest_components[i]): |
| 66 | latest = tag |
| 67 | break |
| 68 | elif int(current_components[i]) < int(latest_components[i]): |
| 69 | break |
| 70 | |
| 71 | return latest |
| 72 | |
| 73 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 74 | def Main(argv): |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 75 | """Checkout the ChromeOS source.""" |
asharif | 5a9bb46 | 2013-02-15 04:50:57 +0000 | [diff] [blame] | 76 | global cmd_executer |
| 77 | cmd_executer = command_executer.GetCommandExecuter() |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 78 | parser = optparse.OptionParser() |
| 79 | parser.add_option("--dir", dest="directory", |
| 80 | help="Target directory for ChromeOS installation.") |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 81 | parser.add_option("--version", dest="version", default="latest", |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 82 | help="""ChromeOS version. Can be: (1) A release version |
| 83 | in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3) |
| 84 | 'top' for top of trunk. Default is 'latest'""") |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 85 | parser.add_option("--minilayout", dest="minilayout", default=False, |
asharif | dff6134 | 2013-02-15 04:50:46 +0000 | [diff] [blame] | 86 | action="store_true", |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 87 | help="""Whether to checkout the minilayout |
| 88 | (smaller checkout).'""") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 89 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 90 | options = parser.parse_args(argv)[0] |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 91 | |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 92 | tags = GetTags() |
| 93 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 94 | if options.version == "latest": |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 95 | version = GetLatestTag(tags) |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 96 | print version |
| 97 | elif options.version == "top": |
raymes | 04164a1 | 2013-02-15 04:36:03 +0000 | [diff] [blame] | 98 | version = "top" |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 99 | elif options.version is None: |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 100 | print "No version specified" |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 101 | Usage(parser) |
| 102 | else: |
| 103 | version = options.version.strip() |
| 104 | |
raymes | 04164a1 | 2013-02-15 04:36:03 +0000 | [diff] [blame] | 105 | if not version in tags and version != "top": |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 106 | print "Version: '" + version + "' does not exist" |
| 107 | Usage(parser) |
| 108 | |
| 109 | if options.directory is None: |
| 110 | print "Please give a valid directory" |
| 111 | Usage(parser) |
| 112 | |
| 113 | directory = options.directory.strip() |
| 114 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 115 | # Don't checkout chrome sources outside the chroot at the moment. |
| 116 | # If we check them out outside, we can't do some things, like build tests. |
| 117 | checkout_chrome_outside_chroot = False |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 118 | |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 119 | minilayout = "" |
| 120 | if options.minilayout == True: |
| 121 | minilayout = " -m minilayout.xml" |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 122 | commands = [] |
| 123 | commands.append("mkdir -p " + directory) |
| 124 | commands.append("cd " + directory) |
| 125 | commands.append("repo init -u " |
asharif | 911bd27 | 2013-02-15 09:04:48 +0000 | [diff] [blame^] | 126 | "ssh://git@gitrw.chromium.org:9222/manifest-internal" |
| 127 | + minilayout) |
| 128 | commands.append("repo sync -j" + str(multiprocessing.cpu_count() + 1)) |
| 129 | if version != "top": |
| 130 | commands.append("repo forall -c 'git checkout -f %s'" % version) |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 131 | cmd_executer.RunCommands(commands) |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 132 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 133 | # Setup svn credentials for use inside the chroot |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 134 | if getpass.getuser() == "mobiletc-prebuild": |
| 135 | chromium_username = "raymes" |
| 136 | else: |
| 137 | chromium_username = "$USER" |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 138 | cmd_executer.RunCommand("svn ls --config-option config:auth:password-stores= " |
| 139 | "--config-option " |
| 140 | "servers:global:store-plaintext-passwords=yes " |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 141 | "--username " + chromium_username + "@google.com " |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 142 | "svn://svn.chromium.org/leapfrog-internal " |
| 143 | "svn://svn.chromium.org/chrome " |
| 144 | "svn://svn.chromium.org/chrome-internal > /dev/null") |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 145 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 146 | if checkout_chrome_outside_chroot: |
| 147 | # Find Chrome browser version |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 148 | chrome_version = cmd_executer.RunCommand("%s/src/scripts/" |
| 149 | "chromeos_version.sh | " |
| 150 | "grep CHROME_BUILD" |
| 151 | % directory, True) |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 152 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 153 | chrome_version = chrome_version[1].strip().split("=") |
| 154 | if len(chrome_version) == 2: |
| 155 | chrome_version = chrome_version[1] |
| 156 | else: |
| 157 | chrome_version = "" |
| 158 | |
| 159 | # Checkout chrome |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 160 | cmd_executer.RunCommand("mkdir -p %s/chrome_browser/" % directory) |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 161 | gclient_file = GCLIENT_FILE % chrome_version |
| 162 | StoreFile(os.path.expanduser("%s/chrome_browser/.gclient" |
| 163 | % directory), gclient_file) |
| 164 | commands = [] |
| 165 | commands.append("cd " + options.directory) |
| 166 | commands.append("cd chrome_browser") |
| 167 | commands.append("gclient sync -v --nohooks --delete_unversioned_trees") |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 168 | cmd_executer.RunCommands(commands) |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 169 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 170 | print "Done" |
| 171 | |
| 172 | |
| 173 | if __name__ == "__main__": |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 174 | Main(sys.argv) |