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

Unified Diff: site/try/build_sdk_json.dart

Issue 2006993002: Build sdk.json without source-mirrors (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/samples/jsonify/jsonify.dart ('k') | site/try/build_try.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: site/try/build_sdk_json.dart
diff --git a/site/try/build_sdk_json.dart b/site/try/build_sdk_json.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b46cc77ade65eb456df48c4c0104a4c9bd6e7b7e
--- /dev/null
+++ b/site/try/build_sdk_json.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+import 'dart:convert';
+import 'package:compiler/src/util/uri_extras.dart' show relativize;
+
+main(List<String> arguments) async {
+ if (arguments.length == 0) {
+ print('usage: jsonify.dart <out-path>');
Harry Terkelsen 2016/05/24 16:17:30 usage: build_sdk_json.dart <out-path>
Siggi Cherem (dart-lang) 2016/05/24 16:50:34 Done.
+ exit(1);
+ }
+
+ var out = arguments[0];
+ List<Uri> sdkFiles = await collectSdkFiles();
+ new File(out).writeAsStringSync(emitSdkAsJson(sdkFiles));
+}
+
+Uri sdkRoot = Uri.base.resolveUri(Platform.script).resolve('../../');
+
+/// Collects a list of files that are part of the SDK.
+List<Uri> collectSdkFiles() {
+ var files = <Uri>[];
+ for (var entity in new
+ Directory.fromUri(sdkRoot.resolve('sdk/lib/')).listSync(recursive: true)) {
Harry Terkelsen 2016/05/24 16:17:30 run dartfmt on this?
Siggi Cherem (dart-lang) 2016/05/24 16:50:34 Done. Split out subexpression to make it more read
+ if (entity is File &&
+ (entity.path.endsWith('.dart') || entity.path.endsWith('.platform'))) {
+ files.add(entity.uri);
+ }
+ }
+ return files;
+}
+
+/// Creates a string that encodes the contents of the sdk libraries in json.
+///
+/// The keys of the json file are sdk-relative paths to source files, and the
+/// values are the contents of the file.
+String emitSdkAsJson(List<Uri> paths) {
+ var map = <String, String>{};
+ for (var uri in paths) {
+ String filename = relativize(sdkRoot, uri, false);
Harry Terkelsen 2016/05/24 16:17:30 out of scope for this CL but the boolean flag for
Siggi Cherem (dart-lang) 2016/05/24 16:50:34 Agree - in the future we should also migrate to us
+ var contents = new File.fromUri(uri).readAsStringSync();
+ map['sdk:/$filename'] = contents;
+ }
+ return JSON.encode(map);
+}
« no previous file with comments | « pkg/compiler/samples/jsonify/jsonify.dart ('k') | site/try/build_try.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698