| 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 * A utility function for test and tools that compensates (at least for very | 6 * A utility function for test and tools that compensates (at least for very |
| 7 * simple cases) for file-dependent programs being run from different | 7 * simple cases) for file-dependent programs being run from different |
| 8 * directories. | 8 * directories. The important cases are |
| 9 * -running in the directory that contains the test itself, i.e. |
| 10 * pkg/intl/test or a sub-directory. |
| 11 * -running in pkg/intl, which is where the editor will run things by default |
| 12 * -running in the top-level dart directory, where the build tests run |
| 9 */ | 13 */ |
| 10 library data_directory; | 14 library data_directory; |
| 11 | 15 |
| 12 import 'dart:io'; | 16 import "package:pathos/path.dart" as path; |
| 13 | 17 |
| 14 String get _sep => Platform.pathSeparator; | 18 String get dataDirectory { |
| 19 return path.join(intlDirectory, datesRelativeToIntl); |
| 20 } |
| 15 | 21 |
| 16 get dataDirectory { | 22 String get intlDirectory { |
| 17 var current = new Directory.current().path; | 23 var components = path.split(path.current); |
| 18 if (new RegExp('.*${_sep}test').hasMatch(current)) { | 24 var foundIntlDir = false; |
| 19 return '..${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}'; | 25 |
| 26 /** |
| 27 * A helper function that returns false (indicating we should stop iterating) |
| 28 * if the argument to the previous call was 'intl' and also sets |
| 29 * the outer scope [foundIntl]. |
| 30 */ |
| 31 bool checkForIntlDir(String each) { |
| 32 if (foundIntlDir) return false; |
| 33 foundIntlDir = (each == 'intl') ? true : false; |
| 34 return true; |
| 20 } | 35 } |
| 21 if (new RegExp('.*${_sep}intl').hasMatch(current)) { | 36 |
| 22 return 'lib${_sep}src${_sep}data${_sep}dates${_sep}'; | 37 var pathUpToIntl = components.takeWhile(checkForIntlDir).toList(); |
| 38 // We assume that if we're not somewhere underneath the intl hierarchy |
| 39 // that we are in the dart root. |
| 40 if (foundIntlDir) { |
| 41 return path.joinAll(pathUpToIntl); |
| 42 } else { |
| 43 return path.join(path.current, 'pkg', 'intl'); |
| 23 } | 44 } |
| 24 return 'pkg${_sep}intl${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}'; | |
| 25 } | 45 } |
| 46 |
| 47 String get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates'); |
| OLD | NEW |