shenhan | b7ff88b | 2013-02-19 20:42:48 +0000 | [diff] [blame^] | 1 | #!/usr/bin/python |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 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 |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 14 | import optparse |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 15 | import os |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 16 | import sys |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 17 | import tempfile |
| 18 | import time |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 19 | from utils import command_executer |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 20 | from utils import logger |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 21 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 22 | GCLIENT_FILE = """solutions = [ |
| 23 | { "name" : "CHROME_DEPS", |
| 24 | "url" : |
| 25 | "svn://svn.chromium.org/chrome-internal/trunk/tools/buildspec/releases/%s", |
| 26 | "custom_deps" : { |
| 27 | "src/third_party/WebKit/LayoutTests": None, |
| 28 | "src-pdf": None, |
| 29 | "src/pdf": None, |
| 30 | }, |
| 31 | "safesync_url": "", |
| 32 | }, |
| 33 | ] |
| 34 | """ |
| 35 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 36 | def Usage(parser): |
| 37 | parser.print_help() |
| 38 | sys.exit(0) |
| 39 | |
| 40 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 41 | def TimeToVersion(my_time, versions_git): |
| 42 | """Convert timestamp to version number.""" |
| 43 | cur_time = time.mktime(time.gmtime()) |
| 44 | des_time = float(my_time) |
| 45 | if cur_time - des_time > 7000000: |
| 46 | logger.GetLogger().LogFatal("The time you specify is too early.") |
| 47 | temp = tempfile.mkdtemp() |
| 48 | commands = ["cd {0}".format(temp), "git clone {0}".format(versions_git), |
| 49 | "cd manifest-versions", "git checkout -f $(git rev-list" + |
| 50 | " --max-count=1 --before={0} origin/master)".format(my_time)] |
| 51 | cmd_executer = command_executer.GetCommandExecuter() |
| 52 | ret = cmd_executer.RunCommands(commands) |
| 53 | if ret: |
| 54 | return None |
| 55 | path = os.path.realpath("{0}/manifest-versions/LKGM/lkgm.xml".format(temp)) |
| 56 | pp = path.split("/") |
| 57 | small = os.path.basename(path).split(".xml")[0] |
| 58 | version = pp[-2] + "." + small |
| 59 | commands = ["rm -rf {0}".format(temp)] |
| 60 | cmd_executer.RunCommands(commands) |
| 61 | return version |
| 62 | |
| 63 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 64 | def Main(argv): |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 65 | """Checkout the ChromeOS source.""" |
| 66 | parser = optparse.OptionParser() |
| 67 | parser.add_option("--dir", dest="directory", |
| 68 | help="Target directory for ChromeOS installation.") |
raymes | d1eed80 | 2013-02-15 04:36:08 +0000 | [diff] [blame] | 69 | parser.add_option("--version", dest="version", default="latest", |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 70 | help="""ChromeOS version. Can be: (1) A release version |
| 71 | in the format: 'X.X.X.X' (2) 'latest' for the latest release version or (3) |
| 72 | 'top' for top of trunk. Default is 'latest'""") |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 73 | parser.add_option("--timestamp", dest="timestamp", default=None, |
| 74 | help="""Timestamps in epoch format. It will check out the |
| 75 | latest LKGM version of ChromeOS before the timestamp. It will also overide |
| 76 | the version option.""") |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 77 | parser.add_option("--minilayout", dest="minilayout", default=False, |
asharif | dff6134 | 2013-02-15 04:50:46 +0000 | [diff] [blame] | 78 | action="store_true", |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 79 | help="""Whether to checkout the minilayout |
| 80 | (smaller checkout).'""") |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 81 | parser.add_option("--jobs", "-j", dest="jobs", default="1", |
| 82 | help="Number of repo sync threads to use.") |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 83 | parser.add_option("--public", "-p", dest="public", default=False, |
| 84 | action="store_true", |
| 85 | help="Use the public checkout instead of the private one.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 86 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 87 | options = parser.parse_args(argv)[0] |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 88 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 89 | if not options.version: |
| 90 | parser.print_help() |
| 91 | logger.GetLogger().LogFatal("No version specified.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 92 | else: |
| 93 | version = options.version.strip() |
| 94 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 95 | if not options.timestamp: |
| 96 | timestamp = "" |
| 97 | else: |
| 98 | timestamp = options.timestamp.strip() |
| 99 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 100 | if not options.directory: |
| 101 | parser.print_help() |
| 102 | logger.GetLogger().LogFatal("No directory specified.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 103 | |
| 104 | directory = options.directory.strip() |
| 105 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 106 | if options.public: |
| 107 | manifest_repo = "http://git.chromium.org/chromiumos/manifest.git" |
| 108 | versions_repo = "http://git.chromium.org/chromiumos/manifest-versions.git" |
| 109 | else: |
| 110 | manifest_repo = ( |
| 111 | "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git") |
| 112 | versions_repo = ( |
| 113 | "ssh://gerrit-int.chromium.org:29419/chromeos/manifest-versions.git") |
| 114 | |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 115 | if timestamp: |
| 116 | my_version = TimeToVersion(timestamp, versions_repo) |
| 117 | if my_version: |
| 118 | version = my_version |
| 119 | |
| 120 | if version == "top": |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 121 | init = "repo init -u %s" % manifest_repo |
raymes | 69c8d72 | 2013-02-15 17:55:36 +0000 | [diff] [blame] | 122 | else: |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 123 | if version =="latest": |
| 124 | version = TimeToVersion(time.mktime(time.gmtime()), versions_repo) |
shenhan | 9c39a84 | 2013-02-16 03:14:07 +0000 | [diff] [blame] | 125 | version, manifest = version.split(".", 1) |
llozano | 54bef9a | 2013-02-19 19:42:41 +0000 | [diff] [blame] | 126 | init = ("repo init -u %s -m paladin/buildspecs/%s/%s.xml" % ( |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 127 | versions_repo, version, manifest)) |
| 128 | if options.minilayout: |
yunlian | 992a490 | 2013-02-19 20:19:25 +0000 | [diff] [blame] | 129 | init += " -g minilayout" |
yunlian | 3802fbf | 2013-02-19 19:58:44 +0000 | [diff] [blame] | 130 | |
asharif | 731e293 | 2013-02-15 21:20:10 +0000 | [diff] [blame] | 131 | init += " --repo-url=http://git.chromium.org/external/repo.git" |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 132 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 133 | commands = ["mkdir -p %s" % directory, |
| 134 | "cd %s" % directory, |
| 135 | init, |
shenhan | b7ff88b | 2013-02-19 20:42:48 +0000 | [diff] [blame^] | 136 | # crosbug#31837 - "Sources need to be world-readable to properly |
| 137 | # function inside the chroot" |
| 138 | "umask 022 && repo sync -j %s" % options.jobs] |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 139 | cmd_executer = command_executer.GetCommandExecuter() |
| 140 | ret = cmd_executer.RunCommands(commands) |
| 141 | if ret: |
| 142 | return ret |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 143 | |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 144 | # Setup svn credentials for use inside the chroot |
asharif | ca35b77 | 2013-02-15 04:56:41 +0000 | [diff] [blame] | 145 | if getpass.getuser() == "mobiletc-prebuild": |
| 146 | chromium_username = "raymes" |
| 147 | else: |
| 148 | chromium_username = "$USER" |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 149 | |
asharif | bf6899d | 2013-02-15 21:42:35 +0000 | [diff] [blame] | 150 | return cmd_executer.RunCommand( |
| 151 | "svn ls --config-option config:auth:password-stores= " |
| 152 | "--config-option " |
| 153 | "servers:global:store-plaintext-passwords=yes " |
| 154 | "--username " + chromium_username + "@google.com " |
| 155 | "svn://svn.chromium.org/leapfrog-internal " |
| 156 | "svn://svn.chromium.org/chrome " |
| 157 | "svn://svn.chromium.org/chrome-internal > /dev/null") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | if __name__ == "__main__": |
asharif | 2198c51 | 2013-02-15 09:21:35 +0000 | [diff] [blame] | 161 | retval = Main(sys.argv) |
| 162 | sys.exit(retval) |