| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 front_end.compiler_options; | 5 library front_end.compiler_options; |
| 6 | 6 |
| 7 import 'package:front_end/src/base/performace_logger.dart'; | 7 import 'package:front_end/src/base/performace_logger.dart'; |
| 8 import 'package:front_end/src/incremental/byte_store.dart'; | 8 import 'package:front_end/src/incremental/byte_store.dart'; |
| 9 import 'package:kernel/target/targets.dart' show Target; | |
| 10 | 9 |
| 11 import 'compilation_error.dart'; | 10 import 'compilation_error.dart'; |
| 12 import 'file_system.dart'; | 11 import 'file_system.dart'; |
| 13 import 'physical_file_system.dart'; | 12 import 'physical_file_system.dart'; |
| 14 | 13 |
| 15 /// Default error handler used by [CompilerOptions.onError]. | 14 /// Default error handler used by [CompilerOptions.onError]. |
| 16 void defaultErrorHandler(CompilationError error) => throw error; | 15 void defaultErrorHandler(CompilationError error) => throw error; |
| 17 | 16 |
| 18 /// Callback used to report errors encountered during compilation. | 17 /// Callback used to report errors encountered during compilation. |
| 19 typedef void ErrorHandler(CompilationError error); | 18 typedef void ErrorHandler(CompilationError error); |
| 20 | 19 |
| 21 /// Front-end options relevant to compiler back ends. | 20 /// Front-end options relevant to compiler back ends. |
| 22 /// | 21 /// |
| 23 /// Not intended to be implemented or extended by clients. | 22 /// Not intended to be implemented or extended by clients. |
| 24 class CompilerOptions { | 23 class CompilerOptions { |
| 25 /// The URI of the root of the Dart SDK (typically a "file:" URI). | 24 /// The URI of the root of the Dart SDK (typically a "file:" URI). |
| 26 /// | 25 /// |
| 27 /// If `null`, the SDK will be searched for using | 26 /// If `null`, the SDK will be searched for using |
| 28 /// [Platform.resolvedExecutable] as a starting point. | 27 /// [Platform.resolvedExecutable] as a starting point. |
| 28 /// |
| 29 /// This option is mutually exclusive with [sdkSummary]. |
| 29 Uri sdkRoot; | 30 Uri sdkRoot; |
| 30 | 31 |
| 31 /// Map of `dart:*` libraries to URIs in the [fileSystem]. | 32 /// Map of `dart.xyz` libraries to URIs in the [fileSystem]. |
| 32 /// | 33 /// E.g. {'core': 'file:///sdk/lib/core/core.dart'} (no `dart:` prefix). |
| 33 /// Keys in the map are the name of the library with no `dart:` prefix, for | 34 Map<String, Uri> dartLibraries = {}; |
| 34 /// example: | |
| 35 /// | |
| 36 /// {'core': 'file:///sdk/lib/core/core.dart'} | |
| 37 /// | |
| 38 /// If `null`, the default set of libraries will be loaded from | |
| 39 /// `sdkRoot/lib/libraries.json`. | |
| 40 // TODO(sigmund): also provide an option to specify the .json file, then | |
| 41 // consider dropping this option. | |
| 42 Map<String, Uri> dartLibraries; | |
| 43 | 35 |
| 44 /// Callback to which compilation errors should be delivered. | 36 /// Callback to which compilation errors should be delivered. |
| 45 /// | 37 /// |
| 46 /// By default, the first error will be reported by throwing an exception of | 38 /// By default, the first error will be reported by throwing an exception of |
| 47 /// type [CompilationError]. | 39 /// type [CompilationError]. |
| 48 ErrorHandler onError = defaultErrorHandler; | 40 ErrorHandler onError = defaultErrorHandler; |
| 49 | 41 |
| 50 /// URI of the ".packages" file (typically a "file:" URI). | 42 /// URI of the ".packages" file (typically a "file:" URI). |
| 51 /// | 43 /// |
| 52 /// If `null`, the ".packages" file will be found via the standard | 44 /// If `null`, the ".packages" file will be found via the standard |
| 53 /// package_config search algorithm. | 45 /// package_config search algorithm. |
| 54 /// | 46 /// |
| 55 /// If the URI's path component is empty (e.g. `new Uri()`), no packages file | 47 /// If the URI's path component is empty (e.g. `new Uri()`), no packages file |
| 56 /// will be used. | 48 /// will be used. |
| 57 Uri packagesFileUri; | 49 Uri packagesFileUri; |
| 58 | 50 |
| 59 /// URIs of input summary files (excluding the SDK summary; typically these | 51 /// URIs of input summary files (excluding the SDK summary; typically these |
| 60 /// will be "file:" URIs). | 52 /// will be "file:" URIs). These files should all be linked summaries. They |
| 61 /// | 53 /// should also be closed, in the sense that any libraries they reference |
| 62 /// These files should be summary files generated by this package (and not the | 54 /// should also appear in [inputSummaries] or [sdkSummary]. |
| 63 /// similarly named summary files from `package:analyzer`.) | |
| 64 /// | |
| 65 /// Summaries may be provided in any order, but they should be acyclic and | |
| 66 /// closed: any libraries that they reference should be defined in either one | |
| 67 /// of [inputSummaries] or [sdkSummary]. | |
| 68 List<Uri> inputSummaries = []; | 55 List<Uri> inputSummaries = []; |
| 69 | 56 |
| 70 /// URIs of other kernel programs to link. | |
| 71 /// | |
| 72 /// Commonly used to link the code for the SDK libraries that was compiled | |
| 73 /// separately. For example, dart2js needs to link the SDK so it can | |
| 74 /// optimize and tree-shake the code for the application, whereas the VM | |
| 75 /// always embeds the SDK internally and doesn't need it as part of the | |
| 76 /// program. | |
| 77 /// | |
| 78 /// The programs provided here should be closed and acyclic: any libraries | |
| 79 /// that they reference should be defined in a program in [linkedDependencies] | |
| 80 /// or any of the [inputSummaries] or [sdkSummary]. | |
| 81 List<Uri> linkedDependencies = []; | |
| 82 | |
| 83 /// URI of the SDK summary file (typically a "file:" URI). | 57 /// URI of the SDK summary file (typically a "file:" URI). |
| 84 /// | 58 /// |
| 85 /// This should should be a summary previosly generated by this package (and | 59 /// This should be a linked summary. If `null`, the SDK summary will be |
| 86 /// not the similarly named summary files from `package:analyzer`.) | 60 /// searched for at a default location within [sdkRoot]. |
| 87 /// | 61 /// |
| 88 /// If `null` and [compileSdk] is false, the SDK summary will be searched for | 62 /// This option is mutually exclusive with [sdkRoot]. TODO(paulberry): if the |
| 89 /// at a default location within [sdkRoot]. | 63 /// VM does not contain a pickled copy of the SDK, we might need to change |
| 64 /// this. |
| 90 Uri sdkSummary; | 65 Uri sdkSummary; |
| 91 | 66 |
| 67 /// URI override map. |
| 68 /// |
| 69 /// This is a map from URIs that might appear in import/export/part statements |
| 70 /// to URIs that should be used to locate the corresponding files in the |
| 71 /// [fileSystem]. Any URI override listed in this map takes precedence over |
| 72 /// the URI resolution that would be implied by the packages file (see |
| 73 /// [packagesFileUri]) and/or [multiRoots]. |
| 74 /// |
| 75 /// If a URI is not listed in this map, then the normal URI resolution |
| 76 /// algorithm will be used. |
| 77 /// |
| 78 /// TODO(paulberry): transition analyzer and dev_compiler to use the |
| 79 /// "multi-root:" mechanism, and then remove this. |
| 80 @deprecated |
| 81 Map<Uri, Uri> uriOverride = {}; |
| 82 |
| 92 /// Multi-roots. | 83 /// Multi-roots. |
| 93 /// | 84 /// |
| 94 /// Any Uri that resolves to "multi-root:///$absolute_path" will be searched | 85 /// Any Uri that resolves to "multi-root:///$rest" will be searched for |
| 95 /// for at "$root/$absolute_path", where "$root" is drawn from this list. | 86 /// at "$root/$rest", where "$root" is drawn from this list. |
| 96 /// | 87 /// |
| 97 /// Intended use: if the user has a Bazel workspace located at path | 88 /// Intended use: if the user has a Bazel workspace located at path |
| 98 /// "$workspace", this could be set to the file URIs corresponding to the | 89 /// "$workspace", this could be set to the file URIs corresponding to the |
| 99 /// paths for "$workspace", "$workspace/bazel-bin", | 90 /// paths for "$workspace", "$workspace/bazel-bin", |
| 100 /// and "$workspace/bazel-genfiles", effectively overlaying source and | 91 /// and "$workspace/bazel-genfiles", effectively overlaying source and |
| 101 /// generated files. | 92 /// generated files. |
| 102 List<Uri> multiRoots = []; | 93 List<Uri> multiRoots = []; |
| 103 | 94 |
| 104 /// The declared variables for use by configurable imports and constant | 95 /// The declared variables for use by configurable imports and constant |
| 105 /// evaluation. | 96 /// evaluation. |
| 106 Map<String, String> declaredVariables; | 97 Map<String, String> declaredVariables; |
| 107 | 98 |
| 108 /// The [FileSystem] which should be used by the front end to access files. | 99 /// The [FileSystem] which should be used by the front end to access files. |
| 109 /// | 100 /// |
| 110 /// All file system access performed by the front end goes through this | 101 /// All file system access performed by the front end goes through this |
| 111 /// mechanism, with one exception: if no value is specified for | 102 /// mechanism, with one exception: if no value is specified for |
| 112 /// [packagesFileUri], the packages file is located using the actual physical | 103 /// [packagesFileUri], the packages file is located using the actual physical |
| 113 /// file system. TODO(paulberry): fix this. | 104 /// file system. TODO(paulberry): fix this. |
| 114 FileSystem fileSystem = PhysicalFileSystem.instance; | 105 FileSystem fileSystem = PhysicalFileSystem.instance; |
| 115 | 106 |
| 116 /// The byte storage to access serialized data. | 107 /// The byte storage to get and put serialized data. |
| 117 ByteStore byteStore = new NullByteStore(); | 108 ByteStore byteStore = new NullByteStore(); |
| 118 | 109 |
| 119 /// The logger to report compilation progress. | 110 /// The logger to report compilation progress. |
| 120 PerformanceLog logger = new PerformanceLog(new StringBuffer()); | 111 PerformanceLog logger = new PerformanceLog(new StringBuffer()); |
| 121 | 112 |
| 122 /// Whether to generate code for the SDK. | 113 /// Whether to generate code for the SDK when compiling a whole-program. |
| 123 /// | |
| 124 /// By default the front end resolves programs using a prebuilt SDK summary. | |
| 125 /// When this option is `true`, [sdkSummary] must be null. | |
| 126 bool compileSdk = false; | 114 bool compileSdk = false; |
| 127 | 115 |
| 128 /// Whether the compiler should read files that are discovered as | 116 /// Whether a modular build compiles only the files listed explicitly or if it |
| 129 /// dependencies, or only access the files listed explicitly. | 117 /// compiles dependencies as well. |
| 130 /// | 118 /// |
| 131 /// This option has different defaults depending on the API. | 119 /// This option is intended only for modular APIs like `kernelForBuildUnit`. |
| 120 /// These APIs by default ensure that builds are hermetic, where all files |
| 121 /// that will be compiled are listed explicitly and all other dependencies |
| 122 /// are covered by summary files. |
| 132 /// | 123 /// |
| 133 /// For modular APIs like `kernelForBuildUnit` and `summaryFor` the default | 124 /// When this option is true, these APIs will treat any dependency that is |
| 134 /// behavior is `false`. These APIs want to ensure that builds are hermetic, | 125 /// not described in a summary as if it was explicitly listed as an input. |
| 135 /// where all files that will be compiled are listed explicitly and all other | 126 bool chaseDependencies = false; |
| 136 /// dependencies are covered by summary files. | |
| 137 /// | |
| 138 /// For whole-program APIs like `kernelForProgram`, this option is true by | |
| 139 /// default, so they can treat any dependency that is not described in a | |
| 140 /// summary as if it was explicitly listed as an input. | |
| 141 bool chaseDependencies; | |
| 142 | 127 |
| 143 /// Whether to interpret Dart sources in strong-mode. | 128 /// Whether to interpret Dart sources in strong-mode. |
| 144 bool strongMode = true; | 129 bool strongMode = true; |
| 145 | 130 |
| 131 // All options below are target-specific options. |
| 132 // |
| 133 // TODO(sigmund): revisit the right layout for these options. We might want to |
| 134 // split them out into a separate bag of options or provide factories for |
| 135 // common combinations of these options. |
| 136 |
| 146 /// Patch files to apply on the core libraries for a specific target platform. | 137 /// Patch files to apply on the core libraries for a specific target platform. |
| 147 /// | 138 /// |
| 148 /// Keys in the map are the name of the library with no `dart:` prefix, for | 139 /// Keys on this map are expected to be `dart:*` URIs. The values can be |
| 149 /// example: | 140 /// either absolute or relative URIs. Absolute URIs are read directly, while |
| 150 /// | 141 /// relative URIs are resolved from the [sdkRoot]. |
| 151 /// {'core': [ | 142 Map<Uri, List<Uri>> targetPatches = {}; |
| 152 /// 'file:///location/of/core/patch_file1.dart', | |
| 153 /// 'file:///location/of/core/patch_file2.dart', | |
| 154 /// ]} | |
| 155 /// | |
| 156 /// The values can be either absolute or relative URIs. Absolute URIs are read | |
| 157 /// directly, while relative URIs are resolved from the [sdkRoot]. | |
| 158 // TODO(sigmund): provide also a flag to load this data from a file (like | |
| 159 // libraries.json) | |
| 160 Map<String, List<Uri>> targetPatches = {}; | |
| 161 | 143 |
| 162 /// The target platform that will consume the compiled code. | 144 /// Additional core libraries to be loaded when building a program. |
| 163 /// | 145 // TODO(sigmund): delete. Ideally building a program only needs what's |
| 164 /// Used to provide platform-specific details to the compiler like: | 146 // reachable and we can use kernelForBuildUnit when creating a snapshot of the |
| 165 /// * the set of libraries are part of a platform's SDK (e.g. dart:html for | 147 // SDK itself. |
| 166 /// dart2js, dart:ui for flutter). | 148 List<Uri> additionalLibraries = []; |
| 167 /// | |
| 168 /// * what kernel transformations should be applied to the program | |
| 169 /// (async/await, mixin inlining, etc). | |
| 170 /// | |
| 171 /// * how to deal with non-standard features like `native` extensions. | |
| 172 /// | |
| 173 /// If not specified, the default target is the VM. | |
| 174 Target target; | |
| 175 | |
| 176 /// Whether to show verbose messages (mainly for debugging and performance | |
| 177 /// tracking). | |
| 178 /// | |
| 179 /// Messages are printed on stdout. | |
| 180 // TODO(sigmund): improve the diagnotics API to provide mechanism to intercept | |
| 181 // verbose data (Issue #30056) | |
| 182 bool verbose = false; | |
| 183 | |
| 184 /// Whether to run extra verification steps to validate that compiled programs | |
| 185 /// are well formed. | |
| 186 /// | |
| 187 /// Errors are reported via the [onError] callback. | |
| 188 // TODO(sigmund): ensure we don't print errors to stdout (Issue #30056) | |
| 189 bool verify = false; | |
| 190 | |
| 191 /// Whether to dump generated programs in a text format (also mainly for | |
| 192 /// debugging). | |
| 193 /// | |
| 194 /// Dumped data is printed in stdout. | |
| 195 bool debugDump = false; | |
| 196 } | 149 } |
| OLD | NEW |