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

Side by Side Diff: tool/patch_sdk.dart

Issue 1266483003: format with dart_style 0.2.0-rc.3 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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 | « test/testing.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 dev_compiler.tool.patch_sdk; 8 library dev_compiler.tool.patch_sdk;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 26 matching lines...) Expand all
37 var patchIn = path.join(input, 'patch'); 37 var patchIn = path.join(input, 'patch');
38 var privateIn = path.join(input, 'private'); 38 var privateIn = path.join(input, 'private');
39 var sdkOut = path.join(argv[1], 'lib'); 39 var sdkOut = path.join(argv[1], 'lib');
40 40
41 var INTERNAL_PATH = '_internal/compiler/js_lib/'; 41 var INTERNAL_PATH = '_internal/compiler/js_lib/';
42 42
43 // Copy libraries.dart and version 43 // Copy libraries.dart and version
44 var libContents = new File(path.join(sdkLibIn, '_internal', 'libraries.dart')) 44 var libContents = new File(path.join(sdkLibIn, '_internal', 'libraries.dart'))
45 .readAsStringSync(); 45 .readAsStringSync();
46 _writeSync(path.join(sdkOut, '_internal', 'libraries.dart'), libContents); 46 _writeSync(path.join(sdkOut, '_internal', 'libraries.dart'), libContents);
47 _writeSync(path.join( 47 _writeSync(
48 path.join(
48 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), 49 sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'),
49 libContents); 50 libContents);
50 _writeSync(path.join(sdkOut, '..', 'version'), 51 _writeSync(path.join(sdkOut, '..', 'version'),
51 new File(path.join(sdkLibIn, '..', 'version')).readAsStringSync()); 52 new File(path.join(sdkLibIn, '..', 'version')).readAsStringSync());
52 53
53 // Parse libraries.dart 54 // Parse libraries.dart
54 var sdkLibraries = _getSdkLibraries(libContents); 55 var sdkLibraries = _getSdkLibraries(libContents);
55 56
56 // Enumerate core libraries and apply patches 57 // Enumerate core libraries and apply patches
57 for (SdkLibrary library in sdkLibraries) { 58 for (SdkLibrary library in sdkLibraries) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (_isLibrary) _mergeUnpatched(node); 161 if (_isLibrary) _mergeUnpatched(node);
161 } 162 }
162 163
163 void _merge(AstNode node, int pos) { 164 void _merge(AstNode node, int pos) {
164 var code = patch.contents.substring(node.offset, node.end); 165 var code = patch.contents.substring(node.offset, node.end);
165 edits.insert(pos, '\n' + code); 166 edits.insert(pos, '\n' + code);
166 } 167 }
167 168
168 /// Merges directives and declarations that are not `@patch` into the library. 169 /// Merges directives and declarations that are not `@patch` into the library.
169 void _mergeUnpatched(CompilationUnit unit) { 170 void _mergeUnpatched(CompilationUnit unit) {
170
171 // Merge imports from the patch 171 // Merge imports from the patch
172 // TODO(jmesserly): remove duplicate imports 172 // TODO(jmesserly): remove duplicate imports
173 173
174 // To patch a library, we must have a library directive 174 // To patch a library, we must have a library directive
175 var libDir = unit.directives.first as LibraryDirective; 175 var libDir = unit.directives.first as LibraryDirective;
176 int importPos = unit.directives.lastWhere((d) => d is ImportDirective, 176 int importPos = unit.directives
177 orElse: () => libDir).end; 177 .lastWhere((d) => d is ImportDirective, orElse: () => libDir)
178 .end;
178 for (var d in patch.unit.directives.where((d) => d is ImportDirective)) { 179 for (var d in patch.unit.directives.where((d) => d is ImportDirective)) {
179 _merge(d, importPos); 180 _merge(d, importPos);
180 } 181 }
181 182
182 int partPos = unit.directives.last.end; 183 int partPos = unit.directives.last.end;
183 for (var d in patch.unit.directives.where((d) => d is PartDirective)) { 184 for (var d in patch.unit.directives.where((d) => d is PartDirective)) {
184 _merge(d, partPos); 185 _merge(d, partPos);
185 } 186 }
186 187
187 // Merge declarations from the patch 188 // Merge declarations from the patch
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 if (diff != 0) return diff; 392 if (diff != 0) return diff;
392 return end - other.end; 393 return end - other.end;
393 } 394 }
394 } 395 }
395 396
396 List<SdkLibrary> _getSdkLibraries(String contents) { 397 List<SdkLibrary> _getSdkLibraries(String contents) {
397 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); 398 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true);
398 parseCompilationUnit(contents).accept(libraryBuilder); 399 parseCompilationUnit(contents).accept(libraryBuilder);
399 return libraryBuilder.librariesMap.sdkLibraries; 400 return libraryBuilder.librariesMap.sdkLibraries;
400 } 401 }
OLDNEW
« no previous file with comments | « test/testing.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698