OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:io'; | |
6 import 'dart:convert'; | |
7 import 'package:compiler/src/util/uri_extras.dart' show relativize; | |
8 | |
9 main(List<String> arguments) async { | |
10 if (arguments.length == 0) { | |
11 print('usage: build_sdk_json.dart <out-path>'); | |
12 exit(1); | |
13 } | |
14 | |
15 var out = arguments[0]; | |
16 List<Uri> sdkFiles = await collectSdkFiles(); | |
17 new File(out).writeAsStringSync(emitSdkAsJson(sdkFiles)); | |
18 } | |
19 | |
20 Uri sdkRoot = Uri.base.resolveUri(Platform.script).resolve('../../'); | |
21 | |
22 /// Collects a list of files that are part of the SDK. | |
23 List<Uri> collectSdkFiles() { | |
24 var files = <Uri>[]; | |
25 var sdkDir = new Directory.fromUri(sdkRoot.resolve('sdk/lib/')); | |
26 for (var entity in sdkDir.listSync(recursive: true)) { | |
27 if (entity is File && | |
28 (entity.path.endsWith('.dart') || entity.path.endsWith('.platform'))) { | |
29 files.add(entity.uri); | |
30 } | |
31 } | |
32 return files; | |
33 } | |
34 | |
35 /// Creates a string that encodes the contents of the sdk libraries in json. | |
36 /// | |
37 /// The keys of the json file are sdk-relative paths to source files, and the | |
38 /// values are the contents of the file. | |
39 String emitSdkAsJson(List<Uri> paths) { | |
40 var map = <String, String>{}; | |
41 for (var uri in paths) { | |
42 String filename = relativize(sdkRoot, uri, false); | |
43 var contents = new File.fromUri(uri).readAsStringSync(); | |
44 map['sdk:/$filename'] = contents; | |
45 } | |
46 return JSON.encode(map); | |
47 } | |
OLD | NEW |