Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: tools/patch_sdk.dart

Issue 2993113003: Revert "Switch FE to use the libraries.json format." (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/tool/fasta_perf.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 var outDirUri = Uri.base.resolveUri(new Uri.directory(outDir)); 101 var outDirUri = Uri.base.resolveUri(new Uri.directory(outDir));
102 var sdkOut = path.join(outDir, 'lib'); 102 var sdkOut = path.join(outDir, 'lib');
103 var packagesFile = argv[4]; 103 var packagesFile = argv[4];
104 104
105 // Parse libraries.dart 105 // Parse libraries.dart
106 var libContents = readInputFile(path.join( 106 var libContents = readInputFile(path.join(
107 sdkLibIn, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart')); 107 sdkLibIn, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'));
108 libContents = _updateLibraryMetadata(sdkOut, libContents); 108 libContents = _updateLibraryMetadata(sdkOut, libContents);
109 var sdkLibraries = _getSdkLibraries(libContents); 109 var sdkLibraries = _getSdkLibraries(libContents);
110 110
111 var locations = <String, Map<String, String>>{}; 111 Map<String, String> locations = <String, String>{};
112 112
113 // Enumerate core libraries and apply patches 113 // Enumerate core libraries and apply patches
114 for (SdkLibrary library in sdkLibraries) { 114 for (SdkLibrary library in sdkLibraries) {
115 if (forDart2js && library.isVmLibrary) continue; 115 if (forDart2js && library.isVmLibrary) continue;
116 if (!forDart2js && library.isDart2JsLibrary) continue; 116 if (!forDart2js && library.isDart2JsLibrary) continue;
117 _applyPatch(library, sdkLibIn, patchIn, sdkOut, locations); 117 _applyPatch(library, sdkLibIn, patchIn, sdkOut, locations);
118 } 118 }
119 119
120 _copyExtraLibraries(sdkOut, locations); 120 _copyExtraLibraries(sdkOut, locations);
121 121
122 Uri platform = outDirUri.resolve('platform.dill.tmp'); 122 Uri platform = outDirUri.resolve('platform.dill.tmp');
123 Uri outline = outDirUri.resolve('outline.dill'); 123 Uri outline = outDirUri.resolve('outline.dill');
124 Uri librariesJson = outDirUri.resolve("lib/libraries.json"); 124 Uri librariesJson = outDirUri.resolve("lib/libraries.json");
125 Uri packages = Uri.base.resolveUri(new Uri.file(packagesFile)); 125 Uri packages = Uri.base.resolveUri(new Uri.file(packagesFile));
126 126
127 await _writeSync( 127 await _writeSync(
128 librariesJson.toFilePath(), 128 librariesJson.toFilePath(), JSON.encode({"libraries": locations}));
129 JSON.encode({
130 mode: {"libraries": locations}
131 }));
132 129
133 var flags = new TargetFlags(); 130 var flags = new TargetFlags();
134 var target = forVm 131 var target = forVm
135 ? new VmFastaTarget(flags) 132 ? new VmFastaTarget(flags)
136 : (forFlutter ? new FlutterFastaTarget(flags) : new Dart2jsTarget(flags)); 133 : (forFlutter ? new FlutterFastaTarget(flags) : new Dart2jsTarget(flags));
137 var platformDeps = 134 var platformDeps =
138 await compilePlatform(outDirUri, target, packages, platform, outline); 135 await compilePlatform(outDirUri, target, packages, platform, outline);
139 deps.addAll(platformDeps); 136 deps.addAll(platformDeps);
140 137
141 if (forVm) { 138 if (forVm) {
142 // TODO(sigmund): add support for the flutter vmservice_sky as well. 139 // TODO(sigmund): add support for the flutter vmservice_sky as well.
143 var vmserviceName = 'vmservice_io'; 140 var vmserviceName = 'vmservice_io';
144 var base = path.fromUri(Platform.script); 141 var base = path.fromUri(Platform.script);
145 Uri dartDir = 142 Uri dartDir =
146 new Uri.directory(path.dirname(path.dirname(path.absolute(base)))); 143 new Uri.directory(path.dirname(path.dirname(path.absolute(base))));
147
148 String vmserviceJson = JSON.encode({
149 'vm': {
150 "libraries": {
151 '_vmservice': {
152 'uri': dartDir.resolve('sdk/lib/vmservice/vmservice.dart').path
153 },
154 'vmservice_io': {
155 'uri':
156 dartDir.resolve('runtime/bin/vmservice/vmservice_io.dart').path
157 },
158 }
159 }
160 });
161 Uri vmserviceJsonUri = outDirUri.resolve("lib/vmservice_libraries.json");
162 await _writeSync(vmserviceJsonUri.toFilePath(), vmserviceJson);
163 var program = await kernelForProgram( 144 var program = await kernelForProgram(
164 Uri.parse('dart:$vmserviceName'), 145 Uri.parse('dart:$vmserviceName'),
165 new CompilerOptions() 146 new CompilerOptions()
166 ..setExitCodeOnProblem = true 147 ..setExitCodeOnProblem = true
167 // TODO(sigmund): investigate. This should be outline, but it breaks 148 // TODO(sigmund): investigate. This should be outline, but it breaks
168 // vm-debug tests. Issue #30111 149 // vm-debug tests. Issue #30111
169 ..sdkSummary = platform 150 ..sdkSummary = platform
170 ..librariesSpecificationUri = vmserviceJsonUri 151 ..dartLibraries = <String, Uri>{
152 '_vmservice': dartDir.resolve('sdk/lib/vmservice/vmservice.dart'),
153 'vmservice_io':
154 dartDir.resolve('runtime/bin/vmservice/vmservice_io.dart'),
155 }
171 ..packagesFileUri = packages); 156 ..packagesFileUri = packages);
172 Uri vmserviceUri = outDirUri.resolve('$vmserviceName.dill'); 157 Uri vmserviceUri = outDirUri.resolve('$vmserviceName.dill');
173 // TODO(sigmund): remove. This is a workaround because in the VM 158 // TODO(sigmund): remove. This is a workaround because in the VM
174 // doesn't support loading vmservice if it contains external libraries 159 // doesn't support loading vmservice if it contains external libraries
175 // (there is an assertion that only fails in debug builds). Issue #30111 160 // (there is an assertion that only fails in debug builds). Issue #30111
176 program.libraries.forEach((l) => l.isExternal = false); 161 program.libraries.forEach((l) => l.isExternal = false);
177 await writeProgramToFile(program, vmserviceUri); 162 await writeProgramToFile(program, vmserviceUri);
178 } 163 }
179 164
180 Uri platformFinalLocation = outDirUri.resolve('platform.dill'); 165 Uri platformFinalLocation = outDirUri.resolve('platform.dill');
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 _writeSync( 326 _writeSync(
342 path.join( 327 path.join(
343 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), 328 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'),
344 libContents); 329 libContents);
345 return libContents; 330 return libContents;
346 } 331 }
347 332
348 /// Copy internal libraries that are developed outside the sdk folder into the 333 /// Copy internal libraries that are developed outside the sdk folder into the
349 /// patched_sdk folder. For the VM< this includes files under 'runtime/bin/', 334 /// patched_sdk folder. For the VM< this includes files under 'runtime/bin/',
350 /// for flutter, this is includes also the ui library. 335 /// for flutter, this is includes also the ui library.
351 _copyExtraLibraries(String sdkOut, Map<String, Map<String, String>> locations) { 336 _copyExtraLibraries(String sdkOut, Map<String, String> locations) {
352 if (forDart2js) return; 337 if (forDart2js) return;
353 var base = path.fromUri(Platform.script); 338 var base = path.fromUri(Platform.script);
354 var dartDir = path.dirname(path.dirname(path.absolute(base))); 339 var dartDir = path.dirname(path.dirname(path.absolute(base)));
355 340
356 var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', 'builtin.dart'); 341 var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', 'builtin.dart');
357 var builtinLibraryOut = path.join(sdkOut, '_builtin', '_builtin.dart'); 342 var builtinLibraryOut = path.join(sdkOut, '_builtin', '_builtin.dart');
358 _writeSync(builtinLibraryOut, readInputFile(builtinLibraryIn)); 343 _writeSync(builtinLibraryOut, readInputFile(builtinLibraryIn));
359 addLocation(locations, '_builtin', path.join('_builtin', '_builtin.dart')); 344 locations['_builtin'] = path.join('_builtin', '_builtin.dart');
360 345
361 if (forFlutter) { 346 if (forFlutter) {
362 // Flutter repo has this layout: 347 // Flutter repo has this layout:
363 // engine/src/ 348 // engine/src/
364 // dart/ 349 // dart/
365 // flutter/ 350 // flutter/
366 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base)))); 351 var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base))));
367 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui'); 352 var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui');
368 for (var file in new Directory(uiLibraryInDir).listSync()) { 353 for (var file in new Directory(uiLibraryInDir).listSync()) {
369 if (!file.path.endsWith('.dart')) continue; 354 if (!file.path.endsWith('.dart')) continue;
370 var name = path.basename(file.path); 355 var name = path.basename(file.path);
371 var uiLibraryOut = path.join(sdkOut, 'ui', name); 356 var uiLibraryOut = path.join(sdkOut, 'ui', name);
372 _writeSync(uiLibraryOut, readInputFile(file.path)); 357 _writeSync(uiLibraryOut, readInputFile(file.path));
373 } 358 }
374 addLocation(locations, 'ui', path.join('ui', 'ui.dart')); 359 locations['ui'] = 'ui/ui.dart';
375 360
376 if (!forFlutterRelease) { 361 if (!forFlutterRelease) {
377 // vmservice should be present unless we build release flavor of Flutter. 362 // vmservice should be present unless we build release flavor of Flutter.
378 // 363 //
379 // TODO(dartbug.com/30158): Consider producing separate Flutter 364 // TODO(dartbug.com/30158): Consider producing separate Flutter
380 // vmservice.dill with these vmservice libraries. 365 // vmservice.dill with these vmservice libraries.
381 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) { 366 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) {
382 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file); 367 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file);
383 var libraryOut = path.join(sdkOut, 'vmservice_io', file); 368 var libraryOut = path.join(sdkOut, 'vmservice_io', file);
384 _writeSync(libraryOut, readInputFile(libraryIn)); 369 _writeSync(libraryOut, readInputFile(libraryIn));
385 } 370 }
386 addLocation(locations, 'vmservice_sky', 371 locations['vmservice_sky'] =
387 path.join('vmservice_io', 'vmservice_io.dart')); 372 path.join('vmservice_io', 'vmservice_io.dart');
388 addLocation( 373 locations['_vmservice'] = path.join('vmservice', 'vmservice.dart');
389 locations, '_vmservice', path.join('vmservice', 'vmservice.dart'));
390 } 374 }
391 } 375 }
392 } 376 }
393 377
394 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut, 378 _applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut,
395 Map<String, Map<String, String>> locations) { 379 Map<String, String> locations) {
396 var libraryOut = path.join(sdkLibIn, library.path); 380 var libraryOut = path.join(sdkLibIn, library.path);
397 var libraryIn = libraryOut; 381 var libraryIn = libraryOut;
398 382
399 var libraryFile = getInputFile(libraryIn, canBeMissing: true); 383 var libraryFile = getInputFile(libraryIn, canBeMissing: true);
400 if (libraryFile != null) { 384 if (libraryFile != null) {
401 addLocation(locations, Uri.parse(library.shortName).path, 385 locations[Uri.parse(library.shortName).path] =
402 path.relative(libraryOut, from: sdkLibIn)); 386 path.relative(libraryOut, from: sdkLibIn);
403 var outPaths = <String>[libraryOut]; 387 var outPaths = <String>[libraryOut];
404 var libraryContents = libraryFile.readAsStringSync(); 388 var libraryContents = libraryFile.readAsStringSync();
405 389
406 int inputModifyTime = libraryFile.lastModifiedSync().millisecondsSinceEpoch; 390 int inputModifyTime = libraryFile.lastModifiedSync().millisecondsSinceEpoch;
407 var partFiles = <File>[]; 391 var partFiles = <File>[];
408 for (var part in parseDirectives(libraryContents).directives) { 392 for (var part in parseDirectives(libraryContents).directives) {
409 if (part is PartDirective) { 393 if (part is PartDirective) {
410 var partPath = part.uri.stringValue; 394 var partPath = part.uri.stringValue;
411 outPaths.add(path.join(path.dirname(libraryOut), partPath)); 395 outPaths.add(path.join(path.dirname(libraryOut), partPath));
412 396
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 if (diff != 0) return diff; 799 if (diff != 0) return diff;
816 return end - other.end; 800 return end - other.end;
817 } 801 }
818 } 802 }
819 803
820 List<SdkLibrary> _getSdkLibraries(String contents) { 804 List<SdkLibrary> _getSdkLibraries(String contents) {
821 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js); 805 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js);
822 parseCompilationUnit(contents).accept(libraryBuilder); 806 parseCompilationUnit(contents).accept(libraryBuilder);
823 return libraryBuilder.librariesMap.sdkLibraries; 807 return libraryBuilder.librariesMap.sdkLibraries;
824 } 808 }
825
826 void addLocation(Map<String, Map<String, String>> locations, String libraryName,
827 String path) {
828 assert(locations[libraryName] == null);
829 locations[libraryName] = {'uri': path};
830 }
OLDNEW
« no previous file with comments | « pkg/front_end/tool/fasta_perf.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698