Chromium Code Reviews| 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 "dart:io"; |
| 17 import "package:pathos/path.dart" as path; | 17 import "package:pathos/path.dart" as path; |
| 18 | 18 |
| 19 String get dataDirectory { | 19 String get dataDirectory { |
| 20 return path.join(intlDirectory, datesRelativeToIntl); | 20 return path.join(intlDirectory(), datesRelativeToIntl); |
| 21 } | 21 } |
| 22 | 22 |
| 23 String get intlDirectory { | 23 String intlDirectory() { |
| 24 var components = path.split(path.current); | 24 var components = path.split(path.current); |
| 25 var foundIntlDir = false; | 25 var foundIntlDir = false; |
| 26 | 26 |
| 27 /** | 27 List findPathUpToIntl() { |
| 28 * A helper function that returns false (indicating we should stop iterating) | 28 var result = []; |
| 29 * if the argument to the previous call was 'intl' and also sets | 29 for (var each in components) { |
|
Siggi Cherem (dart-lang)
2013/04/23 02:12:51
nit: 'each' => 'segment' or 'component'?
(general
Emily Fortuna
2013/04/23 17:24:48
+1
Alan Knight
2013/04/23 17:59:56
This is moot, because this file's changes were bec
Siggi Cherem (dart-lang)
2013/04/23 18:56:37
sure - I noticed that the original code is also us
Alan Knight
2013/04/23 21:37:19
Done.
| |
| 30 * the outer scope [foundIntl]. | 30 if (each == 'intl') { |
| 31 */ | 31 foundIntlDir = true; |
| 32 bool checkForIntlDir(String each) { | 32 result.add(each); |
| 33 if (foundIntlDir) return false; | 33 return result; |
| 34 foundIntlDir = (each == 'intl') ? true : false; | 34 } else { |
| 35 return true; | 35 result.add(each); |
| 36 } | |
| 37 } | |
| 38 return result; | |
| 36 } | 39 } |
| 37 | 40 |
| 38 var pathUpToIntl = components.takeWhile(checkForIntlDir).toList(); | 41 var pathUpToIntl = findPathUpToIntl(); |
| 39 // We assume that if we're not somewhere underneath the intl hierarchy | 42 // We assume that if we're not somewhere underneath the intl hierarchy |
| 40 // that we are in the dart root. | 43 // that we are in the dart root. |
| 41 if (foundIntlDir) { | 44 if (foundIntlDir) { |
| 42 return path.joinAll(pathUpToIntl); | 45 return path.joinAll(pathUpToIntl); |
| 43 } else { | 46 } else { |
| 44 if (new Directory(path.join(path.current, 'pkg', 'intl')).existsSync()) { | 47 if (new Directory(path.join(path.current, 'pkg', 'intl')).existsSync()) { |
| 45 return path.join(path.current, 'pkg', 'intl'); | 48 return path.join(path.current, 'pkg', 'intl'); |
| 46 } | 49 } |
| 47 if (new Directory( | 50 if (new Directory( |
| 48 path.join(path.current, '..', 'pkg', 'intl')).existsSync()) { | 51 path.join(path.current, '..', 'pkg', 'intl')).existsSync()) { |
| 49 return path.join(path.current, '..', 'pkg', 'intl'); | 52 return path.join(path.current, '..', 'pkg', 'intl'); |
| 50 } | 53 } |
| 51 } | 54 } |
| 52 throw new UnsupportedError( | 55 throw new UnsupportedError( |
| 53 'Cannot find ${path.join('pkg','intl')} directory.'); | 56 'Cannot find ${path.join('pkg','intl')} directory.'); |
| 54 } | 57 } |
| 55 | 58 |
| 56 String get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates'); | 59 String get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates'); |
| OLD | NEW |