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

Side by Side Diff: pkg/analyzer/lib/source/pub_package_map_provider.dart

Issue 1470793002: Don't run 'pub list-package-dirs' if there is no pubpsec.lock file. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library source.pub_package_map_provider; 5 library source.pub_package_map_provider;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:core' hide Resource; 9 import 'dart:core' hide Resource;
10 import 'dart:io' as io; 10 import 'dart:io' as io;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 * A [RunPubList] implementation may be injected for testing 52 * A [RunPubList] implementation may be injected for testing
53 */ 53 */
54 PubPackageMapProvider(this.resourceProvider, this.sdk, [this._runPubList]) { 54 PubPackageMapProvider(this.resourceProvider, this.sdk, [this._runPubList]) {
55 if (_runPubList == null) { 55 if (_runPubList == null) {
56 _runPubList = _runPubListDefault; 56 _runPubList = _runPubListDefault;
57 } 57 }
58 } 58 }
59 59
60 @override 60 @override
61 PackageMapInfo computePackageMap(Folder folder) { 61 PackageMapInfo computePackageMap(Folder folder) {
62 // If the pubspec.lock file does not exist, no need to run anything.
63 {
64 String lockPath = getPubspecLockPath(folder);
65 if (!resourceProvider.getFile(lockPath).exists) {
66 return computePackageMapError(folder);
67 }
68 }
62 // TODO(paulberry) make this asynchronous so that we can (a) do other 69 // TODO(paulberry) make this asynchronous so that we can (a) do other
63 // analysis while it's in progress, and (b) time out if it takes too long 70 // analysis while it's in progress, and (b) time out if it takes too long
64 // to respond. 71 // to respond.
65 io.ProcessResult result; 72 io.ProcessResult result;
66 try { 73 try {
67 result = _runPubList(folder); 74 result = _runPubList(folder);
68 } on io.ProcessException catch (exception, stackTrace) { 75 } on io.ProcessException catch (exception, stackTrace) {
69 AnalysisEngine.instance.logger.logInformation( 76 AnalysisEngine.instance.logger.logInformation(
70 "Error running pub $PUB_LIST_COMMAND\n$exception\n$stackTrace"); 77 "Error running pub $PUB_LIST_COMMAND\n$exception\n$stackTrace");
71 } 78 }
(...skipping 17 matching lines...) Expand all
89 } 96 }
90 97
91 /** 98 /**
92 * Create a PackageMapInfo object representing an error condition. 99 * Create a PackageMapInfo object representing an error condition.
93 */ 100 */
94 PackageMapInfo computePackageMapError(Folder folder) { 101 PackageMapInfo computePackageMapError(Folder folder) {
95 // Even if an error occurs, we still need to know the dependencies, so that 102 // Even if an error occurs, we still need to know the dependencies, so that
96 // we'll know when to try running "pub list-package-dirs" again. 103 // we'll know when to try running "pub list-package-dirs" again.
97 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when 104 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when
98 // an error occurs, so just assume there is one dependency, "pubspec.lock". 105 // an error occurs, so just assume there is one dependency, "pubspec.lock".
99 List<String> dependencies = <String>[ 106 String lockPath = getPubspecLockPath(folder);
100 resourceProvider.pathContext.join(folder.path, PUBSPEC_LOCK_NAME) 107 List<String> dependencies = <String>[lockPath];
101 ];
102 return new PackageMapInfo(null, dependencies.toSet()); 108 return new PackageMapInfo(null, dependencies.toSet());
103 } 109 }
104 110
105 /** 111 /**
112 * Return the path to the `pubspec.lock` file in the given [folder].
113 */
114 String getPubspecLockPath(Folder folder) =>
115 resourceProvider.pathContext.join(folder.path, PUBSPEC_LOCK_NAME);
116
117 /**
106 * Decode the JSON output from pub into a package map. Paths in the 118 * Decode the JSON output from pub into a package map. Paths in the
107 * output are considered relative to [folder]. 119 * output are considered relative to [folder].
108 */ 120 */
109 PackageMapInfo parsePackageMap(Map obj, Folder folder) { 121 PackageMapInfo parsePackageMap(Map obj, Folder folder) {
110 // The output of pub looks like this: 122 // The output of pub looks like this:
111 // { 123 // {
112 // "packages": { 124 // "packages": {
113 // "foo": "path/to/foo", 125 // "foo": "path/to/foo",
114 // "bar": ["path/to/bar1", "path/to/bar2"], 126 // "bar": ["path/to/bar1", "path/to/bar2"],
115 // "myapp": "path/to/myapp", // self link is included 127 // "myapp": "path/to/myapp", // self link is included
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 String workingDirectory = folder.path; 174 String workingDirectory = folder.path;
163 int subprocessId = AnalysisEngine.instance.instrumentationService 175 int subprocessId = AnalysisEngine.instance.instrumentationService
164 .logSubprocessStart(executablePath, arguments, workingDirectory); 176 .logSubprocessStart(executablePath, arguments, workingDirectory);
165 io.ProcessResult result = io.Process 177 io.ProcessResult result = io.Process
166 .runSync(executablePath, arguments, workingDirectory: workingDirectory); 178 .runSync(executablePath, arguments, workingDirectory: workingDirectory);
167 AnalysisEngine.instance.instrumentationService.logSubprocessResult( 179 AnalysisEngine.instance.instrumentationService.logSubprocessResult(
168 subprocessId, result.exitCode, result.stdout, result.stderr); 180 subprocessId, result.exitCode, result.stdout, result.stderr);
169 return result; 181 return result;
170 } 182 }
171 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698