| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 c.completeException("Wrong format in VERSION file, line does not " | 88 c.completeException("Wrong format in VERSION file, line does not " |
| 89 "contain one of {MAJOR, MINOR, BUILD, PATCH}"); | 89 "contain one of {MAJOR, MINOR, BUILD, PATCH}"); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 }; | 92 }; |
| 93 input.onClosed = () { | 93 input.onClosed = () { |
| 94 // Only complete if we did not already complete with a failure. | 94 // Only complete if we did not already complete with a failure. |
| 95 if (!c.future.isComplete) { | 95 if (!c.future.isComplete) { |
| 96 getRevision().then((revision) { | 96 getRevision().then((revision) { |
| 97 REVISION = revision; | 97 REVISION = revision; |
| 98 getUserName().then((username) { | 98 USERNAME = getUserName(); |
| 99 USERNAME = username; | 99 var userNameString = ""; |
| 100 if (username != '') username = "_$username"; | 100 if (USERNAME != '') userNameString = "_$USERNAME"; |
| 101 var revisionString = ""; | 101 var revisionString = ""; |
| 102 if (revision != 0) revisionString = "_r$revision"; | 102 if (revision != 0) revisionString = "_r$revision"; |
| 103 c.complete("$MAJOR.$MINOR.$BUILD.$PATCH$revisionString$username"); | 103 c.complete( |
| 104 return; | 104 "$MAJOR.$MINOR.$BUILD.$PATCH$revisionString$userNameString"); |
| 105 }); | 105 return; |
| 106 }); | 106 }); |
| 107 } | 107 } |
| 108 }; | 108 }; |
| 109 }); | 109 }); |
| 110 return c.future; | 110 return c.future; |
| 111 } | 111 } |
| 112 | 112 |
| 113 String getExecutableSuffix() { |
| 114 if (Platform.operatingSystem == 'windows') { |
| 115 return '.exe'; |
| 116 } |
| 117 return ''; |
| 118 } |
| 119 |
| 113 Future<int> getRevision() { | 120 Future<int> getRevision() { |
| 114 if (repositoryType == RepositoryType.UNKNOWN) { | 121 if (repositoryType == RepositoryType.UNKNOWN) { |
| 115 return new Future.immediate(0); | 122 return new Future.immediate(0); |
| 116 } | 123 } |
| 117 var isSvn = repositoryType == RepositoryType.SVN; | 124 var isSvn = repositoryType == RepositoryType.SVN; |
| 118 var command = isSvn ? "svn" : "git"; | 125 var command = isSvn ? "svn" : "git"; |
| 126 command = "$command${getExecutableSuffix()}"; |
| 119 var arguments = isSvn ? ["info"] : ["svn", "info"]; | 127 var arguments = isSvn ? ["info"] : ["svn", "info"]; |
| 120 return Process.run(command, arguments).transform((result) { | 128 return Process.run(command, arguments).transform((result) { |
| 121 if (result.exitCode != 0) { | 129 if (result.exitCode != 0) { |
| 122 return 0; | 130 return 0; |
| 123 } | 131 } |
| 124 // If anything goes wrong parsing the revision we simply return 0. | 132 // If anything goes wrong parsing the revision we simply return 0. |
| 125 try { | 133 try { |
| 126 // Extract the revision. It's located at the 8th line, | 134 // Extract the revision. It's located at the 8th line, |
| 127 // 18 characters in. | 135 // 18 characters in. |
| 128 String revisionString = result.stdout.split("\n")[8].substring(18); | 136 String revisionString = result.stdout.split("\n")[8].substring(18); |
| 129 return int.parse(revisionString); | 137 return int.parse(revisionString); |
| 130 } catch (e) { | 138 } catch (e) { |
| 131 return 0; | 139 return 0; |
| 132 } | 140 } |
| 133 }); | 141 }); |
| 134 } | 142 } |
| 135 | 143 |
| 136 Future<String> getUserName() { | 144 String getUserName() { |
| 137 // TODO(ricow): Don't add this on the buildbot. | 145 // TODO(ricow): Don't add this on the buildbot. |
| 138 // If we can't get the username simple return "" (e.g. on windows). | 146 if (!Platform.environment.containsKey("USER")) return ""; |
| 139 return Process.run("whoami", []).transform((result) { | 147 return Platform.environment["USER"]; |
| 140 if (result.exitCode != 0) { | |
| 141 return ""; | |
| 142 } | |
| 143 return result.stdout; | |
| 144 }).transformException((e) { | |
| 145 return ""; | |
| 146 }); | |
| 147 } | 148 } |
| 148 | 149 |
| 149 RepositoryType get repositoryType { | 150 RepositoryType get repositoryType { |
| 150 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; | 151 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; |
| 151 if (new Directory(".git").existsSync()) return RepositoryType.GIT; | 152 if (new Directory(".git").existsSync()) return RepositoryType.GIT; |
| 152 return RepositoryType.UNKNOWN; | 153 return RepositoryType.UNKNOWN; |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 | 156 |
| 156 class RepositoryType { | 157 class RepositoryType { |
| 157 static final RepositoryType SVN = const RepositoryType("SVN"); | 158 static final RepositoryType SVN = const RepositoryType("SVN"); |
| 158 static final RepositoryType GIT = const RepositoryType("GIT"); | 159 static final RepositoryType GIT = const RepositoryType("GIT"); |
| 159 static final RepositoryType UNKNOWN = const RepositoryType("UNKNOWN"); | 160 static final RepositoryType UNKNOWN = const RepositoryType("UNKNOWN"); |
| 160 | 161 |
| 161 const RepositoryType(String this.name); | 162 const RepositoryType(String this.name); |
| 162 | 163 |
| 163 static RepositoryType guessType() { | 164 static RepositoryType guessType() { |
| 164 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; | 165 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; |
| 165 if (new Directory(".git").existsSync()) return RepositoryType.GIT; | 166 if (new Directory(".git").existsSync()) return RepositoryType.GIT; |
| 166 return RepositoryType.UNKNOWN; | 167 return RepositoryType.UNKNOWN; |
| 167 } | 168 } |
| 168 | 169 |
| 169 String toString() => name; | 170 String toString() => name; |
| 170 | 171 |
| 171 final String name; | 172 final String name; |
| 172 } | 173 } |
| OLD | NEW |