OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.generated.sdk; | 5 library analyzer.src.generated.sdk; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
13 show AnalysisContext, AnalysisOptions, AnalysisOptionsImpl; | 13 show AnalysisContext, AnalysisOptions, AnalysisOptionsImpl; |
14 import 'package:analyzer/src/generated/source.dart' show Source; | 14 import 'package:analyzer/src/generated/source.dart' show Source; |
15 import 'package:analyzer/src/generated/utilities_general.dart'; | 15 import 'package:analyzer/src/generated/utilities_general.dart'; |
16 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; | 16 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; |
17 import 'package:path/path.dart' as pathos; | |
17 | 18 |
18 /** | 19 /** |
19 * A function used to create a new DartSdk with the given [options]. If the | 20 * A function used to create a new DartSdk with the given [options]. If the |
20 * passed [options] are `null`, then default options are used. | 21 * passed [options] are `null`, then default options are used. |
21 */ | 22 */ |
22 typedef DartSdk SdkCreator(AnalysisOptions options); | 23 typedef DartSdk SdkCreator(AnalysisOptions options); |
23 | 24 |
24 /** | 25 /** |
25 * A Dart SDK installed in a specified location. | 26 * A Dart SDK installed in a specified location. |
26 */ | 27 */ |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 library.documented = (expression as BooleanLiteral).value; | 413 library.documented = (expression as BooleanLiteral).value; |
413 } else if (name == _PATCHES) { | 414 } else if (name == _PATCHES) { |
414 if (expression is MapLiteral) { | 415 if (expression is MapLiteral) { |
415 expression.entries.forEach((MapLiteralEntry entry) { | 416 expression.entries.forEach((MapLiteralEntry entry) { |
416 int platforms = _convertPlatforms(entry.key); | 417 int platforms = _convertPlatforms(entry.key); |
417 Expression pathsListLiteral = entry.value; | 418 Expression pathsListLiteral = entry.value; |
418 if (pathsListLiteral is ListLiteral) { | 419 if (pathsListLiteral is ListLiteral) { |
419 List<String> paths = <String>[]; | 420 List<String> paths = <String>[]; |
420 pathsListLiteral.elements.forEach((Expression pathExpr) { | 421 pathsListLiteral.elements.forEach((Expression pathExpr) { |
421 if (pathExpr is SimpleStringLiteral) { | 422 if (pathExpr is SimpleStringLiteral) { |
422 paths.add(pathExpr.value); | 423 String path = pathExpr.value; |
424 _validatePatchPath(path); | |
425 paths.add(path); | |
423 } else { | 426 } else { |
424 throw new ArgumentError( | 427 throw new ArgumentError( |
425 'The "patch" argument items must be simple strings.'); | 428 'The "patch" argument items must be simple strings.'); |
426 } | 429 } |
427 }); | 430 }); |
428 library.setPatchPaths(platforms, paths); | 431 library.setPatchPaths(platforms, paths); |
429 } else { | 432 } else { |
430 throw new ArgumentError( | 433 throw new ArgumentError( |
431 'The "patch" argument values must be list literals.'); | 434 'The "patch" argument values must be list literals.'); |
432 } | 435 } |
(...skipping 14 matching lines...) Expand all Loading... | |
447 } | 450 } |
448 } | 451 } |
449 } | 452 } |
450 } | 453 } |
451 _librariesMap.setLibrary(libraryName, library); | 454 _librariesMap.setLibrary(libraryName, library); |
452 } | 455 } |
453 return null; | 456 return null; |
454 } | 457 } |
455 | 458 |
456 /** | 459 /** |
460 * Validate the given [path] to a patch file. Throw [ArgumentError] if not a | |
461 * valid path: is absolute, or contains `..`. | |
462 */ | |
463 void _validatePatchPath(String path) { | |
464 if (path.contains(r'\')) { | |
465 throw new ArgumentError('The path to a patch file must be posix: $path'); | |
466 } | |
467 if (pathos.isAbsolute(path)) { | |
Paul Berry
2016/10/11 16:57:51
Use pathos.posix.isAbsolute() so that we don't get
| |
468 throw new ArgumentError( | |
469 'The path to a patch file cannot be absolute: $path'); | |
470 } | |
471 if (path.contains('..')) { | |
472 throw new ArgumentError( | |
473 'The path to a patch file cannot contain "..": $path'); | |
474 } | |
475 } | |
476 | |
477 /** | |
457 * Return the platform constant value for the given [expr]. | 478 * Return the platform constant value for the given [expr]. |
458 * Throw [ArgumentError] if not a valid platform name given. | 479 * Throw [ArgumentError] if not a valid platform name given. |
459 */ | 480 */ |
460 static int _convertPlatform(Expression expr) { | 481 static int _convertPlatform(Expression expr) { |
461 if (expr is SimpleIdentifier) { | 482 if (expr is SimpleIdentifier) { |
462 String name = expr.name; | 483 String name = expr.name; |
463 if (name == _DART2JS_PLATFORM) { | 484 if (name == _DART2JS_PLATFORM) { |
464 return SdkLibraryImpl.DART2JS_PLATFORM; | 485 return SdkLibraryImpl.DART2JS_PLATFORM; |
465 } | 486 } |
466 if (name == _VM_PLATFORM) { | 487 if (name == _VM_PLATFORM) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 _platformsToPatchPaths[platforms] = paths; | 684 _platformsToPatchPaths[platforms] = paths; |
664 } | 685 } |
665 | 686 |
666 /** | 687 /** |
667 * Record that this library can be run on the VM. | 688 * Record that this library can be run on the VM. |
668 */ | 689 */ |
669 void setVmLibrary() { | 690 void setVmLibrary() { |
670 _platforms |= VM_PLATFORM; | 691 _platforms |= VM_PLATFORM; |
671 } | 692 } |
672 } | 693 } |
OLD | NEW |