Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / update_sdktools.py
blob95f08b85f739663de3ed2249ba37deed33d8d9eb
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Script that reads omahaproxy and gsutil to determine a version of the
7 sdk_tools bundle to use.
9 Please note the differences between this script and update_nacl_manifest.py:
11 update_sdktools.py is run by a SDK-team developer to assist in updating to a
12 new sdk_tools bundle. A file on the developer's hard drive is modified, and
13 must be checked in for the new sdk_tools bundle to be used.
15 update_nacl_manifest.py is customarily run by a cron job, and does not check in
16 any changes. Instead it modifies the manifest file in commondatastorage."""
19 import collections
20 import difflib
21 import json
22 from manifest_util import DownloadAndComputeHash
23 import optparse
24 import re
25 import sys
26 from update_nacl_manifest import RealDelegate
27 import urllib2
30 SDK_TOOLS_DESCRIPTION_FORMAT = 'Native Client SDK Tools, revision %d'
31 BUCKET_PATH = 'nativeclient-mirror/nacl/nacl_sdk/'
32 GS_BUCKET_PATH = 'gs://' + BUCKET_PATH
33 HTTPS_BUCKET_PATH = 'https://commondatastorage.googleapis.com/' + BUCKET_PATH
36 def GetSdkToolsUrl(revision):
37 return HTTPS_BUCKET_PATH + 'trunk.%d/sdk_tools.tgz' % revision
40 def GetTrunkRevisions(delegate):
41 urls = delegate.GsUtil_ls(GS_BUCKET_PATH)
42 revisions = []
43 for url in urls:
44 m = re.match(GS_BUCKET_PATH + 'trunk\.(\d+)', url)
45 if m:
46 revisions.append((int(m.group(1)), url))
47 return sorted(revisions)
50 def FindMostRecentSdkTools(delegate):
51 for revision, url in reversed(GetTrunkRevisions(delegate)):
52 sdktools_url = url + 'sdk_tools.tgz'
53 if delegate.GsUtil_ls(sdktools_url):
54 return revision, sdktools_url
55 return None
58 def JsonLoadFromString(json_string):
59 if sys.version_info > (2, 7):
60 return json.loads(json_string, object_pairs_hook=collections.OrderedDict)
61 else:
62 return json.loads(json_string)
65 def GetBundleByName(bundles, name):
66 for bundle in bundles:
67 if bundle['name'] == name:
68 return bundle
69 return None
72 def UpdateSdkToolsBundle(sdk_tools_bundle, revision, url, sha1, size):
73 sdk_tools_bundle['description'] = SDK_TOOLS_DESCRIPTION_FORMAT % revision
74 sdk_tools_bundle['revision'] = revision
75 # Update archive for each OS
76 for archive in sdk_tools_bundle['archives']:
77 archive['url'] = url
78 archive['checksum']['sha1'] = sha1
79 archive['size'] = size
82 def UpdateManifest(manifest, revision):
83 sdk_tools_bundle = GetBundleByName(manifest['bundles'], 'sdk_tools')
84 url = GetSdkToolsUrl(revision)
85 sha1, size = DownloadAndComputeHash(urllib2.urlopen(url))
86 UpdateSdkToolsBundle(sdk_tools_bundle, revision, url, sha1, size)
89 def UpdateManifestFileToRevision(filename, revision):
90 with open(filename) as stream:
91 manifest_string = stream.read()
93 manifest = JsonLoadFromString(manifest_string)
94 UpdateManifest(manifest, revision)
95 new_manifest_string = json.dumps(manifest, indent=2)
97 diff_string = ''.join(difflib.unified_diff(manifest_string.splitlines(1),
98 new_manifest_string.splitlines(1)))
100 print 'diff %s' % filename
101 print diff_string
102 print
104 with open(filename, 'w') as stream:
105 stream.write(new_manifest_string)
108 def main(args):
109 parser = optparse.OptionParser()
110 parser.add_option('-r', '--revision',
111 help='set revision manually, rather than using the latest version')
112 options, args = parser.parse_args(args[1:])
113 if len(args) != 0:
114 parser.error('Unexpected args: %s' % ', '.join(args))
116 # TODO(binji): http://crbug.com/169047. Rename RealDelegate to something else.
117 delegate = RealDelegate()
118 if not options.revision:
119 revision, _ = FindMostRecentSdkTools(delegate)
120 else:
121 revision = int(options.revision)
123 UpdateManifestFileToRevision('json/naclsdk_manifest0.json', revision)
124 UpdateManifestFileToRevision('json/naclsdk_manifest2.json', revision)
127 if __name__ == '__main__':
128 sys.exit(main(sys.argv))