Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1704)

Unified Diff: native_client_sdk/src/build_tools/update_sdktools.py

Issue 11759011: [NaCl SDK] Update sdk_tools to 160493->174973. Also added script to make updating sdk_tools easier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/build_tools/json/naclsdk_manifest2.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/build_tools/update_sdktools.py
diff --git a/native_client_sdk/src/build_tools/update_sdktools.py b/native_client_sdk/src/build_tools/update_sdktools.py
new file mode 100755
index 0000000000000000000000000000000000000000..95f08b85f739663de3ed2249ba37deed33d8d9eb
--- /dev/null
+++ b/native_client_sdk/src/build_tools/update_sdktools.py
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Script that reads omahaproxy and gsutil to determine a version of the
+sdk_tools bundle to use.
+
+Please note the differences between this script and update_nacl_manifest.py:
+
+update_sdktools.py is run by a SDK-team developer to assist in updating to a
+new sdk_tools bundle. A file on the developer's hard drive is modified, and
+must be checked in for the new sdk_tools bundle to be used.
+
+update_nacl_manifest.py is customarily run by a cron job, and does not check in
+any changes. Instead it modifies the manifest file in commondatastorage."""
+
+
+import collections
+import difflib
+import json
+from manifest_util import DownloadAndComputeHash
+import optparse
+import re
+import sys
+from update_nacl_manifest import RealDelegate
+import urllib2
+
+
+SDK_TOOLS_DESCRIPTION_FORMAT = 'Native Client SDK Tools, revision %d'
+BUCKET_PATH = 'nativeclient-mirror/nacl/nacl_sdk/'
+GS_BUCKET_PATH = 'gs://' + BUCKET_PATH
+HTTPS_BUCKET_PATH = 'https://commondatastorage.googleapis.com/' + BUCKET_PATH
+
+
+def GetSdkToolsUrl(revision):
+ return HTTPS_BUCKET_PATH + 'trunk.%d/sdk_tools.tgz' % revision
+
+
+def GetTrunkRevisions(delegate):
+ urls = delegate.GsUtil_ls(GS_BUCKET_PATH)
+ revisions = []
+ for url in urls:
+ m = re.match(GS_BUCKET_PATH + 'trunk\.(\d+)', url)
+ if m:
+ revisions.append((int(m.group(1)), url))
+ return sorted(revisions)
+
+
+def FindMostRecentSdkTools(delegate):
+ for revision, url in reversed(GetTrunkRevisions(delegate)):
+ sdktools_url = url + 'sdk_tools.tgz'
+ if delegate.GsUtil_ls(sdktools_url):
+ return revision, sdktools_url
+ return None
+
+
+def JsonLoadFromString(json_string):
+ if sys.version_info > (2, 7):
+ return json.loads(json_string, object_pairs_hook=collections.OrderedDict)
+ else:
+ return json.loads(json_string)
+
+
+def GetBundleByName(bundles, name):
+ for bundle in bundles:
+ if bundle['name'] == name:
+ return bundle
+ return None
+
+
+def UpdateSdkToolsBundle(sdk_tools_bundle, revision, url, sha1, size):
+ sdk_tools_bundle['description'] = SDK_TOOLS_DESCRIPTION_FORMAT % revision
+ sdk_tools_bundle['revision'] = revision
+ # Update archive for each OS
+ for archive in sdk_tools_bundle['archives']:
+ archive['url'] = url
+ archive['checksum']['sha1'] = sha1
+ archive['size'] = size
+
+
+def UpdateManifest(manifest, revision):
+ sdk_tools_bundle = GetBundleByName(manifest['bundles'], 'sdk_tools')
+ url = GetSdkToolsUrl(revision)
+ sha1, size = DownloadAndComputeHash(urllib2.urlopen(url))
+ UpdateSdkToolsBundle(sdk_tools_bundle, revision, url, sha1, size)
+
+
+def UpdateManifestFileToRevision(filename, revision):
+ with open(filename) as stream:
+ manifest_string = stream.read()
+
+ manifest = JsonLoadFromString(manifest_string)
+ UpdateManifest(manifest, revision)
+ new_manifest_string = json.dumps(manifest, indent=2)
+
+ diff_string = ''.join(difflib.unified_diff(manifest_string.splitlines(1),
+ new_manifest_string.splitlines(1)))
+
+ print 'diff %s' % filename
+ print diff_string
+ print
+
+ with open(filename, 'w') as stream:
+ stream.write(new_manifest_string)
+
+
+def main(args):
+ parser = optparse.OptionParser()
+ parser.add_option('-r', '--revision',
+ help='set revision manually, rather than using the latest version')
+ options, args = parser.parse_args(args[1:])
+ if len(args) != 0:
+ parser.error('Unexpected args: %s' % ', '.join(args))
+
+ # TODO(binji): http://crbug.com/169047. Rename RealDelegate to something else.
+ delegate = RealDelegate()
+ if not options.revision:
+ revision, _ = FindMostRecentSdkTools(delegate)
+ else:
+ revision = int(options.revision)
+
+ UpdateManifestFileToRevision('json/naclsdk_manifest0.json', revision)
+ UpdateManifestFileToRevision('json/naclsdk_manifest2.json', revision)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « native_client_sdk/src/build_tools/json/naclsdk_manifest2.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698