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

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

Issue 11090046: Add a dart library and a dart script for creating version numbers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « no previous file | tools/version.dart » ('j') | tools/version.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * This file contains functionality for getting dart version numbers using
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.
9 *
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
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
14 * source control system that is used in the current checkout. We call this
15 * REVISION.
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
18 * person from the operating system. We call this USERNAME.
19 * 4. The version number is constructed as follows:
20 * MAJOR.MINOR.BUILD.PATCH_rREVISION_USERNAME
21 */
22 #library("version");
kasperl 2012/10/10 12:21:05 You should be able to use the new library syntax.
ricow1 2012/10/10 12:32:39 Done.
23
24 #import("dart:io");
25
26 /**
27 * Generates version information for builds.
28 */
29 class Version {
30
31 Version(String this._versionFile);
32
33 /**
34 * Get the version number for this specific build using the version info
35 * from the VERSION file in the root directory and the revision info
36 * from the source control system of the current checkout.
37 */
38 Future<String> getVersion() {
39 File f = new File(_versionFile);
40 Completer c = new Completer();
41 f.exists().then((existed) {
42 if (!existed) {
43 c.completeException("No VERSION file");
44 return;
45 }
46 StringInputStream input = new StringInputStream(f.openInputStream());
47 input.onLine = () {
48 var line = input.readLine();
49 if (line == null) {
50 c.completeException(
51 "VERSION input file seems to be in the wrong format");
52 return;
53 }
54 var values = line.split(" ");
55 if (values.length != 2) {
56 c.completeException(
57 "VERSION input file seems to be in the wrong format");
58 return;
59 }
60 var number = 0;
61 try {
62 number = int.parse(values[1]);
63 } catch (e) {
64 c.completeException("Can't parse version numbers, not an int");
65 return;
66 }
67 switch (values[0]) {
68 case "MAJOR":
69 MAJOR = number;
70 break;
71 case "MINOR":
72 MINOR = number;
73 break;
74 case "BUILD":
75 BUILD = number;
76 break;
77 case "PATCH":
78 PATCH = number;
79 break;
80 default:
81 c.completeException("Wrong format in VERSION file, line does not "
82 "contain on of {MAJOR, MINOR, BUILD, PATCH}");
kasperl 2012/10/10 12:21:05 on -> one
ricow1 2012/10/10 12:32:39 Done.
83 return;
84 }
85 };
86 input.onClosed = () {
87 // Only complete if we did not already complete with a failure.
88 if (!c.future.isComplete) {
89 getRevision().then((revision) {
90 REVISION = revision;
91 getUserName().then((username) {
92 USERNAME = username;
93 if (username != '') username = "_$username";
94 var revisionString = "";
95 if (revision != 0) revisionString = "_r$revision";
96 c.complete("$MAJOR.$MINOR.$BUILD.$PATCH$revisionString$username");
97 return;
98 });
99 });
100 }
101 };
102 });
103 return c.future;
104 }
105
106 Future<int> getRevision() {
107 if (repositoryType != RepositoryType.UNKNOWN) {
kasperl 2012/10/10 12:21:05 Maybe invert this to avoid all the nesting (early
ricow1 2012/10/10 12:32:39 Done.
108 var isSvn = repositoryType == RepositoryType.SVN;
109 var command = isSvn ? "svn" : "git";
110 var arguments = isSvn ? ["info"] : ["svn", "info"];
111 return Process.run(command, arguments).transform((result) {
112 if (result.exitCode != 0) {
113 return 0;
114 }
115 // If anything goes wrong parsing the revision number we simply return 0
kasperl 2012/10/10 12:21:05 Terminate comment with .
ricow1 2012/10/10 12:32:39 Done.
116 try {
117 // Extract the revision. It's located at the 8th line,
118 // 18 characters in.
119 String revisionString = result.stdout.split("\n")[8].substring(18);
120 return int.parse(revisionString);
121 } catch (e) {
122 return 0;
123 }
124 });
125 } else {
126 return new Future.immediate(0);
127 }
128 }
129
130 Future<String> getUserName() {
131 // TODO(ricow): Don't add this on the buildbot.
132 // If we can't get the username simple return "" (e.g. on windows)
kasperl 2012/10/10 12:21:05 Terminate comment with .
ricow1 2012/10/10 12:32:39 Done.
133 return Process.run("whoami", []).transform((result) {
134 if (result.exitCode != 0) {
135 return "";
136 }
137 return result.stdout;
138 }).transformException((e) {
139 return "";
140 });
141 }
142
143 RepositoryType get repositoryType {
144 if (new Directory(".svn").existsSync()) return RepositoryType.SVN;
145 if (new Directory(".git").existsSync()) return RepositoryType.GIT;
146 return RepositoryType.UNKNOWN;
147 }
148
149 String _versionFile;
kasperl 2012/10/10 12:21:05 We usually put fields at the top of class definiti
ricow1 2012/10/10 12:32:39 Done.
150 String USERNAME;
151 int REVISION;
152 int MAJOR;
153 int MINOR;
154 int BUILD;
155 int PATCH;
156 }
157
158 class RepositoryType {
159 static final RepositoryType SVN = const RepositoryType("SVN");
160 static final RepositoryType GIT = const RepositoryType("GIT");
161 static final RepositoryType UNKNOWN = const RepositoryType("UNKNOWN");
162
163 const RepositoryType(String this.name);
164
165 static RepositoryType guessType() {
166 if (new Directory(".svn").existsSync()) return RepositoryType.SVN;
167 if (new Directory(".git").existsSync()) return RepositoryType.GIT;
168 return RepositoryType.UNKNOWN;
169 }
170
171 String toString() => name;
172
173 final String name;
174 }
OLDNEW
« no previous file with comments | « no previous file | tools/version.dart » ('j') | tools/version.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698