| 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:async'; | 10 import 'dart:async'; |
| 11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
| 12 | 12 |
| 13 import 'package:analyzer/analyzer.dart'; | 13 import 'package:analyzer/analyzer.dart'; |
| 14 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 15 import 'package:path/path.dart' as path; | 15 import 'package:path/path.dart' as path; |
| 16 import 'package:front_end/src/fasta/bin/compile_platform.dart' as | 16 import 'package:front_end/src/fasta/compile_platform.dart' as |
| 17 compile_platform; | 17 compile_platform; |
| 18 | 18 |
| 19 Future main(List<String> argv) async { | 19 Future main(List<String> argv) async { |
| 20 var base = path.fromUri(Platform.script); | 20 var base = path.fromUri(Platform.script); |
| 21 var dartDir = path.dirname(path.dirname(path.absolute(base))); | 21 var dartDir = path.dirname(path.dirname(path.absolute(base))); |
| 22 | 22 |
| 23 if (argv.length != 5 || argv.first != 'vm') { | 23 if (argv.length != 5 || argv.first != 'vm') { |
| 24 final self = path.relative(base); | 24 final self = path.relative(base); |
| 25 print('Usage: $self vm SDK_DIR PATCH_DIR OUTPUT_DIR PACKAGES'); | 25 print('Usage: $self vm SDK_DIR PATCH_DIR OUTPUT_DIR PACKAGES'); |
| 26 | 26 |
| 27 final repositoryDir = path.relative(path.dirname(path.dirname(base))); | 27 final repositoryDir = path.relative(path.dirname(path.dirname(base))); |
| 28 final sdkExample = path.relative(path.join(repositoryDir, 'sdk')); | 28 final sdkExample = path.relative(path.join(repositoryDir, 'sdk')); |
| 29 final packagesExample = path.relative( | |
| 30 path.join(repositoryDir, '.packages')); | |
| 31 final patchExample = path.relative( | 29 final patchExample = path.relative( |
| 32 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); | 30 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); |
| 33 final outExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64', | 31 final outExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64', |
| 34 'obj', 'gen', 'patched_sdk')); | 32 'obj', 'gen', 'patched_sdk')); |
| 35 print('For example:'); | 33 print('For example:'); |
| 36 print('\$ $self vm $sdkExample $patchExample $outExample'); | 34 print('\$ $self vm $sdkExample $patchExample $outExample'); |
| 37 | 35 |
| 38 exit(1); | 36 exit(1); |
| 39 } | 37 } |
| 40 | 38 |
| 41 var mode = argv[0]; | 39 var mode = argv[0]; |
| 42 var input = argv[1]; | 40 var input = argv[1]; |
| 43 var sdkLibIn = path.join(input, 'lib'); | 41 var sdkLibIn = path.join(input, 'lib'); |
| 44 var patchIn = argv[2]; | 42 var patchIn = argv[2]; |
| 45 var outDir = argv[3]; | 43 var outDir = argv[3]; |
| 46 var sdkOut = path.join(outDir, 'lib'); | 44 var sdkOut = path.join(outDir, 'lib'); |
| 47 var packagesFile = argv[4]; | 45 var packagesFile = argv[4]; |
| 48 | 46 |
| 49 var privateIn = path.join(input, 'private'); | 47 var privateIn = path.join(input, 'private'); |
| 50 var INTERNAL_PATH = '_internal/compiler/js_lib/'; | 48 var INTERNAL_PATH = '_internal/compiler/js_lib/'; |
| 51 | 49 |
| 52 // Copy and patch libraries.dart and version | 50 // Copy and patch libraries.dart and version |
| 53 var libContents = new File(path.join(sdkLibIn, '_internal', | 51 var libContents = new File(path.join(sdkLibIn, '_internal', |
| 54 'sdk_library_metadata', 'lib', 'libraries.dart')).readAsStringSync(); | 52 'sdk_library_metadata', 'lib', 'libraries.dart')).readAsStringSync(); |
| 55 var patchedLibContents = libContents; | |
| 56 if (mode == 'vm') { | 53 if (mode == 'vm') { |
| 57 libContents = libContents.replaceAll( | 54 libContents = libContents.replaceAll( |
| 58 ' libraries = const {', | 55 ' libraries = const {', |
| 59 ''' libraries = const { | 56 ''' libraries = const { |
| 60 | 57 |
| 61 "_builtin": const LibraryInfo( | 58 "_builtin": const LibraryInfo( |
| 62 "_builtin/_builtin.dart", | 59 "_builtin/_builtin.dart", |
| 63 categories: "Client,Server", | 60 categories: "Client,Server", |
| 64 implementation: true, | 61 implementation: true, |
| 65 documented: false, | 62 documented: false, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 } | 91 } |
| 95 | 92 |
| 96 // Parse libraries.dart | 93 // Parse libraries.dart |
| 97 var sdkLibraries = _getSdkLibraries(libContents); | 94 var sdkLibraries = _getSdkLibraries(libContents); |
| 98 | 95 |
| 99 // Enumerate core libraries and apply patches | 96 // Enumerate core libraries and apply patches |
| 100 for (SdkLibrary library in sdkLibraries) { | 97 for (SdkLibrary library in sdkLibraries) { |
| 101 // TODO(jmesserly): analyzer does not handle the default case of | 98 // TODO(jmesserly): analyzer does not handle the default case of |
| 102 // "both platforms" correctly, and treats it as being supported on neither. | 99 // "both platforms" correctly, and treats it as being supported on neither. |
| 103 // So instead we skip explicitly marked as either VM or dart2js libs. | 100 // So instead we skip explicitly marked as either VM or dart2js libs. |
| 104 if (mode == 'ddc' ? libary.isVmLibrary : library.isDart2JsLibrary) { | 101 if (mode == 'ddc' ? library.isVmLibrary : library.isDart2JsLibrary) { |
| 105 continue; | 102 continue; |
| 106 } | 103 } |
| 107 | 104 |
| 108 var libraryOut = path.join(sdkLibIn, library.path); | 105 var libraryOut = path.join(sdkLibIn, library.path); |
| 109 var libraryIn; | 106 var libraryIn; |
| 110 if (mode == 'ddc' && library.path.contains(INTERNAL_PATH)) { | 107 if (mode == 'ddc' && library.path.contains(INTERNAL_PATH)) { |
| 111 libraryIn = | 108 libraryIn = |
| 112 path.join(privateIn, library.path.replaceAll(INTERNAL_PATH, '')); | 109 path.join(privateIn, library.path.replaceAll(INTERNAL_PATH, '')); |
| 113 } else { | 110 } else { |
| 114 libraryIn = libraryOut; | 111 libraryIn = libraryOut; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 193 } |
| 197 } | 194 } |
| 198 | 195 |
| 199 // TODO(kustermann): We suppress compiler hints/warnings/errors temporarily | 196 // TODO(kustermann): We suppress compiler hints/warnings/errors temporarily |
| 200 // because everyone building the `runtime` target will get these now. | 197 // because everyone building the `runtime` target will get these now. |
| 201 // We should remove the suppression again once the underlying issues have | 198 // We should remove the suppression again once the underlying issues have |
| 202 // been fixed (either in fasta or the dart files in the patched_sdk). | 199 // been fixed (either in fasta or the dart files in the patched_sdk). |
| 203 final capturedLines = <String>[]; | 200 final capturedLines = <String>[]; |
| 204 try { | 201 try { |
| 205 await runZoned(() async { | 202 await runZoned(() async { |
| 206 await compile_platform.main(<String>[ | 203 await compile_platform.mainEntryPoint(<String>[ |
| 207 '--packages', | 204 '--packages', |
| 208 new Uri.file(packagesFile).toString(), | 205 new Uri.file(packagesFile).toString(), |
| 209 new Uri.directory(outDir).toString(), | 206 new Uri.directory(outDir).toString(), |
| 210 path.join(outDir, 'platform.dill') | 207 path.join(outDir, 'platform.dill') |
| 211 ]); | 208 ]); |
| 212 }, zoneSpecification: new ZoneSpecification(print: (_, _2, _3, line) { | 209 }, zoneSpecification: new ZoneSpecification(print: (_, _2, _3, line) { |
| 213 capturedLines.add(line); | 210 capturedLines.add(line); |
| 214 })); | 211 })); |
| 215 } catch (_) { | 212 } catch (_) { |
| 216 for (final line in capturedLines) { | 213 for (final line in capturedLines) { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (diff != 0) return diff; | 551 if (diff != 0) return diff; |
| 555 return end - other.end; | 552 return end - other.end; |
| 556 } | 553 } |
| 557 } | 554 } |
| 558 | 555 |
| 559 List<SdkLibrary> _getSdkLibraries(String contents) { | 556 List<SdkLibrary> _getSdkLibraries(String contents) { |
| 560 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); | 557 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); |
| 561 parseCompilationUnit(contents).accept(libraryBuilder); | 558 parseCompilationUnit(contents).accept(libraryBuilder); |
| 562 return libraryBuilder.librariesMap.sdkLibraries; | 559 return libraryBuilder.librariesMap.sdkLibraries; |
| 563 } | 560 } |
| OLD | NEW |