{"action":"created","comment":{"url":"https://api.github.com/repos/flutter/flutter/pulls/comments/66878769","id":66878769,"diff_hunk":"@@ -0,0 +1,257 @@\n+// Copyright 2016 The Chromium Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file.\n+\n+import 'dart:io';\n+\n+import 'package:analyzer/analyzer.dart';\n+import 'package:analyzer/src/generated/java_io.dart'; // ignore: implementation_imports\n+import 'package:analyzer/src/generated/sdk.dart'; // ignore: implementation_imports\n+import 'package:analyzer/src/generated/sdk_io.dart'; // ignore: implementation_imports\n+import 'package:package_config/packages_file.dart' as packages;\n+import 'package:path/path.dart' as path;\n+import 'package:yaml/yaml.dart' as yaml;\n+\n+import 'sdk.dart';\n+\n+// TODO(devoncarew): Implement added, changed, and removed sources information (add a GraphChange class).\n+// TODO(devoncarew): Use GraphSourceReferences.resolved when doing incremental checks.\n+// TODO(devoncarew): For performance, the lexer should not lex the entire file.\n+\n+class SourceGraph {\n+  SourceGraph(this.directory, this.entryPointPath, { this.parseEmbedderSource: false });\n+\n+  final Directory directory;\n+  final String entryPointPath;\n+  final bool parseEmbedderSource;\n+\n+  PackagesFile _packagesFile;\n+  Map<String, String> _dartLibraryMap = <String, String>{};\n+  bool _wasIncremental = false;\n+  Map<String, GraphSource> _sourceMap = <String, GraphSource>{};\n+\n+  /// Whether the last parse was incremental, or a full re-parse.\n+  bool get wasIncremental => _wasIncremental;\n+\n+  Iterable<GraphSource> get sources => _sourceMap.values;\n+\n+  void initialParse() {\n+    _fullParse();\n+  }\n+\n+  // TODO(devoncarew): Implement an incremental mode.\n+  void reparseSources() {\n+    _fullParse();\n+  }\n+\n+  /// Flush any cached file contents.\n+  void flushCachedFileContents() {\n+    for (GraphSource source in sources)\n+      source.flushCachedFileContents();\n+  }\n+\n+  void _fullParse() {\n+    _wasIncremental = false;\n+\n+    _sourceMap.clear();\n+\n+    if (parseEmbedderSource) {\n+      // Parse the libraries.dart file - use that info to resolve dart: references.\n+      _dartLibraryMap.clear();\n+      String sdkPath = dartSdkPath;\n+      File librariesFile = new File(path.join(sdkPath, 'lib/_internal/libraries.dart'));\n+      if (librariesFile.existsSync()) {\n+        SdkLibrariesReader reader = new SdkLibrariesReader(false);\n+        LibraryMap dartLibraryMap = reader.readFromFile(\n+          new JavaFile(librariesFile.path), librariesFile.readAsStringSync()\n+        );\n+\n+        String libPath = path.normalize(path.absolute(path.join(dartSdkPath, 'lib')));\n+        for (SdkLibrary library in dartLibraryMap.sdkLibraries)\n+          _dartLibraryMap[library.shortName] = path.join(libPath, library.path);\n+      }\n+    }\n+\n+    // Parse the .packages file.\n+    _packagesFile = new PackagesFile(new File(path.join(directory.path, '.packages')));\n+    _packagesFile.parse();\n+\n+    GraphSource root = _getCreateSource(path.join(directory.path, entryPointPath));\n+    root.parse();\n+\n+    // Parse any dirty sources.\n+    while (sources.any((GraphSource source) => source.dirty)) {\n+      for (GraphSource source in sources.where((GraphSource source) => source.dirty).toList()) {\n+        source.parse();\n+      }\n+    }\n+  }\n+\n+  GraphSource _getCreateSource(String resolvedPath) {\n+    if (_sourceMap.containsKey(resolvedPath)) {\n+      return _sourceMap[resolvedPath];\n+    } else {\n+      GraphSource source = new GraphSource(this, resolvedPath);\n+      _sourceMap[resolvedPath] = source;\n+      return source;\n+    }\n+  }\n+\n+  String _resolveDirectiveUri(String uriString, String basePath) {","path":"packages/flutter_tools/lib/src/dart/source_graph.dart","position":100,"original_position":100,"commit_id":"088b76626d67f4df12c63fc23cfa7e0c2f6a4061","original_commit_id":"088b76626d67f4df12c63fc23cfa7e0c2f6a4061","user":{"login":"bwilkerson","id":5840555,"avatar_url":"https://avatars.githubusercontent.com/u/5840555?v=3","gravatar_id":"","url":"https://api.github.com/users/bwilkerson","html_url":"https://github.com/bwilkerson","followers_url":"https://api.github.com/users/bwilkerson/followers","following_url":"https://api.github.com/users/bwilkerson/following{/other_user}","gists_url":"https://api.github.com/users/bwilkerson/gists{/gist_id}","starred_url":"https://api.github.com/users/bwilkerson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwilkerson/subscriptions","organizations_url":"https://api.github.com/users/bwilkerson/orgs","repos_url":"https://api.github.com/users/bwilkerson/repos","events_url":"https://api.github.com/users/bwilkerson/events{/privacy}","received_events_url":"https://api.github.com/users/bwilkerson/received_events","type":"User","site_admin":false},"body":"A minor observation: this duplicates some of the logic in SourceFactory. Possibly more importantly, it doesn't match the VM's rules for URI equality. I don't know what the VM's hot-patching API looks like, but if you're sending a mapping from URI to file content, there might be a subtle bug here related to relative URI's. We should talk off-line.","created_at":"2016-06-13T22:15:34Z","updated_at":"2016-06-13T22:15:34Z","html_url":"https://github.com/flutter/flutter/pull/4543#discussion_r66878769","pull_request_url":"https://api.github.com/repos/flutter/flutter/pulls/4543","_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments/66878769"},"html":{"href":"https://github.com/flutter/flutter/pull/4543#discussion_r66878769"},"pull_request":{"href":"https://api.github.com/repos/flutter/flutter/pulls/4543"}}},"pull_request":{"url":"https://api.github.com/repos/flutter/flutter/pulls/4543","id":73644461,"html_url":"https://github.com/flutter/flutter/pull/4543","diff_url":"https://github.com/flutter/flutter/pull/4543.diff","patch_url":"https://github.com/flutter/flutter/pull/4543.patch","issue_url":"https://api.github.com/repos/flutter/flutter/issues/4543","number":4543,"state":"open","locked":false,"title":"add a source_graph library to find the transitive deps of an entry-point","user":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"body":"This uses the analyzer library to do parse the directives of dart files, traversing from an entry-point to all referenced sources. This will be used to send dart sources to the VM's dev FS. This is non-incremental - incrementality will be added as follow-on work.\r\n\r\nParsing the graph for flutter_gallery:\r\n\r\n```\r\n452 sources parsed in 684ms.\r\n```\r\n\r\nMaking it incremental will drop later parses to ~ms range, and there's some additional possible optimization w/ only tokenizing the parts of the source file that we need (the directives).\r\n\r\n@bwilkerson for review\r\n\r\n/cc @johnmccutchan @turnidge\r\n\r\n","created_at":"2016-06-13T21:14:52Z","updated_at":"2016-06-13T22:15:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32c71e83e51a3543c9ca5e09fcb3d032e96b3377","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flutter/flutter/pulls/4543/commits","review_comments_url":"https://api.github.com/repos/flutter/flutter/pulls/4543/comments","review_comment_url":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/4543/comments","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/088b76626d67f4df12c63fc23cfa7e0c2f6a4061","head":{"label":"devoncarew:source_graph","ref":"source_graph","sha":"088b76626d67f4df12c63fc23cfa7e0c2f6a4061","user":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"repo":{"id":45596312,"name":"flutter","full_name":"devoncarew/flutter","owner":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/devoncarew/flutter","description":"The Flutter framework","fork":true,"url":"https://api.github.com/repos/devoncarew/flutter","forks_url":"https://api.github.com/repos/devoncarew/flutter/forks","keys_url":"https://api.github.com/repos/devoncarew/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devoncarew/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devoncarew/flutter/teams","hooks_url":"https://api.github.com/repos/devoncarew/flutter/hooks","issue_events_url":"https://api.github.com/repos/devoncarew/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/devoncarew/flutter/events","assignees_url":"https://api.github.com/repos/devoncarew/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/devoncarew/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/devoncarew/flutter/tags","blobs_url":"https://api.github.com/repos/devoncarew/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devoncarew/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devoncarew/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/devoncarew/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devoncarew/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/devoncarew/flutter/languages","stargazers_url":"https://api.github.com/repos/devoncarew/flutter/stargazers","contributors_url":"https://api.github.com/repos/devoncarew/flutter/contributors","subscribers_url":"https://api.github.com/repos/devoncarew/flutter/subscribers","subscription_url":"https://api.github.com/repos/devoncarew/flutter/subscription","commits_url":"https://api.github.com/repos/devoncarew/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/devoncarew/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/devoncarew/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/devoncarew/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/devoncarew/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/devoncarew/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devoncarew/flutter/merges","archive_url":"https://api.github.com/repos/devoncarew/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devoncarew/flutter/downloads","issues_url":"https://api.github.com/repos/devoncarew/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/devoncarew/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/devoncarew/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/devoncarew/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devoncarew/flutter/labels{/name}","releases_url":"https://api.github.com/repos/devoncarew/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/devoncarew/flutter/deployments","created_at":"2015-11-05T07:56:06Z","updated_at":"2016-04-09T14:03:56Z","pushed_at":"2016-06-13T21:07:06Z","git_url":"git://github.com/devoncarew/flutter.git","ssh_url":"git@github.com:devoncarew/flutter.git","clone_url":"https://github.com/devoncarew/flutter.git","svn_url":"https://github.com/devoncarew/flutter","homepage":"http://flutter.io","size":19107,"stargazers_count":0,"watchers_count":0,"language":"Dart","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flutter:master","ref":"master","sha":"2cdda9e6797a973f7fa07650a3ce655321553407","user":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"repo":{"id":31792824,"name":"flutter","full_name":"flutter/flutter","owner":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flutter/flutter","description":"Framework for building high-performance, high-fidelity iOS and Android apps.","fork":false,"url":"https://api.github.com/repos/flutter/flutter","forks_url":"https://api.github.com/repos/flutter/flutter/forks","keys_url":"https://api.github.com/repos/flutter/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flutter/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flutter/flutter/teams","hooks_url":"https://api.github.com/repos/flutter/flutter/hooks","issue_events_url":"https://api.github.com/repos/flutter/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/flutter/flutter/events","assignees_url":"https://api.github.com/repos/flutter/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/flutter/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/flutter/flutter/tags","blobs_url":"https://api.github.com/repos/flutter/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flutter/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flutter/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/flutter/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/flutter/flutter/languages","stargazers_url":"https://api.github.com/repos/flutter/flutter/stargazers","contributors_url":"https://api.github.com/repos/flutter/flutter/contributors","subscribers_url":"https://api.github.com/repos/flutter/flutter/subscribers","subscription_url":"https://api.github.com/repos/flutter/flutter/subscription","commits_url":"https://api.github.com/repos/flutter/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/flutter/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/flutter/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/flutter/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/flutter/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/flutter/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flutter/flutter/merges","archive_url":"https://api.github.com/repos/flutter/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flutter/flutter/downloads","issues_url":"https://api.github.com/repos/flutter/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/flutter/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/flutter/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/flutter/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flutter/flutter/labels{/name}","releases_url":"https://api.github.com/repos/flutter/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/flutter/flutter/deployments","created_at":"2015-03-06T22:54:58Z","updated_at":"2016-06-13T08:29:54Z","pushed_at":"2016-06-13T21:48:24Z","git_url":"git://github.com/flutter/flutter.git","ssh_url":"git@github.com:flutter/flutter.git","clone_url":"https://github.com/flutter/flutter.git","svn_url":"https://github.com/flutter/flutter","homepage":"https://flutter.io","size":113029,"stargazers_count":2840,"watchers_count":2840,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":300,"mirror_url":null,"open_issues_count":1044,"forks":300,"open_issues":1044,"watchers":2840,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/4543"},"html":{"href":"https://github.com/flutter/flutter/pull/4543"},"issue":{"href":"https://api.github.com/repos/flutter/flutter/issues/4543"},"comments":{"href":"https://api.github.com/repos/flutter/flutter/issues/4543/comments"},"review_comments":{"href":"https://api.github.com/repos/flutter/flutter/pulls/4543/comments"},"review_comment":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flutter/flutter/pulls/4543/commits"},"statuses":{"href":"https://api.github.com/repos/flutter/flutter/statuses/088b76626d67f4df12c63fc23cfa7e0c2f6a4061"}}}}
{"actor":{"display_login":"bwilkerson"}}