| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library dart2js.src.options; | |
| 6 | |
| 7 import 'commandline_options.dart' show Flags; | |
| 8 import '../compiler.dart' show PackagesDiscoveryProvider; | |
| 9 | |
| 10 /// Options used for parsing. | |
| 11 /// | |
| 12 /// Use this to conditionally support certain constructs, e.g., | |
| 13 /// experimental ones. | |
| 14 abstract class ParserOptions { | |
| 15 const ParserOptions(); | |
| 16 | |
| 17 /// Support conditional directives, e.g., configurable imports. | |
| 18 bool get enableConditionalDirectives; | |
| 19 } | |
| 20 | |
| 21 /// Options used for controlling diagnostic messages. | |
| 22 abstract class DiagnosticOptions { | |
| 23 const DiagnosticOptions(); | |
| 24 | |
| 25 /// If `true`, warnings cause the compilation to fail. | |
| 26 bool get fatalWarnings; | |
| 27 | |
| 28 /// Emit terse diagnostics without howToFix. | |
| 29 bool get terseDiagnostics; | |
| 30 | |
| 31 /// If `true`, warnings are not reported. | |
| 32 bool get suppressWarnings; | |
| 33 | |
| 34 /// If `true`, hints are not reported. | |
| 35 bool get suppressHints; | |
| 36 | |
| 37 /// Returns `true` if warnings and hints are shown for all packages. | |
| 38 bool get showAllPackageWarnings; | |
| 39 | |
| 40 /// Returns `true` if warnings and hints are hidden for all packages. | |
| 41 bool get hidePackageWarnings; | |
| 42 | |
| 43 /// Returns `true` if warnings should be should for [uri]. | |
| 44 bool showPackageWarningsFor(Uri uri); | |
| 45 } | |
| 46 | |
| 47 /// Object for passing options to the compiler. Superclasses are used to select | |
| 48 /// subsets of these options, enabling each part of the compiler to depend on | |
| 49 /// as few as possible. | |
| 50 class CompilerOptions implements DiagnosticOptions, ParserOptions { | |
| 51 /// The entry point of the application that is being compiled. | |
| 52 final Uri entryPoint; | |
| 53 | |
| 54 /// Root location where SDK libraries are found. | |
| 55 final Uri libraryRoot; | |
| 56 | |
| 57 /// Package root location. | |
| 58 /// | |
| 59 /// If not null then [packageConfig] should be null. | |
| 60 final Uri packageRoot; | |
| 61 | |
| 62 /// Location of the package configuration file. | |
| 63 /// | |
| 64 /// If not null then [packageRoot] should be null. | |
| 65 final Uri packageConfig; | |
| 66 | |
| 67 // TODO(sigmund): Move out of here, maybe to CompilerInput. Options should not | |
| 68 // hold code, just configuration options. | |
| 69 final PackagesDiscoveryProvider packagesDiscoveryProvider; | |
| 70 | |
| 71 /// Resolved constant "environment" values passed to the compiler via the `-D` | |
| 72 /// flags. | |
| 73 final Map<String, dynamic> environment; | |
| 74 | |
| 75 /// Whether we allow mocking compilation of libraries such as dart:io and | |
| 76 /// dart:html for unit testing purposes. | |
| 77 final bool allowMockCompilation; | |
| 78 | |
| 79 /// Whether the native extension syntax is supported by the frontend. | |
| 80 final bool allowNativeExtensions; | |
| 81 | |
| 82 /// Whether to resolve all functions in the program, not just those reachable | |
| 83 /// from main. This implies [analyzeOnly] is true as well. | |
| 84 final bool analyzeAll; | |
| 85 | |
| 86 /// Whether to disable tree-shaking for the main script. This marks all | |
| 87 /// functions in the main script as reachable (not just a function named | |
| 88 /// `main`). | |
| 89 // TODO(sigmund): rename. The current name seems to indicate that only the | |
| 90 // main function is retained, which is the opposite of what this does. | |
| 91 final bool analyzeMain; | |
| 92 | |
| 93 /// Whether to run the compiler just for the purpose of analysis. That is, to | |
| 94 /// run resolution and type-checking alone, but otherwise do not generate any | |
| 95 /// code. | |
| 96 final bool analyzeOnly; | |
| 97 | |
| 98 /// Whether to skip analysis of method bodies and field initializers. Implies | |
| 99 /// [analyzeOnly]. | |
| 100 final bool analyzeSignaturesOnly; | |
| 101 | |
| 102 /// ID associated with this sdk build. | |
| 103 final String buildId; | |
| 104 | |
| 105 /// Whether there is a build-id available so we can use it on error messages | |
| 106 /// and in the emitted output of the compiler. | |
| 107 bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID; | |
| 108 | |
| 109 /// Location where to generate a map containing details of how deferred | |
| 110 /// libraries are subdivided. | |
| 111 final Uri deferredMapUri; | |
| 112 | |
| 113 /// Whether to disable inlining during the backend optimizations. | |
| 114 // TODO(sigmund): negate, so all flags are positive | |
| 115 final bool disableInlining; | |
| 116 | |
| 117 /// Diagnostic option: If `true`, warnings cause the compilation to fail. | |
| 118 final bool fatalWarnings; | |
| 119 | |
| 120 /// Diagnostic option: Emit terse diagnostics without howToFix. | |
| 121 final bool terseDiagnostics; | |
| 122 | |
| 123 /// Diagnostic option: If `true`, warnings are not reported. | |
| 124 final bool suppressWarnings; | |
| 125 | |
| 126 /// Diagnostic option: If `true`, hints are not reported. | |
| 127 final bool suppressHints; | |
| 128 | |
| 129 /// Diagnostic option: List of packages for which warnings and hints are | |
| 130 /// reported. If `null`, no package warnings or hints are reported. If | |
| 131 /// empty, all warnings and hints are reported. | |
| 132 final List<String> _shownPackageWarnings; | |
| 133 | |
| 134 /// Whether to disable global type inference. | |
| 135 final bool disableTypeInference; | |
| 136 | |
| 137 /// Whether to emit a .json file with a summary of the information used by the | |
| 138 /// compiler during optimization. This includes resolution details, | |
| 139 /// dependencies between elements, results of type inference, and the output | |
| 140 /// code for each function. | |
| 141 final bool dumpInfo; | |
| 142 | |
| 143 /// Whether we allow passing an extra argument to `assert`, containing a | |
| 144 /// reason for why an assertion fails. (experimental) | |
| 145 final bool enableAssertMessage; | |
| 146 | |
| 147 /// Whether to enable the experimental conditional directives feature. | |
| 148 final bool enableConditionalDirectives; | |
| 149 | |
| 150 /// Whether the user specified a flag to allow the use of dart:mirrors. This | |
| 151 /// silences a warning produced by the compiler. | |
| 152 final bool enableExperimentalMirrors; | |
| 153 | |
| 154 /// Whether to enable minification | |
| 155 // TODO(sigmund): rename to minify | |
| 156 final bool enableMinification; | |
| 157 | |
| 158 /// Whether to model which native classes are live based on annotations on the | |
| 159 /// core libraries. If false, all native classes will be included by default. | |
| 160 final bool enableNativeLiveTypeAnalysis; | |
| 161 | |
| 162 /// Whether to generate code containing checked-mode assignability checks. | |
| 163 final bool enableTypeAssertions; | |
| 164 | |
| 165 /// Whether to generate code containing user's `assert` statements. | |
| 166 final bool enableUserAssertions; | |
| 167 | |
| 168 /// Whether to generate output even when there are compile-time errors. | |
| 169 final bool generateCodeWithCompileTimeErrors; | |
| 170 | |
| 171 /// Whether to generate a source-map file together with the output program. | |
| 172 final bool generateSourceMap; | |
| 173 | |
| 174 /// Whether some values are cached for reuse in incremental compilation. | |
| 175 /// Incremental compilation allows calling `Compiler.run` more than once | |
| 176 /// (experimental). | |
| 177 final bool hasIncrementalSupport; | |
| 178 | |
| 179 /// URI of the main output if the compiler is generating source maps. | |
| 180 final Uri outputUri; | |
| 181 | |
| 182 /// Location of the platform configuration file. | |
| 183 final Uri platformConfigUri; | |
| 184 | |
| 185 /// Whether to emit URIs in the reflection metadata. | |
| 186 final bool preserveUris; | |
| 187 | |
| 188 /// URI where the compiler should generate the output source map file. | |
| 189 final Uri sourceMapUri; | |
| 190 | |
| 191 /// The compiler is run from the build bot. | |
| 192 final bool testMode; | |
| 193 | |
| 194 /// Whether to trust JS-interop annotations. (experimental) | |
| 195 final bool trustJSInteropTypeAnnotations; | |
| 196 | |
| 197 /// Whether to trust primitive types during inference and optimizations. | |
| 198 final bool trustPrimitives; | |
| 199 | |
| 200 /// Whether to trust type annotations during inference and optimizations. | |
| 201 final bool trustTypeAnnotations; | |
| 202 | |
| 203 /// Whether to generate code compliant with content security policy (CSP). | |
| 204 final bool useContentSecurityPolicy; | |
| 205 | |
| 206 /// Use the experimental CPS based backend. | |
| 207 final bool useCpsIr; | |
| 208 | |
| 209 /// When obfuscating for minification, whether to use the frequency of a name | |
| 210 /// as an heuristic to pick shorter names. | |
| 211 final bool useFrequencyNamer; | |
| 212 | |
| 213 /// Whether to use the new source-information implementation for source-maps. | |
| 214 /// (experimental) | |
| 215 final bool useNewSourceInfo; | |
| 216 | |
| 217 /// Whether the user requested to use the fast startup emitter. The full | |
| 218 /// emitter might still be used if the program uses dart:mirrors. | |
| 219 final bool useStartupEmitter; | |
| 220 | |
| 221 /// Enable verbose printing during compilation. Includes progress messages | |
| 222 /// during each phase and a time-breakdown between phases at the end. | |
| 223 final bool verbose; | |
| 224 | |
| 225 // ------------------------------------------------- | |
| 226 // Options for deprecated features | |
| 227 // ------------------------------------------------- | |
| 228 // TODO(sigmund): delete these as we delete the underlying features | |
| 229 | |
| 230 /// Whether to preserve comments while scanning (only use for dart:mirrors). | |
| 231 final bool preserveComments; | |
| 232 | |
| 233 /// Whether to emit JavaScript (false enables dart2dart). | |
| 234 final bool emitJavaScript; | |
| 235 | |
| 236 /// When using dart2dart, whether to use the multi file format. | |
| 237 final bool dart2dartMultiFile; | |
| 238 | |
| 239 /// Strip option used by dart2dart. | |
| 240 final List<String> strips; | |
| 241 | |
| 242 /// Create an options object by parsing flags from [options]. | |
| 243 factory CompilerOptions.parse( | |
| 244 {Uri entryPoint, | |
| 245 Uri libraryRoot, | |
| 246 Uri packageRoot, | |
| 247 Uri packageConfig, | |
| 248 PackagesDiscoveryProvider packagesDiscoveryProvider, | |
| 249 Map<String, dynamic> environment: const <String, dynamic>{}, | |
| 250 List<String> options}) { | |
| 251 return new CompilerOptions( | |
| 252 entryPoint: entryPoint, | |
| 253 libraryRoot: libraryRoot, | |
| 254 packageRoot: packageRoot, | |
| 255 packageConfig: packageConfig, | |
| 256 packagesDiscoveryProvider: packagesDiscoveryProvider, | |
| 257 environment: environment, | |
| 258 allowMockCompilation: _hasOption(options, Flags.allowMockCompilation), | |
| 259 allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions), | |
| 260 analyzeAll: _hasOption(options, Flags.analyzeAll), | |
| 261 analyzeMain: _hasOption(options, Flags.analyzeMain), | |
| 262 analyzeOnly: _hasOption(options, Flags.analyzeOnly), | |
| 263 analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly), | |
| 264 buildId: _extractStringOption( | |
| 265 options, '--build-id=', _UNDETERMINED_BUILD_ID), | |
| 266 dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'), | |
| 267 deferredMapUri: _extractUriOption(options, '--deferred-map='), | |
| 268 fatalWarnings: _hasOption(options, Flags.fatalWarnings), | |
| 269 terseDiagnostics: _hasOption(options, Flags.terse), | |
| 270 suppressWarnings: _hasOption(options, Flags.suppressWarnings), | |
| 271 suppressHints: _hasOption(options, Flags.suppressHints), | |
| 272 shownPackageWarnings: | |
| 273 _extractOptionalCsvOption(options, Flags.showPackageWarnings), | |
| 274 disableInlining: _hasOption(options, Flags.disableInlining), | |
| 275 disableTypeInference: _hasOption(options, Flags.disableTypeInference), | |
| 276 dumpInfo: _hasOption(options, Flags.dumpInfo), | |
| 277 emitJavaScript: !(_hasOption(options, '--output-type=dart') || | |
| 278 _hasOption(options, '--output-type=dart-multi')), | |
| 279 enableAssertMessage: _hasOption(options, Flags.enableAssertMessage), | |
| 280 enableConditionalDirectives: | |
| 281 _hasOption(options, Flags.conditionalDirectives), | |
| 282 enableExperimentalMirrors: | |
| 283 _hasOption(options, Flags.enableExperimentalMirrors), | |
| 284 enableMinification: _hasOption(options, Flags.minify), | |
| 285 enableNativeLiveTypeAnalysis: | |
| 286 !_hasOption(options, Flags.disableNativeLiveTypeAnalysis), | |
| 287 enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode), | |
| 288 enableUserAssertions: _hasOption(options, Flags.enableCheckedMode), | |
| 289 generateCodeWithCompileTimeErrors: | |
| 290 _hasOption(options, Flags.generateCodeWithCompileTimeErrors), | |
| 291 generateSourceMap: !_hasOption(options, Flags.noSourceMaps), | |
| 292 hasIncrementalSupport: _forceIncrementalSupport || | |
| 293 _hasOption(options, Flags.incrementalSupport), | |
| 294 outputUri: _extractUriOption(options, '--out='), | |
| 295 platformConfigUri: | |
| 296 _resolvePlatformConfigFromOptions(libraryRoot, options), | |
| 297 preserveComments: _hasOption(options, Flags.preserveComments), | |
| 298 preserveUris: _hasOption(options, Flags.preserveUris), | |
| 299 sourceMapUri: _extractUriOption(options, '--source-map='), | |
| 300 strips: _extractCsvOption(options, '--force-strip='), | |
| 301 testMode: _hasOption(options, Flags.testMode), | |
| 302 trustJSInteropTypeAnnotations: | |
| 303 _hasOption(options, Flags.trustJSInteropTypeAnnotations), | |
| 304 trustPrimitives: _hasOption(options, Flags.trustPrimitives), | |
| 305 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations), | |
| 306 useContentSecurityPolicy: | |
| 307 _hasOption(options, Flags.useContentSecurityPolicy), | |
| 308 useCpsIr: _hasOption(options, Flags.useCpsIr), | |
| 309 useFrequencyNamer: | |
| 310 !_hasOption(options, Flags.noFrequencyBasedMinification), | |
| 311 useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo), | |
| 312 useStartupEmitter: _hasOption(options, Flags.fastStartup), | |
| 313 verbose: _hasOption(options, Flags.verbose)); | |
| 314 } | |
| 315 | |
| 316 /// Creates an option object for the compiler. | |
| 317 /// | |
| 318 /// This validates and normalizes dependent options to be consistent. For | |
| 319 /// example, if [analyzeAll] is true, the resulting options object will also | |
| 320 /// have [analyzeOnly] as true. | |
| 321 factory CompilerOptions( | |
| 322 {Uri entryPoint, | |
| 323 Uri libraryRoot, | |
| 324 Uri packageRoot, | |
| 325 Uri packageConfig, | |
| 326 PackagesDiscoveryProvider packagesDiscoveryProvider, | |
| 327 Map<String, dynamic> environment: const <String, dynamic>{}, | |
| 328 bool allowMockCompilation: false, | |
| 329 bool allowNativeExtensions: false, | |
| 330 bool analyzeAll: false, | |
| 331 bool analyzeMain: false, | |
| 332 bool analyzeOnly: false, | |
| 333 bool analyzeSignaturesOnly: false, | |
| 334 String buildId: _UNDETERMINED_BUILD_ID, | |
| 335 bool dart2dartMultiFile: false, | |
| 336 Uri deferredMapUri: null, | |
| 337 bool fatalWarnings: false, | |
| 338 bool terseDiagnostics: false, | |
| 339 bool suppressWarnings: false, | |
| 340 bool suppressHints: false, | |
| 341 List<String> shownPackageWarnings: null, | |
| 342 bool disableInlining: false, | |
| 343 bool disableTypeInference: false, | |
| 344 bool dumpInfo: false, | |
| 345 bool emitJavaScript: true, | |
| 346 bool enableAssertMessage: false, | |
| 347 bool enableConditionalDirectives: false, | |
| 348 bool enableExperimentalMirrors: false, | |
| 349 bool enableMinification: false, | |
| 350 bool enableNativeLiveTypeAnalysis: true, | |
| 351 bool enableTypeAssertions: false, | |
| 352 bool enableUserAssertions: false, | |
| 353 bool generateCodeWithCompileTimeErrors: false, | |
| 354 bool generateSourceMap: true, | |
| 355 bool hasIncrementalSupport: false, | |
| 356 Uri outputUri: null, | |
| 357 Uri platformConfigUri: null, | |
| 358 bool preserveComments: false, | |
| 359 bool preserveUris: false, | |
| 360 Uri sourceMapUri: null, | |
| 361 List<String> strips: const [], | |
| 362 bool testMode: false, | |
| 363 bool trustJSInteropTypeAnnotations: false, | |
| 364 bool trustPrimitives: false, | |
| 365 bool trustTypeAnnotations: false, | |
| 366 bool useContentSecurityPolicy: false, | |
| 367 bool useCpsIr: false, | |
| 368 bool useFrequencyNamer: true, | |
| 369 bool useNewSourceInfo: false, | |
| 370 bool useStartupEmitter: false, | |
| 371 bool verbose: false}) { | |
| 372 // TODO(sigmund): should entrypoint be here? should we validate it is not | |
| 373 // null? In unittests we use the same compiler to analyze or build multiple | |
| 374 // entrypoints. | |
| 375 if (libraryRoot == null) { | |
| 376 throw new ArgumentError("[libraryRoot] is null."); | |
| 377 } | |
| 378 if (!libraryRoot.path.endsWith("/")) { | |
| 379 throw new ArgumentError("[libraryRoot] must end with a /"); | |
| 380 } | |
| 381 if (packageRoot != null && packageConfig != null) { | |
| 382 throw new ArgumentError("Only one of [packageRoot] or [packageConfig] " | |
| 383 "may be given."); | |
| 384 } | |
| 385 if (packageRoot != null && !packageRoot.path.endsWith("/")) { | |
| 386 throw new ArgumentError("[packageRoot] must end with a /"); | |
| 387 } | |
| 388 if (!analyzeOnly) { | |
| 389 if (allowNativeExtensions) { | |
| 390 throw new ArgumentError( | |
| 391 "${Flags.allowNativeExtensions} is only supported in combination " | |
| 392 "with ${Flags.analyzeOnly}"); | |
| 393 } | |
| 394 } | |
| 395 return new CompilerOptions._(entryPoint, libraryRoot, packageRoot, | |
| 396 packageConfig, packagesDiscoveryProvider, environment, | |
| 397 allowMockCompilation: allowMockCompilation, | |
| 398 allowNativeExtensions: allowNativeExtensions, | |
| 399 analyzeAll: analyzeAll, | |
| 400 analyzeMain: analyzeMain, | |
| 401 analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll, | |
| 402 analyzeSignaturesOnly: analyzeSignaturesOnly, | |
| 403 buildId: buildId, | |
| 404 dart2dartMultiFile: dart2dartMultiFile, | |
| 405 deferredMapUri: deferredMapUri, | |
| 406 fatalWarnings: fatalWarnings, | |
| 407 terseDiagnostics: terseDiagnostics, | |
| 408 suppressWarnings: suppressWarnings, | |
| 409 suppressHints: suppressHints, | |
| 410 shownPackageWarnings: shownPackageWarnings, | |
| 411 disableInlining: disableInlining || hasIncrementalSupport, | |
| 412 disableTypeInference: disableTypeInference || !emitJavaScript, | |
| 413 dumpInfo: dumpInfo, | |
| 414 emitJavaScript: emitJavaScript, | |
| 415 enableAssertMessage: enableAssertMessage, | |
| 416 enableConditionalDirectives: enableConditionalDirectives, | |
| 417 enableExperimentalMirrors: enableExperimentalMirrors, | |
| 418 enableMinification: enableMinification, | |
| 419 enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis, | |
| 420 enableTypeAssertions: enableTypeAssertions, | |
| 421 enableUserAssertions: enableUserAssertions, | |
| 422 generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors, | |
| 423 generateSourceMap: generateSourceMap, | |
| 424 hasIncrementalSupport: hasIncrementalSupport, | |
| 425 outputUri: outputUri, | |
| 426 platformConfigUri: platformConfigUri ?? | |
| 427 _resolvePlatformConfig( | |
| 428 libraryRoot, null, !emitJavaScript, const []), | |
| 429 preserveComments: preserveComments, | |
| 430 preserveUris: preserveUris, | |
| 431 sourceMapUri: sourceMapUri, | |
| 432 strips: strips, | |
| 433 testMode: testMode, | |
| 434 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, | |
| 435 trustPrimitives: trustPrimitives, | |
| 436 trustTypeAnnotations: trustTypeAnnotations, | |
| 437 useContentSecurityPolicy: useContentSecurityPolicy, | |
| 438 useCpsIr: useCpsIr, | |
| 439 useFrequencyNamer: useFrequencyNamer, | |
| 440 useNewSourceInfo: useNewSourceInfo, | |
| 441 useStartupEmitter: useStartupEmitter, | |
| 442 verbose: verbose); | |
| 443 } | |
| 444 | |
| 445 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot, | |
| 446 this.packageConfig, this.packagesDiscoveryProvider, this.environment, | |
| 447 {this.allowMockCompilation: false, | |
| 448 this.allowNativeExtensions: false, | |
| 449 this.analyzeAll: false, | |
| 450 this.analyzeMain: false, | |
| 451 this.analyzeOnly: false, | |
| 452 this.analyzeSignaturesOnly: false, | |
| 453 this.buildId: _UNDETERMINED_BUILD_ID, | |
| 454 this.dart2dartMultiFile: false, | |
| 455 this.deferredMapUri: null, | |
| 456 this.fatalWarnings: false, | |
| 457 this.terseDiagnostics: false, | |
| 458 this.suppressWarnings: false, | |
| 459 this.suppressHints: false, | |
| 460 List<String> shownPackageWarnings: null, | |
| 461 this.disableInlining: false, | |
| 462 this.disableTypeInference: false, | |
| 463 this.dumpInfo: false, | |
| 464 this.emitJavaScript: true, | |
| 465 this.enableAssertMessage: false, | |
| 466 this.enableConditionalDirectives: false, | |
| 467 this.enableExperimentalMirrors: false, | |
| 468 this.enableMinification: false, | |
| 469 this.enableNativeLiveTypeAnalysis: false, | |
| 470 this.enableTypeAssertions: false, | |
| 471 this.enableUserAssertions: false, | |
| 472 this.generateCodeWithCompileTimeErrors: false, | |
| 473 this.generateSourceMap: true, | |
| 474 this.hasIncrementalSupport: false, | |
| 475 this.outputUri: null, | |
| 476 this.platformConfigUri: null, | |
| 477 this.preserveComments: false, | |
| 478 this.preserveUris: false, | |
| 479 this.sourceMapUri: null, | |
| 480 this.strips: const [], | |
| 481 this.testMode: false, | |
| 482 this.trustJSInteropTypeAnnotations: false, | |
| 483 this.trustPrimitives: false, | |
| 484 this.trustTypeAnnotations: false, | |
| 485 this.useContentSecurityPolicy: false, | |
| 486 this.useCpsIr: false, | |
| 487 this.useFrequencyNamer: false, | |
| 488 this.useNewSourceInfo: false, | |
| 489 this.useStartupEmitter: false, | |
| 490 this.verbose: false}) | |
| 491 : _shownPackageWarnings = shownPackageWarnings; | |
| 492 | |
| 493 /// Returns `true` if warnings and hints are shown for all packages. | |
| 494 bool get showAllPackageWarnings { | |
| 495 return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; | |
| 496 } | |
| 497 | |
| 498 /// Returns `true` if warnings and hints are hidden for all packages. | |
| 499 bool get hidePackageWarnings => _shownPackageWarnings == null; | |
| 500 | |
| 501 /// Returns `true` if warnings should be should for [uri]. | |
| 502 bool showPackageWarningsFor(Uri uri) { | |
| 503 if (showAllPackageWarnings) { | |
| 504 return true; | |
| 505 } | |
| 506 if (_shownPackageWarnings != null) { | |
| 507 return uri.scheme == 'package' && | |
| 508 _shownPackageWarnings.contains(uri.pathSegments.first); | |
| 509 } | |
| 510 return false; | |
| 511 } | |
| 512 } | |
| 513 | |
| 514 String _extractStringOption( | |
| 515 List<String> options, String prefix, String defaultValue) { | |
| 516 for (String option in options) { | |
| 517 if (option.startsWith(prefix)) { | |
| 518 return option.substring(prefix.length); | |
| 519 } | |
| 520 } | |
| 521 return defaultValue; | |
| 522 } | |
| 523 | |
| 524 Uri _extractUriOption(List<String> options, String prefix) { | |
| 525 var option = _extractStringOption(options, prefix, null); | |
| 526 return (option == null) ? null : Uri.parse(option); | |
| 527 } | |
| 528 | |
| 529 // CSV: Comma separated values. | |
| 530 List<String> _extractCsvOption(List<String> options, String prefix) { | |
| 531 for (String option in options) { | |
| 532 if (option.startsWith(prefix)) { | |
| 533 return option.substring(prefix.length).split(','); | |
| 534 } | |
| 535 } | |
| 536 return const <String>[]; | |
| 537 } | |
| 538 | |
| 539 bool _hasOption(List<String> options, String option) { | |
| 540 return options.indexOf(option) >= 0; | |
| 541 } | |
| 542 | |
| 543 /// Extract list of comma separated values provided for [flag]. Returns an | |
| 544 /// empty list if [option] contain [flag] without arguments. Returns `null` if | |
| 545 /// [option] doesn't contain [flag] with or without arguments. | |
| 546 List<String> _extractOptionalCsvOption(List<String> options, String flag) { | |
| 547 String prefix = '$flag='; | |
| 548 for (String option in options) { | |
| 549 if (option == flag) { | |
| 550 return const <String>[]; | |
| 551 } | |
| 552 if (option.startsWith(flag)) { | |
| 553 return option.substring(prefix.length).split(','); | |
| 554 } | |
| 555 } | |
| 556 return null; | |
| 557 } | |
| 558 | |
| 559 Uri _resolvePlatformConfig(Uri libraryRoot, String platformConfigPath, | |
| 560 bool isDart2Dart, Iterable<String> categories) { | |
| 561 if (platformConfigPath != null) { | |
| 562 return libraryRoot.resolve(platformConfigPath); | |
| 563 } else if (isDart2Dart) { | |
| 564 return libraryRoot.resolve(_dart2dartPlatform); | |
| 565 } else { | |
| 566 if (categories.length == 0) { | |
| 567 return libraryRoot.resolve(_clientPlatform); | |
| 568 } | |
| 569 assert(categories.length <= 2); | |
| 570 if (categories.contains("Client")) { | |
| 571 if (categories.contains("Server")) { | |
| 572 return libraryRoot.resolve(_sharedPlatform); | |
| 573 } | |
| 574 return libraryRoot.resolve(_clientPlatform); | |
| 575 } | |
| 576 assert(categories.contains("Server")); | |
| 577 return libraryRoot.resolve(_serverPlatform); | |
| 578 } | |
| 579 } | |
| 580 | |
| 581 Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) { | |
| 582 return _resolvePlatformConfig( | |
| 583 libraryRoot, | |
| 584 _extractStringOption(options, "--platform-config=", null), | |
| 585 _hasOption(options, '--output-type=dart'), | |
| 586 _extractCsvOption(options, '--categories=')); | |
| 587 } | |
| 588 | |
| 589 /// Locations of the platform descriptor files relative to the library root. | |
| 590 const String _clientPlatform = "lib/dart_client.platform"; | |
| 591 const String _serverPlatform = "lib/dart_server.platform"; | |
| 592 const String _sharedPlatform = "lib/dart_shared.platform"; | |
| 593 const String _dart2dartPlatform = "lib/dart2dart.platform"; | |
| 594 | |
| 595 const String _UNDETERMINED_BUILD_ID = "build number could not be determined"; | |
| 596 const bool _forceIncrementalSupport = | |
| 597 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); | |
| OLD | NEW |