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

Side by Side Diff: tool/patch_sdk.dart

Issue 955513008: cleans up sdk patching so we no longer have unresolved names (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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 | « tool/input_sdk_src/lib/isolate/isolate.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 library ddc.tool.patch_sdk; 8 library ddc.tool.patch_sdk;
9 9
10 import 'dart:io'; 10 import 'dart:io';
11 11
12 import 'package:analyzer/analyzer.dart'; 12 import 'package:analyzer/analyzer.dart';
13 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
14 14
15 import 'input_sdk_src/lib/_internal/libraries.dart' as sdk; 15 import 'input_sdk_src/lib/_internal/libraries.dart' as sdk;
16 16
17 void main(List<String> argv) { 17 void main(List<String> argv) {
18 var toolDir = path.relative(path.dirname(Platform.script.path)); 18 var toolDir = path.relative(path.dirname(Platform.script.path));
19 var sdkIn = path.join(toolDir, 'input_sdk_src', 'lib'); 19 var sdkIn = path.join(toolDir, 'input_sdk_src', 'lib');
20 var patchIn = path.join(toolDir, 'input_sdk_patch'); 20 var patchIn = path.join(toolDir, 'input_sdk_patch');
21 var sdkOut = path.join(path.dirname(toolDir), 'test', 'generated_sdk', 'lib'); 21 var sdkOut =
22 path.normalize(path.join(toolDir, '..', 'test', 'generated_sdk', 'lib'));
22 23
23 if (argv.isNotEmpty) { 24 if (argv.isNotEmpty) {
24 print('Usage: ${path.relative(Platform.script.path)}\n'); 25 print('Usage: ${path.relative(Platform.script.path)}\n');
25 print('input SDK directory: $sdkIn'); 26 print('input SDK directory: $sdkIn');
26 print('input patch directory: $patchIn'); 27 print('input patch directory: $patchIn');
27 print('output SDK directory: $sdkOut'); 28 print('output SDK directory: $sdkOut');
28 exit(1); 29 exit(1);
29 } 30 }
30 31
31 // Copy libraries.dart and version 32 // Copy libraries.dart and version
32 _writeSync(path.join(sdkOut, '_internal', 'libraries.dart'), 33 _writeSync(path.join(sdkOut, '_internal', 'libraries.dart'),
33 new File(path.join(sdkIn, '_internal', 'libraries.dart')) 34 new File(path.join(sdkIn, '_internal', 'libraries.dart'))
34 .readAsStringSync()); 35 .readAsStringSync());
35 _writeSync(path.join(sdkOut, '..', 'version'), 36 _writeSync(path.join(sdkOut, '..', 'version'),
36 new File(path.join(sdkIn, '..', 'version')).readAsStringSync()); 37 new File(path.join(sdkIn, '..', 'version')).readAsStringSync());
37 38
38 // Enumerate core libraries and apply patches 39 // Enumerate core libraries and apply patches
39 for (var library in sdk.LIBRARIES.values) { 40 for (var library in sdk.LIBRARIES.values) {
41 if (library.platforms & sdk.DART2JS_PLATFORM == 0) continue;
42
40 var libraryPath = path.join(sdkIn, library.path); 43 var libraryPath = path.join(sdkIn, library.path);
44
41 var libraryFile = new File(libraryPath); 45 var libraryFile = new File(libraryPath);
42 if (libraryFile.existsSync()) { 46 if (libraryFile.existsSync()) {
43 var contents = <String>[]; 47 var contents = <String>[];
44 var paths = <String>[]; 48 var paths = <String>[];
45 var libraryContents = libraryFile.readAsStringSync(); 49 var libraryContents = libraryFile.readAsStringSync();
46 paths.add(libraryPath); 50 paths.add(libraryPath);
47 contents.add(libraryContents); 51 contents.add(libraryContents);
48 for (var part in parseDirectives(libraryContents).directives) { 52 for (var part in parseDirectives(libraryContents).directives) {
49 if (part is PartDirective) { 53 if (part is PartDirective) {
50 paths.add(path.join(path.dirname(libraryPath), part.uri.stringValue)); 54 paths.add(path.join(path.dirname(libraryPath), part.uri.stringValue));
51 contents.add(new File(paths.last).readAsStringSync()); 55 contents.add(new File(paths.last).readAsStringSync());
52 } 56 }
53 } 57 }
54 58
55 var patchPath = path.join(patchIn, library.dart2jsPatchPath.replaceAll( 59 if (library.dart2jsPatchPath != null) {
56 '_internal/compiler/js_lib/', '')); 60 var patchPath = path.join(patchIn, library.dart2jsPatchPath.replaceAll(
57 var patchContents = new File(patchPath).readAsStringSync(); 61 '_internal/compiler/js_lib/', ''));
62 var patchContents = new File(patchPath).readAsStringSync();
58 63
59 contents = _patchLibrary(contents, patchContents); 64 contents = _patchLibrary(contents, patchContents);
65 }
60 for (var i = 0; i < paths.length; i++) { 66 for (var i = 0; i < paths.length; i++) {
61 var outPath = path.join(sdkOut, path.relative(paths[i], from: sdkIn)); 67 var outPath = path.join(sdkOut, path.relative(paths[i], from: sdkIn));
62 _writeSync(outPath, contents[i]); 68 _writeSync(outPath, contents[i]);
63 } 69 }
64 } 70 }
65 } 71 }
66 } 72 }
67 73
68 /// Writes a file, creating the directory if needed. 74 /// Writes a file, creating the directory if needed.
69 void _writeSync(String filePath, String contents) { 75 void _writeSync(String filePath, String contents) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (_isLibrary) _mergeUnpatched(node); 132 if (_isLibrary) _mergeUnpatched(node);
127 } 133 }
128 134
129 /// Merges directives and declarations that are not `@patch` into the library. 135 /// Merges directives and declarations that are not `@patch` into the library.
130 void _mergeUnpatched(CompilationUnit unit) { 136 void _mergeUnpatched(CompilationUnit unit) {
131 // Merge directives from the patch 137 // Merge directives from the patch
132 // TODO(jmesserly): remove duplicate imports 138 // TODO(jmesserly): remove duplicate imports
133 var directivePos = unit.directives.last.end; 139 var directivePos = unit.directives.last.end;
134 for (var directive in patch.unit.directives) { 140 for (var directive in patch.unit.directives) {
135 var uri = directive.uri.stringValue; 141 var uri = directive.uri.stringValue;
136 // TODO(jmesserly): figure out what to do about these
137 if (uri.startsWith('dart:_') && uri != 'dart:_internal') continue;
138 var code = patch.contents.substring(directive.offset, directive.end); 142 var code = patch.contents.substring(directive.offset, directive.end);
139 edits.insert(directivePos, '\n' + code); 143 edits.insert(directivePos, '\n' + code);
140 } 144 }
141 145
142 // Merge declarations from the patch 146 // Merge declarations from the patch
143 var declarationPos = edits.original.length; 147 var declarationPos = edits.original.length;
144 for (var declaration in patch.mergeDeclarations) { 148 for (var declaration in patch.mergeDeclarations) {
145 var code = patch.contents.substring(declaration.offset, declaration.end); 149 var code = patch.contents.substring(declaration.offset, declaration.end);
146 edits.insert(declarationPos, '\n' + code); 150 edits.insert(declarationPos, '\n' + code);
147 } 151 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 int get length => end - begin; 346 int get length => end - begin;
343 347
344 String toString() => '(Edit @ $begin,$end: "$replace")'; 348 String toString() => '(Edit @ $begin,$end: "$replace")';
345 349
346 int compareTo(_StringEdit other) { 350 int compareTo(_StringEdit other) {
347 int diff = begin - other.begin; 351 int diff = begin - other.begin;
348 if (diff != 0) return diff; 352 if (diff != 0) return diff;
349 return end - other.end; 353 return end - other.end;
350 } 354 }
351 } 355 }
OLDNEW
« no previous file with comments | « tool/input_sdk_src/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698