| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os |
| 7 import subprocess |
| 6 import yaml | 8 import yaml |
| 7 import xml.etree.ElementTree as ET | 9 import xml.etree.ElementTree as ET |
| 8 | 10 |
| 11 |
| 9 PUBSPECS = [ | 12 PUBSPECS = [ |
| 10 'sky/sdk/pubspec.yaml', | 13 'sky/sdk/pubspec.yaml', |
| 11 'mojo/public/dart/pubspec.yaml', | 14 'mojo/public/dart/pubspec.yaml', |
| 12 'mojo/dart/mojo_services/pubspec.yaml', | 15 'mojo/dart/mojo_services/pubspec.yaml', |
| 13 'mojo/dart/mojom/pubspec.yaml', | 16 'mojo/dart/mojom/pubspec.yaml', |
| 14 ] | 17 ] |
| 15 | 18 |
| 16 MANIFESTS = [ | 19 MANIFESTS = [ |
| 17 'sky/apk/demo/AndroidManifest.xml', | 20 'sky/apk/demo/AndroidManifest.xml', |
| 18 ] | 21 ] |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 return '.'.join(pieces) | 34 return '.'.join(pieces) |
| 32 | 35 |
| 33 | 36 |
| 34 def sort_dict(unsorted): | 37 def sort_dict(unsorted): |
| 35 sorted_dict = collections.OrderedDict() | 38 sorted_dict = collections.OrderedDict() |
| 36 for key in sorted(unsorted.keys()): | 39 for key in sorted(unsorted.keys()): |
| 37 sorted_dict[key] = unsorted[key] | 40 sorted_dict[key] = unsorted[key] |
| 38 return sorted_dict | 41 return sorted_dict |
| 39 | 42 |
| 40 | 43 |
| 44 def count_commits(start, end): |
| 45 return subprocess.check_output([ |
| 46 'git', 'rev-list', '%s...%s' % (start, end)]).count('\n') |
| 47 |
| 48 |
| 49 def last_commit_to(file_path): |
| 50 return subprocess.check_output(['git', 'log', '-1', '--format=%h', file_path
]).strip() |
| 51 |
| 52 |
| 41 def update_pubspec(pubspec): | 53 def update_pubspec(pubspec): |
| 42 # TODO(eseidel): This does not prserve any manual sort-order of the yaml. | 54 # TODO(eseidel): This does not prserve any manual sort-order of the yaml. |
| 43 with open(pubspec, 'r') as stream: | 55 with open(pubspec, 'r') as stream: |
| 44 spec = yaml.load(stream) | 56 spec = yaml.load(stream) |
| 45 old_version = spec['version'] | 57 old_version = spec['version'] |
| 46 spec['version'] = increment_version(old_version) | 58 spec['version'] = increment_version(old_version) |
| 47 print "%20s %6s => %6s" % (spec['name'], old_version, spec['version']) | 59 print "%20s %6s => %6s" % (spec['name'], old_version, spec['version']) |
| 48 | 60 |
| 49 with open(pubspec, 'w') as stream: | 61 with open(pubspec, 'w') as stream: |
| 50 yaml.dump(spec, stream=stream, default_flow_style=False) | 62 yaml.dump(spec, stream=stream, default_flow_style=False) |
| 63 return spec['version'] |
| 64 |
| 65 |
| 66 def update_changelog(changelog, pubspec, version): |
| 67 old = last_commit_to(pubspec) |
| 68 new = last_commit_to('.') |
| 69 url = "https://github.com/domokit/mojo/compare/%s...%s" % (old, new) |
| 70 count = count_commits(old, new) |
| 71 message = """## %s |
| 72 |
| 73 - %s changes: %s |
| 74 |
| 75 """ % (version, count, url) |
| 76 prepend_to_file(message, changelog) |
| 51 | 77 |
| 52 | 78 |
| 53 def prepend_to_file(to_prepend, filepath): | 79 def prepend_to_file(to_prepend, filepath): |
| 54 with open(filepath, 'r+') as f: | 80 with open(filepath, 'r+') as f: |
| 55 content = f.read() | 81 content = f.read() |
| 56 f.seek(0, 0) | 82 f.seek(0, 0) |
| 57 f.write(to_prepend + content) | 83 f.write(to_prepend + content) |
| 58 | 84 |
| 59 | 85 |
| 60 def update_manifest(manifest): | 86 def update_manifest(manifest): |
| 61 VERSION_CODE = '{http://schemas.android.com/apk/res/android}versionCode' | 87 VERSION_CODE = '{http://schemas.android.com/apk/res/android}versionCode' |
| 62 VERSION_NAME = '{http://schemas.android.com/apk/res/android}versionName' | 88 VERSION_NAME = '{http://schemas.android.com/apk/res/android}versionName' |
| 63 tree = ET.parse(manifest) | 89 tree = ET.parse(manifest) |
| 64 root = tree.getroot() | 90 root = tree.getroot() |
| 65 package_name = root.get('package') | 91 package_name = root.get('package') |
| 66 old_code = root.get(VERSION_CODE) | 92 old_code = root.get(VERSION_CODE) |
| 67 old_name = root.get(VERSION_NAME) | 93 old_name = root.get(VERSION_NAME) |
| 68 root.set(VERSION_CODE, increment_version(old_code)) | 94 root.set(VERSION_CODE, increment_version(old_code)) |
| 69 root.set(VERSION_NAME, increment_version(old_name)) | 95 root.set(VERSION_NAME, increment_version(old_name)) |
| 70 print "%20s %6s (%s) => %6s (%s)" % (package_name, old_name, old_code, | 96 print "%20s %6s (%s) => %6s (%s)" % (package_name, old_name, old_code, |
| 71 root.get(VERSION_NAME), root.get(VERSION_CODE)) | 97 root.get(VERSION_NAME), root.get(VERSION_CODE)) |
| 72 # TODO(eseidel): This isn't smart enough to wrap/intent multi-attribute | 98 # TODO(eseidel): This isn't smart enough to wrap/intent multi-attribute |
| 73 # elements like <manifest> as is the typical AndroidManifiest.xml style | 99 # elements like <manifest> as is the typical AndroidManifiest.xml style |
| 74 # we could write our own custom prettyprinter to do that? | 100 # we could write our own custom prettyprinter to do that? |
| 75 tree.write(manifest) | 101 tree.write(manifest) |
| 76 prepend_to_file(MANIFEST_PREFACE, manifest) | 102 prepend_to_file(MANIFEST_PREFACE, manifest) |
| 77 | 103 |
| 78 | 104 |
| 79 def main(): | 105 def main(): |
| 106 # Should chdir to the root directory. |
| 107 |
| 80 print 'Pub packages:' | 108 print 'Pub packages:' |
| 81 for pubspec in PUBSPECS: | 109 for pubspec in PUBSPECS: |
| 82 update_pubspec(pubspec) | 110 new_version = update_pubspec(pubspec) |
| 111 changelog = os.path.join(os.path.dirname(pubspec), 'CHANGELOG.md') |
| 112 update_changelog(changelog, pubspec, new_version) |
| 83 | 113 |
| 84 # TODO(eseidel): Without this ET uses 'ns0' for 'android' which is wrong. | 114 # TODO(eseidel): Without this ET uses 'ns0' for 'android' which is wrong. |
| 85 ET.register_namespace('android', 'http://schemas.android.com/apk/res/android
') | 115 ET.register_namespace('android', 'http://schemas.android.com/apk/res/android
') |
| 86 | 116 |
| 87 print 'APKs:' | 117 print 'APKs:' |
| 88 for manifest in MANIFESTS: | 118 for manifest in MANIFESTS: |
| 89 update_manifest(manifest) | 119 update_manifest(manifest) |
| 90 | 120 |
| 91 | 121 |
| 92 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 93 main() | 123 main() |
| OLD | NEW |