Chromium Code Reviews| 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; | |
| 9 | 10 |
| 10 import 'compilation_error.dart'; | 11 import 'compilation_error.dart'; |
| 11 import 'file_system.dart'; | 12 import 'file_system.dart'; |
| 12 import 'physical_file_system.dart'; | 13 import 'physical_file_system.dart'; |
| 13 | 14 |
| 14 /// Default error handler used by [CompilerOptions.onError]. | 15 /// Default error handler used by [CompilerOptions.onError]. |
| 15 void defaultErrorHandler(CompilationError error) => throw error; | 16 void defaultErrorHandler(CompilationError error) => throw error; |
| 16 | 17 |
| 17 /// Callback used to report errors encountered during compilation. | 18 /// Callback used to report errors encountered during compilation. |
| 18 typedef void ErrorHandler(CompilationError error); | 19 typedef void ErrorHandler(CompilationError error); |
|
ahe
2017/06/29 11:09:14
Use new syntax?
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Is the syntax supported everywhere already? happy
| |
| 19 | 20 |
| 20 /// Front-end options relevant to compiler back ends. | 21 /// Front-end options relevant to compiler back ends. |
| 21 /// | 22 /// |
| 22 /// Not intended to be implemented or extended by clients. | 23 /// Not intended to be implemented or extended by clients. |
| 23 class CompilerOptions { | 24 class CompilerOptions { |
| 24 /// The URI of the root of the Dart SDK (typically a "file:" URI). | 25 /// The URI of the root of the Dart SDK (typically a "file:" URI). |
| 25 /// | 26 /// |
| 26 /// If `null`, the SDK will be searched for using | 27 /// If `null`, the SDK will be searched for using |
| 27 /// [Platform.resolvedExecutable] as a starting point. | 28 /// [Platform.resolvedExecutable] as a starting point. |
| 28 /// | |
| 29 /// This option is mutually exclusive with [sdkSummary]. | |
| 30 Uri sdkRoot; | 29 Uri sdkRoot; |
| 31 | 30 |
| 32 /// Map of `dart.xyz` libraries to URIs in the [fileSystem]. | 31 /// Map of `dart.xyz` libraries to URIs in the [fileSystem]. |
|
ahe
2017/06/29 11:09:15
dart:xyz.
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Done.
| |
| 33 /// E.g. {'core': 'file:///sdk/lib/core/core.dart'} (no `dart:` prefix). | 32 /// E.g. {'core': 'file:///sdk/lib/core/core.dart'} (no `dart:` prefix). |
| 34 Map<String, Uri> dartLibraries = {}; | 33 /// |
| 34 /// If `null`, the default set of libraries will be loaded from | |
| 35 /// `sdkRoot/lib/libraries.json`. | |
| 36 // TODO(sigmund): also provide an option to specify the .json file. | |
| 37 Map<String, Uri> dartLibraries; | |
|
ahe
2017/06/29 11:09:15
I think the only option should be a single URI tha
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Happy to look into this in a follow-up CL and disc
| |
| 35 | 38 |
| 36 /// Callback to which compilation errors should be delivered. | 39 /// Callback to which compilation errors should be delivered. |
| 37 /// | 40 /// |
| 38 /// By default, the first error will be reported by throwing an exception of | 41 /// By default, the first error will be reported by throwing an exception of |
| 39 /// type [CompilationError]. | 42 /// type [CompilationError]. |
| 40 ErrorHandler onError = defaultErrorHandler; | 43 ErrorHandler onError = defaultErrorHandler; |
|
ahe
2017/07/03 10:05:31
I think we should provide a stream of diagnostics
Siggi Cherem (dart-lang)
2017/07/05 03:39:30
Yeah, I like the idea of using a stream. I also wa
| |
| 41 | 44 |
| 42 /// URI of the ".packages" file (typically a "file:" URI). | 45 /// URI of the ".packages" file (typically a "file:" URI). |
| 43 /// | 46 /// |
| 44 /// If `null`, the ".packages" file will be found via the standard | 47 /// If `null`, the ".packages" file will be found via the standard |
| 45 /// package_config search algorithm. | 48 /// package_config search algorithm. |
|
ahe
2017/06/29 11:09:15
What is the "standard package_config search algori
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Basically the language team provided a default imp
| |
| 46 /// | 49 /// |
| 47 /// If the URI's path component is empty (e.g. `new Uri()`), no packages file | 50 /// If the URI's path component is empty (e.g. `new Uri()`), no packages file |
| 48 /// will be used. | 51 /// will be used. |
|
ahe
2017/06/29 11:09:15
This seems brittle. I think it would be better to
Paul Berry
2017/06/29 18:51:07
Personally I'm not a fan of custom URI schemes act
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Ha, I had not noticed the special behavior with th
Paul Berry
2017/07/04 15:12:14
IIRC, the "pretend it is empty" was added as an af
Siggi Cherem (dart-lang)
2017/07/05 18:42:07
Thanks - sounds good. I can remove it on a follow
| |
| 49 Uri packagesFileUri; | 52 Uri packagesFileUri; |
| 50 | 53 |
| 51 /// URIs of input summary files (excluding the SDK summary; typically these | 54 /// URIs of input summary files (excluding the SDK summary; typically these |
| 52 /// will be "file:" URIs). These files should all be linked summaries. They | 55 /// will be "file:" URIs). |
| 53 /// should also be closed, in the sense that any libraries they reference | 56 /// |
| 54 /// should also appear in [inputSummaries] or [sdkSummary]. | 57 /// These files should be summary files generated by this package (and not the |
| 58 /// similarly named summary files from `package:analyzer`.) | |
| 59 /// | |
| 60 /// Summaries may be provided in any order, but they should be acyclic and | |
| 61 /// closed: any libraries that they reference should be defined in either one | |
| 62 /// of [inputSummaries] or [sdkSummary]. | |
| 55 List<Uri> inputSummaries = []; | 63 List<Uri> inputSummaries = []; |
| 56 | 64 |
| 65 /// URIs of other kernel programs to link. | |
| 66 /// | |
| 67 /// Commonly used to link the code for the SDK libraries that was compiled | |
| 68 /// separately. Programs should be closed an acyclic: any libraries that they | |
|
ahe
2017/06/29 11:09:15
an -> and.
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Done.
| |
| 69 /// reference should be defined in a program in [linkedDependencies] or any of | |
| 70 /// the [inputSummaries] or [sdkSummary]. | |
| 71 /// CODE REVIEW COMMENT: this is used for the dart2js use case: they want to | |
|
ahe
2017/06/29 11:09:14
This comment could be rewritten to something like:
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
thanks for the suggestion. Updated the doc.
| |
| 72 /// link the SDK, not just use an outline to build the program. | |
| 73 List<Uri> linkedDependencies = []; | |
| 74 | |
| 57 /// URI of the SDK summary file (typically a "file:" URI). | 75 /// URI of the SDK summary file (typically a "file:" URI). |
| 58 /// | 76 /// |
| 59 /// This should be a linked summary. If `null`, the SDK summary will be | 77 /// This should should be a summary previosly generated by this package (and |
| 60 /// searched for at a default location within [sdkRoot]. | 78 /// not the similarly named summary files from `package:analyzer`.) |
| 61 /// | 79 /// |
| 62 /// This option is mutually exclusive with [sdkRoot]. TODO(paulberry): if the | 80 /// If `null` and [compileSdk] is false, the SDK summary will be searched for |
| 63 /// VM does not contain a pickled copy of the SDK, we might need to change | 81 /// at a default location within [sdkRoot]. |
| 64 /// this. | |
| 65 Uri sdkSummary; | 82 Uri sdkSummary; |
| 66 | 83 |
| 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 | |
| 83 /// Multi-roots. | 84 /// Multi-roots. |
| 84 /// | 85 /// |
| 85 /// Any Uri that resolves to "multi-root:///$rest" will be searched for | 86 /// Any Uri that resolves to "multi-root:///$rest" will be searched for |
|
ahe
2017/06/29 11:09:15
Is this scheme registered? If not, we should use "
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
No, it should be possible to change it, let's disc
| |
| 86 /// at "$root/$rest", where "$root" is drawn from this list. | 87 /// at "$root/$rest", where "$root" is drawn from this list. |
|
ahe
2017/06/29 11:09:14
We should use Uri.resolve, not string concatenatio
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
note that $rest was meant to be an absolute path.
| |
| 87 /// | 88 /// |
| 88 /// Intended use: if the user has a Bazel workspace located at path | 89 /// Intended use: if the user has a Bazel workspace located at path |
| 89 /// "$workspace", this could be set to the file URIs corresponding to the | 90 /// "$workspace", this could be set to the file URIs corresponding to the |
| 90 /// paths for "$workspace", "$workspace/bazel-bin", | 91 /// paths for "$workspace", "$workspace/bazel-bin", |
| 91 /// and "$workspace/bazel-genfiles", effectively overlaying source and | 92 /// and "$workspace/bazel-genfiles", effectively overlaying source and |
| 92 /// generated files. | 93 /// generated files. |
| 93 List<Uri> multiRoots = []; | 94 List<Uri> multiRoots = []; |
| 94 | 95 |
| 95 /// The declared variables for use by configurable imports and constant | 96 /// The declared variables for use by configurable imports and constant |
| 96 /// evaluation. | 97 /// evaluation. |
| 97 Map<String, String> declaredVariables; | 98 Map<String, String> declaredVariables; |
| 98 | 99 |
| 99 /// The [FileSystem] which should be used by the front end to access files. | 100 /// The [FileSystem] which should be used by the front end to access files. |
| 100 /// | 101 /// |
| 101 /// All file system access performed by the front end goes through this | 102 /// All file system access performed by the front end goes through this |
| 102 /// mechanism, with one exception: if no value is specified for | 103 /// mechanism, with one exception: if no value is specified for |
| 103 /// [packagesFileUri], the packages file is located using the actual physical | 104 /// [packagesFileUri], the packages file is located using the actual physical |
| 104 /// file system. TODO(paulberry): fix this. | 105 /// file system. TODO(paulberry): fix this. |
| 105 FileSystem fileSystem = PhysicalFileSystem.instance; | 106 FileSystem fileSystem = PhysicalFileSystem.instance; |
| 106 | 107 |
| 107 /// The byte storage to get and put serialized data. | 108 /// The byte storage to get and put serialized data. |
|
ahe
2017/06/29 11:09:15
"get and put" -> "access"
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Done.
| |
| 108 ByteStore byteStore = new NullByteStore(); | 109 ByteStore byteStore = new NullByteStore(); |
| 109 | 110 |
| 110 /// The logger to report compilation progress. | 111 /// The logger to report compilation progress. |
| 111 PerformanceLog logger = new PerformanceLog(new StringBuffer()); | 112 PerformanceLog logger = new PerformanceLog(new StringBuffer()); |
| 112 | 113 |
| 113 /// Whether to generate code for the SDK when compiling a whole-program. | 114 /// Whether to generate code for the SDK. |
| 115 /// | |
| 116 /// By default the front end resolves programs using a prebuilt SDK summary. | |
| 117 /// When this option is `true`, [sdkSummary] must be null. | |
| 114 bool compileSdk = false; | 118 bool compileSdk = false; |
| 115 | 119 |
| 116 /// Whether a modular build compiles only the files listed explicitly or if it | 120 /// Whether a modular build compiles only the files listed explicitly or if it |
| 117 /// compiles dependencies as well. | 121 /// compiles dependencies as well. |
| 118 /// | 122 /// |
| 119 /// This option is intended only for modular APIs like `kernelForBuildUnit`. | 123 /// This option is intended only for modular APIs like `kernelForBuildUnit`. |
| 120 /// These APIs by default ensure that builds are hermetic, where all files | 124 /// These APIs by default ensure that builds are hermetic, where all files |
| 121 /// that will be compiled are listed explicitly and all other dependencies | 125 /// that will be compiled are listed explicitly and all other dependencies |
| 122 /// are covered by summary files. | 126 /// are covered by summary files. |
| 123 /// | 127 /// |
| 124 /// When this option is true, these APIs will treat any dependency that is | 128 /// When this option is true, these APIs will treat any dependency that is |
| 125 /// not described in a summary as if it was explicitly listed as an input. | 129 /// not described in a summary as if it was explicitly listed as an input. |
|
ahe
2017/06/29 11:09:14
This reminds me of the completely broken default b
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Not sure I follow. We can discuss more on our next
| |
| 126 bool chaseDependencies = false; | 130 bool chaseDependencies = false; |
| 127 | 131 |
| 128 /// Whether to interpret Dart sources in strong-mode. | 132 /// Whether to interpret Dart sources in strong-mode. |
| 129 bool strongMode = true; | 133 bool strongMode = true; |
|
ahe
2017/06/29 11:09:15
This should be a per-package option, not a global
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Not sure either - this might be a question for the
| |
| 130 | 134 |
| 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 | |
| 137 /// Patch files to apply on the core libraries for a specific target platform. | 135 /// Patch files to apply on the core libraries for a specific target platform. |
| 138 /// | 136 /// |
| 139 /// Keys on this map are expected to be `dart:*` URIs. The values can be | 137 /// Keys on this map are expected to be `dart:*` URIs. The values can be |
|
ahe
2017/06/29 11:09:14
This is inconsistent with dartLibraries above, whi
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Good point. Done.
| |
| 140 /// either absolute or relative URIs. Absolute URIs are read directly, while | 138 /// either absolute or relative URIs. Absolute URIs are read directly, while |
| 141 /// relative URIs are resolved from the [sdkRoot]. | 139 /// relative URIs are resolved from the [sdkRoot]. |
| 142 Map<Uri, List<Uri>> targetPatches = {}; | 140 Map<Uri, List<Uri>> targetPatches = {}; |
|
ahe
2017/06/29 11:09:15
Think this should be single URI that points to a f
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
I plan to add the .json input like with libraries.
| |
| 143 | 141 |
| 144 /// Additional core libraries to be loaded when building a program. | 142 /// The target platform that will consume the compiled code. |
| 145 // TODO(sigmund): delete. Ideally building a program only needs what's | 143 /// |
| 146 // reachable and we can use kernelForBuildUnit when creating a snapshot of the | 144 /// Used to provide platform-specific details to the compiler like: |
| 147 // SDK itself. | 145 /// * the set of libraries are part of a platform's SDK (e.g. dart:html for |
| 148 List<Uri> additionalLibraries = []; | 146 /// dart2js, dart:ui for flutter). |
| 147 /// | |
| 148 /// * what kernel transformations should be applied to the program | |
| 149 /// (async/await, mixin inlining, etc). | |
| 150 /// | |
| 151 /// * how to deal with non-standard features like `native` extensions. | |
| 152 /// | |
| 153 /// If not specified, the default target is the VM. | |
| 154 Target target; | |
| 155 | |
| 156 /// Whether to show verbose messages (mainly for debugging and performance | |
| 157 /// tracking). | |
|
Paul Berry
2017/06/29 18:51:07
Clarify whether these are shown by print()ing them
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Done and filed a bug that we want to change this.
| |
| 158 bool verbose = false; | |
| 159 | |
| 160 /// Whether to run extra verification steps to validate that compiled programs | |
| 161 /// are well formed. | |
|
Paul Berry
2017/06/29 18:51:06
If verification fails, how is the error reported?
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Well.. both via onError and stdout (I even had a b
| |
| 162 bool verify = false; | |
| 163 | |
| 164 /// Whether to dump generated programs in a text format (also mainly for | |
| 165 /// debugging). | |
| 166 bool debugDump = false; | |
|
Paul Berry
2017/06/29 18:51:07
Clarify whether the dump is shown by print() or th
Siggi Cherem (dart-lang)
2017/06/30 04:12:01
Thanks. Done
| |
| 167 | |
| 168 CompilerOptions(); | |
| 169 | |
| 170 /// Creates a new intance with options copied from [other]. | |
| 171 CompilerOptions.from(CompilerOptions other) | |
| 172 : byteStore = other.byteStore, | |
| 173 chaseDependencies = other.chaseDependencies, | |
| 174 compileSdk = other.compileSdk, | |
| 175 dartLibraries = other.dartLibraries != null | |
| 176 ? new Map.from(other.dartLibraries) | |
| 177 : null, | |
| 178 debugDump = other.debugDump, | |
| 179 declaredVariables = other.declaredVariables != null | |
| 180 ? new Map.from(other.declaredVariables) | |
| 181 : null, | |
| 182 fileSystem = other.fileSystem, | |
| 183 inputSummaries = new List.from(other.inputSummaries), | |
| 184 linkedDependencies = new List.from(other.linkedDependencies), | |
| 185 logger = other.logger, | |
| 186 multiRoots = new List.from(other.multiRoots), | |
| 187 onError = other.onError, | |
| 188 packagesFileUri = other.packagesFileUri, | |
| 189 sdkRoot = other.sdkRoot, | |
| 190 sdkSummary = other.sdkSummary, | |
| 191 strongMode = other.strongMode, | |
| 192 target = other.target, | |
| 193 targetPatches = new Map.from(other.targetPatches), | |
| 194 verbose = other.verbose, | |
| 195 verify = other.verify; | |
| 149 } | 196 } |
| OLD | NEW |