| OLD | NEW |
| 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: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return c.future; | 112 return c.future; |
| 113 } | 113 } |
| 114 | 114 |
| 115 String getExecutableSuffix() { | 115 String getExecutableSuffix() { |
| 116 if (Platform.operatingSystem == 'windows') { | 116 if (Platform.operatingSystem == 'windows') { |
| 117 return '.bat'; | 117 return '.bat'; |
| 118 } | 118 } |
| 119 return ''; | 119 return ''; |
| 120 } | 120 } |
| 121 | 121 |
| 122 int getRevisionFromSvnInfo(String info) { |
| 123 if (info == null || info == '') return 0; |
| 124 var lines = info.split("\n"); |
| 125 RegExp exp = const RegExp(r"Revision: (\d*)"); |
| 126 for (var line in lines) { |
| 127 if (exp.hasMatch(line)) { |
| 128 String revisionString = (exp.firstMatch(line).group(1)); |
| 129 try { |
| 130 return int.parse(revisionString); |
| 131 } catch(e) { |
| 132 return 0; |
| 133 } |
| 134 } |
| 135 } |
| 136 return 0; |
| 137 } |
| 138 |
| 122 Future<int> getRevision() { | 139 Future<int> getRevision() { |
| 123 if (repositoryType == RepositoryType.UNKNOWN) { | 140 if (repositoryType == RepositoryType.UNKNOWN) { |
| 124 return new Future.immediate(0); | 141 return new Future.immediate(0); |
| 125 } | 142 } |
| 126 var isSvn = repositoryType == RepositoryType.SVN; | 143 var isSvn = repositoryType == RepositoryType.SVN; |
| 127 var command = isSvn ? "svn" : "git"; | 144 var command = isSvn ? "svn" : "git"; |
| 128 command = "$command${getExecutableSuffix()}"; | 145 command = "$command${getExecutableSuffix()}"; |
| 129 var arguments = isSvn ? ["info"] : ["svn", "info"]; | 146 var arguments = isSvn ? ["info"] : ["svn", "info"]; |
| 130 return Process.run(command, arguments).transform((result) { | 147 return Process.run(command, arguments).transform((result) { |
| 131 if (result.exitCode != 0) { | 148 if (result.exitCode != 0) { |
| 132 return 0; | 149 return 0; |
| 133 } | 150 } |
| 134 // If anything goes wrong parsing the revision we simply return 0. | 151 return getRevisionFromSvnInfo(result.stdout); |
| 135 try { | |
| 136 // Extract the revision. It's located at the 8th line, | |
| 137 // 18 characters in. | |
| 138 String revisionString = result.stdout.split("\n")[8].substring(18); | |
| 139 return int.parse(revisionString); | |
| 140 } catch (e) { | |
| 141 return 0; | |
| 142 } | |
| 143 }); | 152 }); |
| 144 } | 153 } |
| 145 | 154 |
| 146 String getUserName() { | 155 String getUserName() { |
| 147 // TODO(ricow): Don't add this on the buildbot. | 156 // TODO(ricow): Don't add this on the buildbot. |
| 148 var key = "USER"; | 157 var key = "USER"; |
| 149 if (Platform.operatingSystem == 'windows') { | 158 if (Platform.operatingSystem == 'windows') { |
| 150 key = "USERNAME"; | 159 key = "USERNAME"; |
| 151 } | 160 } |
| 152 if (!Platform.environment.containsKey(key)) return ""; | 161 if (!Platform.environment.containsKey(key)) return ""; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 170 static RepositoryType guessType() { | 179 static RepositoryType guessType() { |
| 171 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; | 180 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; |
| 172 if (new Directory(".git").existsSync()) return RepositoryType.GIT; | 181 if (new Directory(".git").existsSync()) return RepositoryType.GIT; |
| 173 return RepositoryType.UNKNOWN; | 182 return RepositoryType.UNKNOWN; |
| 174 } | 183 } |
| 175 | 184 |
| 176 String toString() => name; | 185 String toString() => name; |
| 177 | 186 |
| 178 final String name; | 187 final String name; |
| 179 } | 188 } |
| OLD | NEW |