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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); | 67 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patch')); |
68 final outExample = path.relative( | 68 final outExample = path.relative( |
69 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patched_sdk')); | 69 path.join(repositoryDir, 'out', 'DebugX64', 'obj', 'gen', 'patched_sdk')); |
70 final packagesExample = path.relative(path.join(repositoryDir, '.packages')); | 70 final packagesExample = path.relative(path.join(repositoryDir, '.packages')); |
71 print('For example:'); | 71 print('For example:'); |
72 print('\$ $self vm $sdkExample $patchExample $outExample $packagesExample'); | 72 print('\$ $self vm $sdkExample $patchExample $outExample $packagesExample'); |
73 | 73 |
74 exit(1); | 74 exit(1); |
75 } | 75 } |
76 | 76 |
77 const validModes = const ['vm', 'dart2js', 'flutter']; | 77 const validModes = const ['vm', 'dart2js', 'flutter', 'flutter_release']; |
78 String mode; | 78 String mode; |
79 bool get forVm => mode == 'vm'; | 79 bool get forVm => mode == 'vm'; |
80 bool get forFlutter => mode == 'flutter'; | 80 bool get forFlutter => mode == 'flutter' || mode == 'flutter_release'; |
81 bool get forFlutterRelease => mode == 'flutter_release'; | |
81 bool get forDart2js => mode == 'dart2js'; | 82 bool get forDart2js => mode == 'dart2js'; |
82 | 83 |
83 Future _main(List<String> argv) async { | 84 Future _main(List<String> argv) async { |
84 if (argv.isEmpty) usage('[${validModes.join('|')}]'); | 85 if (argv.isEmpty) usage('[${validModes.join('|')}]'); |
85 mode = argv.first; | 86 mode = argv.first; |
86 if (!validModes.contains(mode)) usage('[${validModes.join('|')}]'); | 87 if (!validModes.contains(mode)) usage('[${validModes.join('|')}]'); |
87 if (argv.length != 5) usage(mode); | 88 if (argv.length != 5) usage(mode); |
88 | 89 |
89 var input = argv[1]; | 90 var input = argv[1]; |
90 var sdkLibIn = path.join(input, 'lib'); | 91 var sdkLibIn = path.join(input, 'lib'); |
(...skipping 25 matching lines...) Expand all Loading... | |
116 Uri librariesJson = outDirUri.resolve("lib/libraries.json"); | 117 Uri librariesJson = outDirUri.resolve("lib/libraries.json"); |
117 Uri packages = Uri.base.resolveUri(new Uri.file(packagesFile)); | 118 Uri packages = Uri.base.resolveUri(new Uri.file(packagesFile)); |
118 | 119 |
119 await _writeSync( | 120 await _writeSync( |
120 librariesJson.toFilePath(), JSON.encode({"libraries": locations})); | 121 librariesJson.toFilePath(), JSON.encode({"libraries": locations})); |
121 | 122 |
122 if (forVm || forFlutter) { | 123 if (forVm || forFlutter) { |
123 await fasta.compilePlatform(outDirUri, platform, | 124 await fasta.compilePlatform(outDirUri, platform, |
124 packages: packages, | 125 packages: packages, |
125 outlineOutput: outline, | 126 outlineOutput: outline, |
126 backendTarget: forVm ? 'vm_fasta' : 'flutter_fasta'); | 127 backendTarget: forVm |
128 ? 'vm_fasta' | |
129 : forFlutterRelease ? 'flutter_fasta_release' : 'flutter_fasta'); | |
127 } else { | 130 } else { |
128 await dart2js.compilePlatform(outDirUri, platform, | 131 await dart2js.compilePlatform(outDirUri, platform, |
129 packages: packages, outlineOutput: outline); | 132 packages: packages, outlineOutput: outline); |
130 } | 133 } |
131 | 134 |
132 if (forVm) { | 135 if (forVm) { |
133 var base = path.fromUri(Platform.script); | 136 var base = path.fromUri(Platform.script); |
134 Uri repositoryDir = | 137 Uri repositoryDir = |
135 new Uri.directory(path.dirname(path.dirname(path.absolute(base)))); | 138 new Uri.directory(path.dirname(path.dirname(path.absolute(base)))); |
136 var vmserviceName = 'vmservice_io'; | 139 var vmserviceName = 'vmservice_io'; |
Siggi Cherem (dart-lang)
2017/07/10 17:29:57
I thought instead we would compile vmservice_sky h
aam
2017/07/10 22:11:37
Yeah, something like that make sense, yet somehow
| |
137 Uri vmserviceSdk = repositoryDir.resolve('runtime/bin/vmservice_sdk/'); | 140 Uri vmserviceSdk = repositoryDir.resolve('runtime/bin/vmservice_sdk/'); |
138 Uri vmserviceUri = outDirUri.resolve('$vmserviceName.dill'); | 141 Uri vmserviceUri = outDirUri.resolve('$vmserviceName.dill'); |
139 // TODO(sigmundch): Specify libraries.json directly instead of "--sdk" | 142 // TODO(sigmundch): Specify libraries.json directly instead of "--sdk" |
140 // after #29882 is fixed. | 143 // after #29882 is fixed. |
141 await fasta.compile([ | 144 await fasta.compile([ |
142 "--sdk=$vmserviceSdk", | 145 "--sdk=$vmserviceSdk", |
143 "--platform=$outline", | 146 "--platform=$outline", |
144 "--target=vm_fasta", | 147 "--target=vm_fasta", |
145 "--packages=$packages", | 148 "--packages=$packages", |
146 "dart:$vmserviceName", | 149 "dart:$vmserviceName", |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 '''); | 222 '''); |
220 | 223 |
221 if (forFlutter) { | 224 if (forFlutter) { |
222 extraLibraries.write(''' | 225 extraLibraries.write(''' |
223 "ui": const LibraryInfo( | 226 "ui": const LibraryInfo( |
224 "ui/ui.dart", | 227 "ui/ui.dart", |
225 categories: "Client,Server", | 228 categories: "Client,Server", |
226 implementation: true, | 229 implementation: true, |
227 documented: false, | 230 documented: false, |
228 platforms: VM_PLATFORM), | 231 platforms: VM_PLATFORM), |
232 | |
229 '''); | 233 '''); |
234 | |
235 if (!forFlutterRelease) { | |
236 // vmservice should be present unless we build release flavor of Flutter. | |
237 extraLibraries.write(''' | |
238 "_vmservice": const LibraryInfo( | |
239 "vmservice/vmservice.dart", | |
240 categories: "Client,Server", | |
241 implementation: true, | |
242 documented: false, | |
243 platforms: VM_PLATFORM), | |
244 | |
245 "vmservice_sky": const LibraryInfo( | |
246 "vmservice_sky/vmservice_io.dart", | |
247 categories: "Client,Server", | |
248 implementation: true, | |
249 documented: false, | |
250 platforms: VM_PLATFORM), | |
251 | |
252 '''); | |
253 } | |
230 } | 254 } |
231 | 255 |
232 libContents = libContents.replaceAll( | 256 libContents = libContents.replaceAll( |
233 ' libraries = const {', ' libraries = const { $extraLibraries'); | 257 ' libraries = const {', ' libraries = const { $extraLibraries'); |
234 _writeSync( | 258 _writeSync( |
235 path.join( | 259 path.join( |
236 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), | 260 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), |
237 libContents); | 261 libContents); |
238 return libContents; | 262 return libContents; |
239 } | 263 } |
(...skipping 18 matching lines...) Expand all Loading... | |
258 // flutter/ | 282 // flutter/ |
259 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base)))); | 283 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base)))); |
260 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui'); | 284 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui'); |
261 for (var file in new Directory(uiLibraryInDir).listSync()) { | 285 for (var file in new Directory(uiLibraryInDir).listSync()) { |
262 if (!file.path.endsWith('.dart')) continue; | 286 if (!file.path.endsWith('.dart')) continue; |
263 var name = path.basename(file.path); | 287 var name = path.basename(file.path); |
264 var uiLibraryOut = path.join(sdkOut, 'ui', name); | 288 var uiLibraryOut = path.join(sdkOut, 'ui', name); |
265 _writeSync(uiLibraryOut, readInputFile(file.path)); | 289 _writeSync(uiLibraryOut, readInputFile(file.path)); |
266 } | 290 } |
267 locations['ui'] = 'ui/ui.dart'; | 291 locations['ui'] = 'ui/ui.dart'; |
292 | |
293 if (!forFlutterRelease) { | |
294 // vmservice should be present unless we build release flavor of Flutter. | |
295 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) { | |
296 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file); | |
297 var libraryOut = path.join(sdkOut, 'vmservice_io', file); | |
298 _writeSync(libraryOut, readInputFile(libraryIn)); | |
299 } | |
300 | |
301 locations['vmservice_sky'] = | |
302 path.join('vmservice_io', 'vmservice_io.dart'); | |
303 locations['_vmservice'] = path.join('vmservice', 'vmservice.dart'); | |
304 } | |
268 } | 305 } |
269 } | 306 } |
270 | 307 |
271 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut, | 308 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut, |
272 Map<String, String> locations) { | 309 Map<String, String> locations) { |
273 var libraryOut = path.join(sdkLibIn, library.path); | 310 var libraryOut = path.join(sdkLibIn, library.path); |
274 var libraryIn = libraryOut; | 311 var libraryIn = libraryOut; |
275 | 312 |
276 var libraryFile = getInputFile(libraryIn, canBeMissing: true); | 313 var libraryFile = getInputFile(libraryIn, canBeMissing: true); |
277 if (libraryFile != null) { | 314 if (libraryFile != null) { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 if (diff != 0) return diff; | 711 if (diff != 0) return diff; |
675 return end - other.end; | 712 return end - other.end; |
676 } | 713 } |
677 } | 714 } |
678 | 715 |
679 List<SdkLibrary> _getSdkLibraries(String contents) { | 716 List<SdkLibrary> _getSdkLibraries(String contents) { |
680 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js); | 717 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js); |
681 parseCompilationUnit(contents).accept(libraryBuilder); | 718 parseCompilationUnit(contents).accept(libraryBuilder); |
682 return libraryBuilder.librariesMap.sdkLibraries; | 719 return libraryBuilder.librariesMap.sdkLibraries; |
683 } | 720 } |
OLD | NEW |