forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_versions.dart
More file actions
197 lines (161 loc) · 6.67 KB
/
update_versions.dart
File metadata and controls
197 lines (161 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// 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';
enum VersionKind { dev, release }
void main(List<String> 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 VersionKind level = argResults[kMarkRelease] ? VersionKind.release : VersionKind.dev;
final bool help = argResults[kHelp];
if (help) {
print('update_versions.dart - update version numbers of Flutter packages and SDK');
print(argParser.usage);
exit(0);
}
final bool release = level == VersionKind.release;
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(level);
if (increment || brokeFramework)
framework.increment(brokeFramework);
framework.setMode(level);
if (increment || brokeTest)
test.increment(brokeTest);
test.setMode(level);
if (increment || brokeDriver)
driver.increment(brokeDriver);
driver.setMode(level);
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<int> version = <int>[];
@protected
VersionKind level;
@protected
bool dirty = false;
@protected
void read();
void interpret(String value) {
level = value.endsWith(kDev) ? VersionKind.dev : VersionKind.release;
if (level == VersionKind.dev)
value = value.substring(0, value.length - kDev.length);
version.addAll(value.split('.').map<int>(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(VersionKind value) {
if (value != level) {
level = value;
dirty = true;
}
}
void write();
@override
String toString() => version.join('.') + (level == VersionKind.dev ? kDev : '');
}
class PubSpecVersion extends Version {
PubSpecVersion(this.path);
final String path;
@override
void read() {
final List<String> 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<String> 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<String> lines = new File(path).readAsLinesSync();
interpret(lines.where((String line) => line.isNotEmpty && !line.startsWith('#')).single);
}
@override
void write() {
if (!dirty)
return;
final List<String> 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');
}
}