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

Side by Side Diff: tools/patch_sdk.dart

Issue 2710943006: Make patch_sdk step invoke fasta's compile_platform to generate patched_sdk/platform.dill. (Closed)
Patch Set: Add kernel and front_end to dependencies Created 3 years, 10 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
« runtime/vm/BUILD.gn ('K') | « runtime/vm/vm.gypi ('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:math' as math; 10 import 'dart:math' as math;
11 11
12 import 'package:analyzer/analyzer.dart'; 12 import 'package:analyzer/analyzer.dart';
13 import 'package:analyzer/src/generated/sdk.dart'; 13 import 'package:analyzer/src/generated/sdk.dart';
14 import 'package:path/path.dart' as path; 14 import 'package:path/path.dart' as path;
15 import 'package:front_end/src/fasta/bin/compile_platform.dart' as
16 compile_platform;
15 17
16 void main(List<String> argv) { 18 void main(List<String> argv) {
17 var base = path.fromUri(Platform.script); 19 var base = path.fromUri(Platform.script);
18 var dartDir = path.dirname(path.dirname(path.absolute(base))); 20 var dartDir = path.dirname(path.dirname(path.absolute(base)));
19 21
20 if (argv.length != 4 || 22 if (argv.length != 5 || (!argv.isEmpty && argv.first != 'vm')) {
kustermann 2017/02/23 15:59:38 We have shortcut operators: Just use if (argv.len
21 !argv.isEmpty && argv.first != 'vm' && argv.first != 'ddc') {
22 var self = path.relative(base); 23 var self = path.relative(base);
23 print('Usage: $self MODE SDK_DIR PATCH_DIR OUTPUT_DIR'); 24 print('Usage: $self MODE SDK_DIR PATCH_DIR OUTPUT_DIR PACKAGES');
24 print('MODE must be one of ddc or vm.'); 25 print('MODE must be one of ddc or vm.');
kustermann 2017/02/23 15:59:39 Remove "ddc or".
25 26
26 var toolDir = path.relative(path.dirname(base)); 27 var repositoryDir = path.relative(path.dirname(path.dirname(base)));
27 var sdkExample = path.join(toolDir, 'input_sdk'); 28 var sdkExample = path.relative(path.join(repositoryDir, 'sdk'));
28 var patchExample = path.join(sdkExample, 'patch'); 29 var packagesExample = path.relative(path.join(repositoryDir, '.packages'));
29 var outExample = 30 var patchExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64',
30 path.relative(path.normalize(path.join('gen', 'patched_sdk'))); 31 'obj', 'gen', 'patch'));
32 var outExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64',
33 'obj', 'gen', 'patched_sdk'));
kustermann 2017/02/23 15:59:39 final?
31 print('For example:'); 34 print('For example:');
32 print('\$ $self ddc $sdkExample $patchExample $outExample');
33
34 var repositoryDir = path.relative(path.dirname(path.dirname(base)));
35 sdkExample = path.relative(path.join(repositoryDir, 'sdk'));
36 patchExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64',
37 'obj', 'gen', 'patch'));
38 outExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64',
39 'obj', 'gen', 'patched_sdk'));
40 print('or:');
41 print('\$ $self vm $sdkExample $patchExample $outExample'); 35 print('\$ $self vm $sdkExample $patchExample $outExample');
42 36
43 exit(1); 37 exit(1);
44 } 38 }
45 39
46 var mode = argv[0]; 40 var mode = argv[0];
47 var input = argv[1]; 41 var input = argv[1];
48 var sdkLibIn = path.join(input, 'lib'); 42 var sdkLibIn = path.join(input, 'lib');
49 var patchIn = argv[2]; 43 var patchIn = argv[2];
50 var sdkOut = path.join(argv[3], 'lib'); 44 var sdkOut = path.join(argv[3], 'lib');
45 var packagesFile = argv[4];
kustermann 2017/02/23 15:59:38 final?
51 46
52 var privateIn = path.join(input, 'private'); 47 var privateIn = path.join(input, 'private');
53 var INTERNAL_PATH = '_internal/compiler/js_lib/'; 48 var INTERNAL_PATH = '_internal/compiler/js_lib/';
54 49
55 // Copy and patch libraries.dart and version 50 // Copy and patch libraries.dart and version
56 var libContents = new File(path.join(sdkLibIn, '_internal', 51 var libContents = new File(path.join(sdkLibIn, '_internal',
57 'sdk_library_metadata', 'lib', 'libraries.dart')).readAsStringSync(); 52 'sdk_library_metadata', 'lib', 'libraries.dart')).readAsStringSync();
58 var patchedLibContents = libContents; 53 var patchedLibContents = libContents;
59 if (mode == 'vm') { 54 if (mode == 'vm') {
60 libContents = libContents.replaceAll( 55 libContents = libContents.replaceAll(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 contents = _patchLibrary( 168 contents = _patchLibrary(
174 patchFile.path, contents, patchContents); 169 patchFile.path, contents, patchContents);
175 } 170 }
176 171
177 for (var i = 0; i < outPaths.length; i++) { 172 for (var i = 0; i < outPaths.length; i++) {
178 _writeSync(outPaths[i], contents[i]); 173 _writeSync(outPaths[i], contents[i]);
179 } 174 }
180 } 175 }
181 } 176 }
182 } 177 }
178
183 if (mode == 'vm') { 179 if (mode == 'vm') {
184
185 for (var tuple in [['_builtin', 'builtin.dart']]) { 180 for (var tuple in [['_builtin', 'builtin.dart']]) {
186 var vmLibrary = tuple[0]; 181 var vmLibrary = tuple[0];
187 var dartFile = tuple[1]; 182 var dartFile = tuple[1];
188 183
189 // The "dart:_builtin" library is only available for the DartVM. 184 // The "dart:_builtin" library is only available for the DartVM.
190 var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', dartFile); 185 var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', dartFile);
191 var builtinLibraryOut = path.join(sdkOut, vmLibrary, '${vmLibrary}.dart'); 186 var builtinLibraryOut = path.join(sdkOut, vmLibrary, '${vmLibrary}.dart');
192 _writeSync(builtinLibraryOut, new File(builtinLibraryIn).readAsStringSync( )); 187 _writeSync(builtinLibraryOut, new File(builtinLibraryIn).readAsStringSync( ));
193 } 188 }
194 189
195 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) { 190 for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) {
196 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file); 191 var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file);
197 var libraryOut = path.join(sdkOut, 'vmservice_io', file); 192 var libraryOut = path.join(sdkOut, 'vmservice_io', file);
198 _writeSync(libraryOut, new File(libraryIn).readAsStringSync()); 193 _writeSync(libraryOut, new File(libraryIn).readAsStringSync());
199 } 194 }
200 } 195 }
196
197 compile_platform.main(<String>[
kustermann 2017/02/23 15:59:39 await compile_platform.main();
198 '--packages', packagesFile, sdkOut, path.join(sdkOut, 'platform.dill')
199 ]);
201 } 200 }
202 201
203 /// Writes a file, creating the directory if needed. 202 /// Writes a file, creating the directory if needed.
204 void _writeSync(String filePath, String contents) { 203 void _writeSync(String filePath, String contents) {
205 var outDir = new Directory(path.dirname(filePath)); 204 var outDir = new Directory(path.dirname(filePath));
206 if (!outDir.existsSync()) outDir.createSync(recursive: true); 205 if (!outDir.existsSync()) outDir.createSync(recursive: true);
207 206
208 new File(filePath).writeAsStringSync(contents); 207 new File(filePath).writeAsStringSync(contents);
209 } 208 }
210 209
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (diff != 0) return diff; 533 if (diff != 0) return diff;
535 return end - other.end; 534 return end - other.end;
536 } 535 }
537 } 536 }
538 537
539 List<SdkLibrary> _getSdkLibraries(String contents) { 538 List<SdkLibrary> _getSdkLibraries(String contents) {
540 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); 539 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true);
541 parseCompilationUnit(contents).accept(libraryBuilder); 540 parseCompilationUnit(contents).accept(libraryBuilder);
542 return libraryBuilder.librariesMap.sdkLibraries; 541 return libraryBuilder.librariesMap.sdkLibraries;
543 } 542 }
OLDNEW
« runtime/vm/BUILD.gn ('K') | « runtime/vm/vm.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698