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

Side by Side Diff: tools/release/version.dart

Issue 11817012: Migration of testing scripts in tools/ to libv2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This file contains functionality for getting dart version numbers using 6 * This file contains functionality for getting dart version numbers using
7 * our standard version construction method. Systems that does not include this 7 * our standard version construction method. Systems that does not include this
8 * file should emulate the structure for revision numbers that we have here. 8 * file should emulate the structure for revision numbers that we have here.
9 * 9 *
10 * The version number of a dart build is constructed as follows: 10 * The version number of a dart build is constructed as follows:
11 * 1. The major, minor, build and patch numbers are extracted from the VERSION 11 * 1. The major, minor, build and patch numbers are extracted from the VERSION
12 * file in the root directory. We call these MAJOR, MINOR, BUILD and PATCH. 12 * file in the root directory. We call these MAJOR, MINOR, BUILD and PATCH.
13 * 2. The svn revision number for the current checkout is extracted from the 13 * 2. The svn revision number for the current checkout is extracted from the
14 * source control system that is used in the current checkout. We call this 14 * source control system that is used in the current checkout. We call this
15 * REVISION. 15 * REVISION.
16 * 3. If this is _not_ a official build, i.e., this is not build by our 16 * 3. If this is _not_ a official build, i.e., this is not build by our
17 * buildbot infrastructure, we extract the user-name of the logged in 17 * buildbot infrastructure, we extract the user-name of the logged in
18 * person from the operating system. We call this USERNAME. 18 * person from the operating system. We call this USERNAME.
19 * 4. The version number is constructed as follows: 19 * 4. The version number is constructed as follows:
20 * MAJOR.MINOR.BUILD.PATCH_rREVISION_USERNAME 20 * MAJOR.MINOR.BUILD.PATCH_rREVISION_USERNAME
21 */ 21 */
22 22
23 library version; 23 library version;
24
25 import "dart:async";
24 import "dart:io"; 26 import "dart:io";
25 27
26 /** 28 /**
27 * Generates version information for builds. 29 * Generates version information for builds.
28 */ 30 */
29 class Version { 31 class Version {
30 String _versionFileName; 32 String _versionFileName;
31 String USERNAME; 33 String USERNAME;
32 int REVISION; 34 int REVISION;
33 int MAJOR; 35 int MAJOR;
34 int MINOR; 36 int MINOR;
35 int BUILD; 37 int BUILD;
36 int PATCH; 38 int PATCH;
37 39
38 Version(Path versionFile) { 40 Version(Path versionFile) {
39 _versionFileName = versionFile.toNativePath(); 41 _versionFileName = versionFile.toNativePath();
40 } 42 }
41 43
42 /** 44 /**
43 * Get the version number for this specific build using the version info 45 * Get the version number for this specific build using the version info
44 * from the VERSION file in the root directory and the revision info 46 * from the VERSION file in the root directory and the revision info
45 * from the source control system of the current checkout. 47 * from the source control system of the current checkout.
46 */ 48 */
47 Future<String> getVersion() { 49 Future<String> getVersion() {
48 File f = new File(_versionFileName); 50 File f = new File(_versionFileName);
49 Completer c = new Completer(); 51 Completer c = new Completer();
52
53 var wasCompletedWithError = false;
54 completeError(String msg) {
55 if (!wasCompletedWithError) {
56 c.completeError(msg);
57 wasCompletedWithError = true;
58 }
59 }
50 f.exists().then((existed) { 60 f.exists().then((existed) {
51 if (!existed) { 61 if (!existed) {
52 c.completeError("No VERSION file"); 62 completeError("No VERSION file");
53 return; 63 return;
54 } 64 }
55 StringInputStream input = new StringInputStream(f.openInputStream()); 65 StringInputStream input = new StringInputStream(f.openInputStream());
56 input.onLine = () { 66 input.onLine = () {
57 var line = input.readLine().trim(); 67 var line = input.readLine().trim();
58 if (line == null) { 68 if (line == null) {
59 c.completeError( 69 completeError(
60 "VERSION input file seems to be in the wrong format"); 70 "VERSION input file seems to be in the wrong format");
61 return; 71 return;
62 } 72 }
63 var values = line.split(" "); 73 var values = line.split(" ");
64 if (values.length != 2) { 74 if (values.length != 2) {
65 c.completeError( 75 completeError(
66 "VERSION input file seems to be in the wrong format"); 76 "VERSION input file seems to be in the wrong format");
67 return; 77 return;
68 } 78 }
69 var number = 0; 79 var number = 0;
70 try { 80 try {
71 number = int.parse(values[1]); 81 number = int.parse(values[1]);
72 } catch (e) { 82 } catch (e) {
73 c.completeError("Can't parse version numbers, not an int"); 83 completeError("Can't parse version numbers, not an int");
74 return; 84 return;
75 } 85 }
76 switch (values[0]) { 86 switch (values[0]) {
77 case "MAJOR": 87 case "MAJOR":
78 MAJOR = number; 88 MAJOR = number;
79 break; 89 break;
80 case "MINOR": 90 case "MINOR":
81 MINOR = number; 91 MINOR = number;
82 break; 92 break;
83 case "BUILD": 93 case "BUILD":
84 BUILD = number; 94 BUILD = number;
85 break; 95 break;
86 case "PATCH": 96 case "PATCH":
87 PATCH = number; 97 PATCH = number;
88 break; 98 break;
89 default: 99 default:
90 c.completeError("Wrong format in VERSION file, line does not " 100 completeError("Wrong format in VERSION file, line does not "
91 "contain one of {MAJOR, MINOR, BUILD, PATCH}"); 101 "contain one of {MAJOR, MINOR, BUILD, PATCH}");
92 return; 102 return;
93 } 103 }
94 }; 104 };
95 input.onClosed = () { 105 input.onClosed = () {
96 // Only complete if we did not already complete with a failure. 106 // Only complete if we did not already complete with a failure.
97 if (!c.future.isComplete) { 107 if (!wasCompletedWithError) {
98 getRevision().then((revision) { 108 getRevision().then((revision) {
99 REVISION = revision; 109 REVISION = revision;
100 USERNAME = getUserName(); 110 USERNAME = getUserName();
101 var userNameString = ""; 111 var userNameString = "";
102 if (USERNAME != '') userNameString = "_$USERNAME"; 112 if (USERNAME != '') userNameString = "_$USERNAME";
103 var revisionString = ""; 113 var revisionString = "";
104 if (revision != 0) revisionString = "_r$revision"; 114 if (revision != 0) revisionString = "_r$revision";
105 c.complete( 115 c.complete(
106 "$MAJOR.$MINOR.$BUILD.$PATCH$revisionString$userNameString"); 116 "$MAJOR.$MINOR.$BUILD.$PATCH$revisionString$userNameString");
107 return; 117 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 command = "$command${getExecutableSuffix()}"; 155 command = "$command${getExecutableSuffix()}";
146 var arguments = isSvn ? ["info"] : ["svn", "info"]; 156 var arguments = isSvn ? ["info"] : ["svn", "info"];
147 ProcessOptions options = new ProcessOptions(); 157 ProcessOptions options = new ProcessOptions();
148 // Run the command from the root to get the last changed revision for this 158 // Run the command from the root to get the last changed revision for this
149 // "branch". Since we have both trunk and bleeding edge in the same 159 // "branch". Since we have both trunk and bleeding edge in the same
150 // repository and since we always build TOT we need this to get the 160 // repository and since we always build TOT we need this to get the
151 // right version number. 161 // right version number.
152 Path toolsDirectory = new Path.fromNative(_versionFileName).directoryPath; 162 Path toolsDirectory = new Path.fromNative(_versionFileName).directoryPath;
153 Path root = toolsDirectory.join(new Path("..")); 163 Path root = toolsDirectory.join(new Path(".."));
154 options.workingDirectory = root.toNativePath(); 164 options.workingDirectory = root.toNativePath();
155 return Process.run(command, arguments, options).transform((result) { 165 return Process.run(command, arguments, options).then((result) {
156 if (result.exitCode != 0) { 166 if (result.exitCode != 0) {
157 return 0; 167 return 0;
158 } 168 }
159 return getRevisionFromSvnInfo(result.stdout); 169 return getRevisionFromSvnInfo(result.stdout);
160 }); 170 });
161 } 171 }
162 172
163 bool isProductionBuild(String username) { 173 bool isProductionBuild(String username) {
164 return username == "chrome-bot"; 174 return username == "chrome-bot";
165 } 175 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 static RepositoryType guessType() { 216 static RepositoryType guessType() {
207 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; 217 if (new Directory(".svn").existsSync()) return RepositoryType.SVN;
208 if (new Directory(".git").existsSync()) return RepositoryType.GIT; 218 if (new Directory(".git").existsSync()) return RepositoryType.GIT;
209 return RepositoryType.UNKNOWN; 219 return RepositoryType.UNKNOWN;
210 } 220 }
211 221
212 String toString() => name; 222 String toString() => name;
213 223
214 final String name; 224 final String name;
215 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698