From 9f1d5ba50ec244653dceca5dba4e294e8e32af71 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 9 May 2017 17:06:52 -0700 Subject: [PATCH] Rev versions for alpha cut (#9940) And add a script to rev the versions. --- VERSION | 2 +- dev/tools/pubspec.yaml | 1 + dev/tools/update_versions.dart | 194 +++++++++++++++++++++++++++ packages/flutter/pubspec.yaml | 2 +- packages/flutter_driver/pubspec.yaml | 2 +- packages/flutter_test/pubspec.yaml | 1 + packages/flutter_tools/pubspec.yaml | 1 - 7 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 dev/tools/update_versions.dart diff --git a/VERSION b/VERSION index 2d28db994e..2b0bdeecf2 100644 --- a/VERSION +++ b/VERSION @@ -6,4 +6,4 @@ # incompatible way, this version number might not change. Instead, the version # number for package:flutter will update to reflect that change. -0.0.3 +0.0.4 diff --git a/dev/tools/pubspec.yaml b/dev/tools/pubspec.yaml index 41d0f91e0e..f2bd239e7f 100644 --- a/dev/tools/pubspec.yaml +++ b/dev/tools/pubspec.yaml @@ -6,4 +6,5 @@ dependencies: args: ^0.13.4 http: ^0.11.3+12 intl: ^0.14.0 + meta: ^1.0.5 path: ^1.4.0 diff --git a/dev/tools/update_versions.dart b/dev/tools/update_versions.dart new file mode 100644 index 0000000000..b9bcba45ca --- /dev/null +++ b/dev/tools/update_versions.dart @@ -0,0 +1,194 @@ +// Copyright 2017 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. + +// Updates the version numbers of the Flutter repo. +// Only tested on Linux. + +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:meta/meta.dart'; +import 'package:path/path.dart' as path; + +const String kIncrement = 'increment'; +const String kBrokeSdk = 'broke-sdk'; +const String kBrokeFramework = 'broke-framework'; +const String kBrokeTest = 'broke-test'; +const String kBrokeDriver = 'broke-driver'; +const String kMarkRelease = 'release'; +const String kHelp = 'help'; + +const String kYamlVersionPrefix = 'version: '; +const String kDev = '-dev'; + +void main(List args) { + // If we're run from the `tools` dir, set the cwd to the repo root. + if (path.basename(Directory.current.path) == 'tools') + Directory.current = Directory.current.parent.parent; + + final ArgParser argParser = new ArgParser(); + argParser.addFlag(kIncrement, defaultsTo: false, help: 'Increment all the version numbers. Cannot be specified with --$kMarkRelease or with any --broke-* commands.'); + argParser.addFlag(kBrokeSdk, defaultsTo: false, negatable: false, help: 'Increment the Flutter SDK version number to indicate that there has been a breaking change to the SDK (for example, to the command line options).'); + argParser.addFlag(kBrokeFramework, defaultsTo: false, negatable: false, help: 'Increment the "flutter" package version number to indicate that there has been a breaking change to the Flutter framework.'); + argParser.addFlag(kBrokeTest, defaultsTo: false, negatable: false, help: 'Increment the "flutter_test" package version number to indicate that there has been a breaking change to the test API framework.'); + argParser.addFlag(kBrokeDriver, defaultsTo: false, negatable: false, help: 'Increment the "flutter_driver" package version number to indicate that there has been a breaking change to the driver API framework.'); + argParser.addFlag(kMarkRelease, defaultsTo: false, help: 'Remove "-dev" from each version number. This is used when releasing. When not present, "-dev" is added to each version number. Cannot be specified with --$kIncrement or with any --broke-* commands.'); + argParser.addFlag(kHelp, negatable: false, help: 'Show this help message.'); + final ArgResults argResults = argParser.parse(args); + + final bool increment = argResults[kIncrement]; + final bool brokeSdk = argResults[kBrokeSdk]; + final bool brokeFramework = argResults[kBrokeFramework]; + final bool brokeTest = argResults[kBrokeTest]; + final bool brokeDriver = argResults[kBrokeDriver]; + final bool brokeAnything = brokeSdk || brokeFramework || brokeTest || brokeDriver; + final bool release = argResults[kMarkRelease]; + final bool help = argResults[kHelp]; + + if (help) { + print('update_versions.dart - update version numbers of Flutter packages and SDK'); + print(argParser.usage); + exit(0); + } + + if ((brokeAnything && release) || (brokeAnything && increment) || (release && increment)) { + print('You can either increment all the version numbers (--$kIncrement), indicate that some packages have had breaking changes (--broke-*), or switch to release mode (--$kMarkRelease).'); + print('You cannot combine these, however.'); + exit(1); + } + + final RawVersion sdk = new RawVersion('VERSION'); + final PubSpecVersion framework = new PubSpecVersion('packages/flutter/pubspec.yaml'); + final PubSpecVersion test = new PubSpecVersion('packages/flutter_test/pubspec.yaml'); + final PubSpecVersion driver = new PubSpecVersion('packages/flutter_driver/pubspec.yaml'); + + if (increment || brokeAnything) + sdk.increment(brokeAnything); + sdk.setMode(release); + + if (increment || brokeFramework) + framework.increment(brokeFramework); + framework.setMode(release); + + if (increment || brokeTest) + test.increment(brokeTest); + test.setMode(release); + + if (increment || brokeDriver) + driver.increment(brokeDriver); + driver.setMode(release); + + sdk.write(); + framework.write(); + test.write(); + driver.write(); + + print('Flutter SDK is now at version: $sdk'); + print('flutter package is now at version: $framework'); + print('flutter_test package is now at version: $test'); + print('flutter_driver package is now at version: $driver'); +} + +abstract class Version { + Version() { + read(); + } + + @protected + final List version = []; + + @protected + bool dev; + + @protected + bool dirty = false; + + @protected + void read(); + + void interpret(String value) { + dev = value.endsWith(kDev); + if (dev) + value = value.substring(0, value.length - kDev.length); + version.addAll(value.split('.').map(int.parse)); + } + + void increment(bool breaking) { + assert(version.length == 3); + if (breaking) { + version[1] += 1; + version[2] = 0; + } else { + version[2] += 1; + } + dirty = true; + } + + void setMode(bool release) { + if (release != !dev) { + dev = !release; + dirty = true; + } + } + + void write(); + + @override + String toString() => version.join('.') + (dev ? kDev : ''); +} + +class PubSpecVersion extends Version { + PubSpecVersion(this.path); + + final String path; + + @override + void read() { + final List lines = new File(path).readAsLinesSync(); + final String versionLine = lines.where((String line) => line.startsWith(kYamlVersionPrefix)).single; + interpret(versionLine.substring(kYamlVersionPrefix.length)); + } + + @override + void write() { + if (!dirty) + return; + final List lines = new File(path).readAsLinesSync(); + for (int index = 0; index < lines.length; index += 1) { + final String line = lines[index]; + if (line.startsWith(kYamlVersionPrefix)) { + lines[index] = '$kYamlVersionPrefix$this'; + break; + } + } + new File(path).writeAsStringSync(lines.join('\n') + '\n'); + } +} + +class RawVersion extends Version { + RawVersion(this.path); + + final String path; + + @override + void read() { + final List lines = new File(path).readAsLinesSync(); + interpret(lines.where((String line) => line.isNotEmpty && !line.startsWith('#')).single); + } + + @override + void write() { + if (!dirty) + return; + final List lines = new File(path).readAsLinesSync(); + for (int index = 0; index < lines.length; index += 1) { + final String line = lines[index]; + if (line.isNotEmpty && !line.startsWith('#')) { + lines[index] = '$this'; + break; + } + } + new File(path).writeAsStringSync(lines.join('\n') + '\n'); + } +} diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 1a3083507e..0dbf7334de 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -1,5 +1,5 @@ name: flutter -version: 0.0.23 +version: 0.0.24 author: Flutter Authors description: A framework for writing Flutter applications homepage: http://flutter.io diff --git a/packages/flutter_driver/pubspec.yaml b/packages/flutter_driver/pubspec.yaml index 384771916a..230f297a09 100644 --- a/packages/flutter_driver/pubspec.yaml +++ b/packages/flutter_driver/pubspec.yaml @@ -1,5 +1,5 @@ name: flutter_driver -version: 0.0.1 +version: 0.0.2 description: Integration and performance test API for Flutter applications homepage: http://flutter.io author: Flutter Authors diff --git a/packages/flutter_test/pubspec.yaml b/packages/flutter_test/pubspec.yaml index b40716c5e5..b44695f075 100644 --- a/packages/flutter_test/pubspec.yaml +++ b/packages/flutter_test/pubspec.yaml @@ -1,4 +1,5 @@ name: flutter_test +version: 0.0.2 dependencies: # The flutter tools depend on very specific internal implementation # details of the 'test' package, which change between versions, so diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index 74157e65b0..7996feaaad 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -1,5 +1,4 @@ name: flutter_tools -version: 0.0.38 description: Tools for building Flutter applications homepage: http://flutter.io author: Flutter Authors