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