@@ -140,6 +140,27 @@ Future<CompilerResult> _compile(List<String> args,
140
140
141
141
var options = SharedCompilerOptions .fromArguments (argResults);
142
142
143
+ Uri toCustomUri (Uri uri) {
144
+ if (! uri.hasScheme) {
145
+ return Uri (scheme: options.multiRootScheme, path: '/${uri .path }' );
146
+ }
147
+ return uri;
148
+ }
149
+
150
+ // TODO(jmesserly): this is a workaround for the CFE, which does not
151
+ // understand relative URIs, and we'd like to avoid absolute file URIs
152
+ // being placed in the summary if possible.
153
+ // TODO(jmesserly): investigate if Analyzer has a similar issue.
154
+ Uri sourcePathToCustomUri (String source) {
155
+ return toCustomUri (sourcePathToRelativeUri (source));
156
+ }
157
+
158
+ // Compile SDK module directly from a provided .dill file.
159
+ var inputs = [for (var arg in argResults.rest) sourcePathToCustomUri (arg)];
160
+ if (inputs.length == 1 && inputs.single.path.endsWith ('.dill' )) {
161
+ return compileSdkFromDill (args);
162
+ }
163
+
143
164
// To make the output .dill agnostic of the current working directory,
144
165
// we use a custom-uri scheme for all app URIs (these are files outside the
145
166
// lib folder). The following [FileSystem] will resolve those references to
@@ -162,44 +183,36 @@ Future<CompilerResult> _compile(List<String> args,
162
183
163
184
var fileSystem = MultiRootFileSystem (
164
185
options.multiRootScheme, multiRootPaths, fe.StandardFileSystem .instance);
165
-
166
- Uri toCustomUri (Uri uri) {
167
- if (! uri.hasScheme) {
168
- return Uri (scheme: options.multiRootScheme, path: '/${uri .path }' );
169
- }
170
- return uri;
171
- }
172
-
173
- // TODO(jmesserly): this is a workaround for the CFE, which does not
174
- // understand relative URIs, and we'd like to avoid absolute file URIs
175
- // being placed in the summary if possible.
176
- // TODO(jmesserly): investigate if Analyzer has a similar issue.
177
- Uri sourcePathToCustomUri (String source) {
178
- return toCustomUri (sourcePathToRelativeUri (source));
179
- }
180
-
181
186
var summaryPaths = options.summaryModules.keys.toList ();
182
187
var summaryModules = Map .fromIterables (
183
188
summaryPaths.map (sourcePathToUri).cast <Uri >(),
184
189
options.summaryModules.values);
185
190
var sdkSummaryPath = argResults['dart-sdk-summary' ] as String ? ;
186
191
var librarySpecPath = argResults['libraries-file' ] as String ? ;
192
+ var compileSdk = argResults['compile-sdk' ] == true ;
187
193
if (sdkSummaryPath == null ) {
188
- sdkSummaryPath =
189
- defaultSdkSummaryPath (soundNullSafety: options.soundNullSafety);
190
- librarySpecPath ?? = defaultLibrarySpecPath;
194
+ if (! compileSdk) {
195
+ if (! options.soundNullSafety) {
196
+ // Technically if you can produce an SDK outline .dill and pass it
197
+ // this error can be avoided and the compile will still work for now.
198
+ // If you are reading this comment be warned, this loophole will be
199
+ // removed without warning in the future.
200
+ print ('Dart 3 only supports sound null safety, '
201
+ 'see https://dart.dev/null-safety.\n ' );
202
+ return CompilerResult (64 );
203
+ }
204
+ sdkSummaryPath = defaultSdkSummaryPath;
205
+ librarySpecPath ?? = defaultLibrarySpecPath;
206
+ }
207
+ // Compiling without manually passing or getting a default SDK summary is
208
+ // only allowed when `compileSdk` is true.
191
209
}
192
210
var invalidSummary = summaryPaths.any ((s) => ! s.endsWith ('.dill' )) ||
193
- ! sdkSummaryPath.endsWith ('.dill' );
211
+ (sdkSummaryPath != null && ! sdkSummaryPath.endsWith ('.dill' ) );
194
212
if (invalidSummary) {
195
213
throw StateError ('Non-dill file detected in input: $summaryPaths ' );
196
214
}
197
215
198
- var inputs = [for (var arg in argResults.rest) sourcePathToCustomUri (arg)];
199
- if (inputs.length == 1 && inputs.single.path.endsWith ('.dill' )) {
200
- return compileSdkFromDill (args);
201
- }
202
-
203
216
if (librarySpecPath == null ) {
204
217
// TODO(jmesserly): the `isSupported` bit should be included in the SDK
205
218
// summary, but front_end requires a separate file, so we have to work
@@ -210,10 +223,12 @@ Future<CompilerResult> _compile(List<String> args,
210
223
// (if the user is doing something custom).
211
224
//
212
225
// Another option: we could make an in-memory file with the relevant info.
213
- librarySpecPath =
214
- p.join (p.dirname (p.dirname (sdkSummaryPath)), 'libraries.json' );
226
+ librarySpecPath = p.join (
227
+ p.dirname (p.dirname (sdkSummaryPath ?? defaultSdkSummaryPath)),
228
+ 'libraries.json' );
215
229
if (! File (librarySpecPath).existsSync ()) {
216
- librarySpecPath = p.join (p.dirname (sdkSummaryPath), 'libraries.json' );
230
+ librarySpecPath = p.join (
231
+ p.dirname (sdkSummaryPath ?? defaultSdkSummaryPath), 'libraries.json' );
217
232
}
218
233
}
219
234
@@ -245,8 +260,6 @@ Future<CompilerResult> _compile(List<String> args,
245
260
onError: stderr.writeln, onWarning: print);
246
261
247
262
var trackWidgetCreation = argResults['track-widget-creation' ] as bool ;
248
-
249
- var compileSdk = argResults['compile-sdk' ] == true ;
250
263
var oldCompilerState = compilerState;
251
264
var recordUsedInputs = argResults['used-inputs-file' ] != null ;
252
265
var additionalDills = summaryModules.keys.toList ();
@@ -262,7 +275,7 @@ Future<CompilerResult> _compile(List<String> args,
262
275
oldCompilerState,
263
276
compileSdk,
264
277
sourcePathToUri (getSdkPath ()),
265
- compileSdk ? null : sourcePathToUri (sdkSummaryPath),
278
+ compileSdk ? null : sourcePathToUri (sdkSummaryPath! ),
266
279
packageFile != null ? sourcePathToUri (packageFile) : null ,
267
280
sourcePathToUri (librarySpecPath),
268
281
additionalDills,
@@ -284,7 +297,7 @@ Future<CompilerResult> _compile(List<String> args,
284
297
oldCompilerState = null ;
285
298
286
299
if (! compileSdk) {
287
- inputDigests[sourcePathToUri (sdkSummaryPath)] = const [0 ];
300
+ inputDigests[sourcePathToUri (sdkSummaryPath! )] = const [0 ];
288
301
}
289
302
for (var uri in summaryModules.keys) {
290
303
inputDigests[uri] = const [0 ];
@@ -302,7 +315,7 @@ Future<CompilerResult> _compile(List<String> args,
302
315
doneAdditionalDills,
303
316
compileSdk,
304
317
sourcePathToUri (getSdkPath ()),
305
- compileSdk ? null : sourcePathToUri (sdkSummaryPath),
318
+ compileSdk ? null : sourcePathToUri (sdkSummaryPath! ),
306
319
packageFile != null ? sourcePathToUri (packageFile) : null ,
307
320
sourcePathToUri (librarySpecPath),
308
321
additionalDills,
@@ -317,8 +330,9 @@ Future<CompilerResult> _compile(List<String> args,
317
330
nnbdMode:
318
331
options.soundNullSafety ? fe.NnbdMode .Strong : fe.NnbdMode .Weak );
319
332
var incrementalCompiler = compilerState.incrementalCompiler! ;
320
- var cachedSdkInput =
321
- compilerState.workerInputCache! [sourcePathToUri (sdkSummaryPath)];
333
+ var cachedSdkInput = compileSdk
334
+ ? null
335
+ : compilerState.workerInputCache! [sourcePathToUri (sdkSummaryPath! )];
322
336
compilerState.options.onDiagnostic = diagnosticMessageHandler;
323
337
var incrementalCompilerResult = await incrementalCompiler.computeDelta (
324
338
entryPoints: inputs,
@@ -819,13 +833,9 @@ Map<String, String> parseAndRemoveDeclaredVariables(List<String> args) {
819
833
return declaredVariables;
820
834
}
821
835
822
- /// The default path of the kernel summary for the Dart SDK given the
823
- /// [soundNullSafety] mode.
824
- String defaultSdkSummaryPath ({required bool soundNullSafety}) {
825
- var outlineDill =
826
- soundNullSafety ? 'ddc_outline.dill' : 'ddc_outline_unsound.dill' ;
827
- return p.join (getSdkPath (), 'lib' , '_internal' , outlineDill);
828
- }
836
+ /// The default path of the kernel summary for the Dart SDK.
837
+ final defaultSdkSummaryPath =
838
+ p.join (getSdkPath (), 'lib' , '_internal' , 'ddc_outline.dill' );
829
839
830
840
final defaultLibrarySpecPath = p.join (getSdkPath (), 'lib' , 'libraries.json' );
831
841
0 commit comments