OLD | NEW |
---|---|
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 /// Command line tool to merge the SDK libraries and our patch files. | 6 /// Command line tool to merge the SDK libraries and our patch files. |
7 /// This is currently designed as an offline tool, but we could automate it. | 7 /// This is currently designed as an offline tool, but we could automate it. |
8 | 8 |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate' show RawReceivePort; | 10 import 'dart:isolate' show RawReceivePort; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); | 74 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); |
75 final outExample = path.relative( | 75 final outExample = path.relative( |
76 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patched_sdk')); | 76 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patched_sdk')); |
77 final packagesExample = path.relative(path.join(repositoryDir, '.packages')); | 77 final packagesExample = path.relative(path.join(repositoryDir, '.packages')); |
78 print('For example:'); | 78 print('For example:'); |
79 print('\$ $self vm $sdkExample $patchExample $outExample $packagesExample'); | 79 print('\$ $self vm $sdkExample $patchExample $outExample $packagesExample'); |
80 | 80 |
81 exit(1); | 81 exit(1); |
82 } | 82 } |
83 | 83 |
84 const validModes = const ['vm', 'dart2js', 'flutter']; | 84 const validModes = const ['vm', 'dart2js', 'flutter', 'flutter_release']; |
85 String mode; | 85 String mode; |
86 bool get forVm => mode == 'vm'; | 86 bool get forVm => mode == 'vm'; |
87 bool get forFlutter => mode == 'flutter'; | 87 bool get forFlutter => mode == 'flutter' || mode == 'flutter_release'; |
88 bool get forFlutterRelease => mode == 'flutter_release'; | |
88 bool get forDart2js => mode == 'dart2js'; | 89 bool get forDart2js => mode == 'dart2js'; |
89 | 90 |
90 Future _main(List<String> argv) async { | 91 Future _main(List<String> argv) async { |
91 if (argv.isEmpty) usage('[${validModes.join('|')}]'); | 92 if (argv.isEmpty) usage('[${validModes.join('|')}]'); |
92 mode = argv.first; | 93 mode = argv.first; |
93 if (!validModes.contains(mode)) usage('[${validModes.join('|')}]'); | 94 if (!validModes.contains(mode)) usage('[${validModes.join('|')}]'); |
94 if (argv.length != 5) usage(mode); | 95 if (argv.length != 5) usage(mode); |
95 | 96 |
96 var input = argv[1]; | 97 var input = argv[1]; |
97 var sdkLibIn = path.join(input, 'lib'); | 98 var sdkLibIn = path.join(input, 'lib'); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 Future<List<Uri>> compilePlatform(Uri patchedSdk, Target target, Uri packages, | 205 Future<List<Uri>> compilePlatform(Uri patchedSdk, Target target, Uri packages, |
205 Uri fullOutput, Uri outlineOutput) async { | 206 Uri fullOutput, Uri outlineOutput) async { |
206 var options = new CompilerOptions() | 207 var options = new CompilerOptions() |
207 ..strongMode = false | 208 ..strongMode = false |
208 ..compileSdk = true | 209 ..compileSdk = true |
209 ..sdkRoot = patchedSdk | 210 ..sdkRoot = patchedSdk |
210 ..packagesFileUri = packages | 211 ..packagesFileUri = packages |
211 ..chaseDependencies = true | 212 ..chaseDependencies = true |
212 ..target = target; | 213 ..target = target; |
213 | 214 |
215 var inputs = [Uri.parse('dart:core')]; | |
216 if (forFlutter && !forFlutterRelease) { | |
217 inputs.add(Uri.parse('dart:vmservice_sky')); | |
218 } | |
214 var result = await generateKernel( | 219 var result = await generateKernel( |
215 new ProcessedOptions( | 220 new ProcessedOptions( |
216 options, | 221 options, |
217 // TODO(sigmund): pass all sdk libraries needed here, and make this | 222 // TODO(sigmund): pass all sdk libraries needed here, and make this |
218 // hermetic. | 223 // hermetic. |
219 false, | 224 false, |
220 [Uri.parse('dart:core')]), | 225 inputs), |
221 buildSummary: true, | 226 buildSummary: true, |
222 buildProgram: true); | 227 buildProgram: true); |
223 new File.fromUri(outlineOutput).writeAsBytesSync(result.summary); | 228 new File.fromUri(outlineOutput).writeAsBytesSync(result.summary); |
224 await writeProgramToFile(result.program, fullOutput); | 229 await writeProgramToFile(result.program, fullOutput); |
225 return result.deps; | 230 return result.deps; |
226 } | 231 } |
227 | 232 |
228 Future writeDepsFile( | 233 Future writeDepsFile( |
229 Uri output, Uri depsFile, Iterable<Uri> allDependencies) async { | 234 Uri output, Uri depsFile, Iterable<Uri> allDependencies) async { |
230 if (allDependencies.isEmpty) return; | 235 if (allDependencies.isEmpty) return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 | 290 |
286 if (forFlutter) { | 291 if (forFlutter) { |
287 extraLibraries.write(''' | 292 extraLibraries.write(''' |
288 "ui": const LibraryInfo( | 293 "ui": const LibraryInfo( |
289 "ui/ui.dart", | 294 "ui/ui.dart", |
290 categories: "Client,Server", | 295 categories: "Client,Server", |
291 implementation: true, | 296 implementation: true, |
292 documented: false, | 297 documented: false, |
293 platforms: VM_PLATFORM), | 298 platforms: VM_PLATFORM), |
294 '''); | 299 '''); |
300 | |
301 if (!forFlutterRelease) { | |
302 // vmservice should be present unless we build release flavor of Flutter. | |
303 extraLibraries.write(''' | |
304 "_vmservice": const LibraryInfo( | |
305 "vmservice/vmservice.dart", | |
306 categories: "Client,Server", | |
307 implementation: true, | |
308 documented: false, | |
309 platforms: VM_PLATFORM), | |
310 | |
311 "vmservice_sky": const LibraryInfo( | |
312 "vmservice_sky/vmservice_io.dart", | |
313 categories: "Client,Server", | |
314 implementation: true, | |
315 documented: false, | |
316 platforms: VM_PLATFORM), | |
317 | |
318 '''); | |
319 } | |
295 } | 320 } |
296 | 321 |
297 libContents = libContents.replaceAll( | 322 libContents = libContents.replaceAll( |
298 ' libraries = const {', ' libraries = const { $extraLibraries'); | 323 ' libraries = const {', ' libraries = const { $extraLibraries'); |
299 _writeSync( | 324 _writeSync( |
300 path.join( | 325 path.join( |
301 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), | 326 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), |
302 libContents); | 327 libContents); |
303 return libContents; | 328 return libContents; |
304 } | 329 } |
(...skipping 18 matching lines...) Expand all Loading... | |
323 // flutter/ | 348 // flutter/ |
324 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base)))); | 349 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base)))); |
325 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui'); | 350 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui'); |
326 for (var file in new Directory(uiLibraryInDir).listSync()) { | 351 for (var file in new Directory(uiLibraryInDir).listSync()) { |
327 if (!file.path.endsWith('.dart')) continue; | 352 if (!file.path.endsWith('.dart')) continue; |
328 var name = path.basename(file.path); | 353 var name = path.basename(file.path); |
329 var uiLibraryOut = path.join(sdkOut, 'ui', name); | 354 var uiLibraryOut = path.join(sdkOut, 'ui', name); |
330 _writeSync(uiLibraryOut, readInputFile(file.path)); | 355 _writeSync(uiLibraryOut, readInputFile(file.path)); |
331 } | 356 } |
332 locations['ui'] = 'ui/ui.dart'; | 357 locations['ui'] = 'ui/ui.dart'; |
358 | |
359 if (!forFlutterRelease) { | |
Siggi Cherem (dart-lang)
2017/07/12 18:06:18
is the intent to eventually get rid of this? I mea
aam
2017/07/13 16:30:56
If I understand correctly, we won't be able to loa
| |
360 // vmservice should be present unless we build release flavor of Flutter. | |
361 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) { | |
362 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file); | |
363 var libraryOut = path.join(sdkOut, 'vmservice_io', file); | |
364 _writeSync(libraryOut, readInputFile(libraryIn)); | |
365 } | |
366 locations['vmservice_sky'] = | |
367 path.join('vmservice_io', 'vmservice_io.dart'); | |
368 locations['_vmservice'] = path.join('vmservice', 'vmservice.dart'); | |
369 } | |
333 } | 370 } |
334 } | 371 } |
335 | 372 |
336 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut, | 373 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut, |
337 Map<String, String> locations) { | 374 Map<String, String> locations) { |
338 var libraryOut = path.join(sdkLibIn, library.path); | 375 var libraryOut = path.join(sdkLibIn, library.path); |
339 var libraryIn = libraryOut; | 376 var libraryIn = libraryOut; |
340 | 377 |
341 var libraryFile = getInputFile(libraryIn, canBeMissing: true); | 378 var libraryFile = getInputFile(libraryIn, canBeMissing: true); |
342 if (libraryFile != null) { | 379 if (libraryFile != null) { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 if (diff != 0) return diff; | 776 if (diff != 0) return diff; |
740 return end - other.end; | 777 return end - other.end; |
741 } | 778 } |
742 } | 779 } |
743 | 780 |
744 List<SdkLibrary> _getSdkLibraries(String contents) { | 781 List<SdkLibrary> _getSdkLibraries(String contents) { |
745 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js); | 782 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js); |
746 parseCompilationUnit(contents).accept(libraryBuilder); | 783 parseCompilationUnit(contents).accept(libraryBuilder); |
747 return libraryBuilder.librariesMap.sdkLibraries; | 784 return libraryBuilder.librariesMap.sdkLibraries; |
748 } | 785 } |
OLD | NEW |