|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'dart:io' as io; |
| 6 | + |
5 | 7 | import 'package:file/file.dart';
|
6 | 8 | import 'package:yaml/yaml.dart';
|
7 | 9 |
|
@@ -34,12 +36,18 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
34 | 36 | argParser.addFlag(_libOnlyFlag,
|
35 | 37 | help: 'Only analyze the lib/ directory of the main package, not the '
|
36 | 38 | 'entire package.');
|
| 39 | + argParser.addFlag(_skipIfResolvingFailsFlag, |
| 40 | + help: 'If resolution fails, skip the package. This is only ' |
| 41 | + 'intended to be used with pathified analysis, where a resolver ' |
| 42 | + 'failure indicates that no out-of-band failure can result anyway.', |
| 43 | + hide: true); |
37 | 44 | }
|
38 | 45 |
|
39 | 46 | static const String _customAnalysisFlag = 'custom-analysis';
|
40 | 47 | static const String _downgradeFlag = 'downgrade';
|
41 | 48 | static const String _libOnlyFlag = 'lib-only';
|
42 | 49 | static const String _analysisSdk = 'analysis-sdk';
|
| 50 | + static const String _skipIfResolvingFailsFlag = 'skip-if-resolving-fails'; |
43 | 51 |
|
44 | 52 | late String _dartBinaryPath;
|
45 | 53 |
|
@@ -134,6 +142,20 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
134 | 142 | .pubspecFile
|
135 | 143 | .existsSync()) {
|
136 | 144 | if (!await _runPubCommand(packageToGet, 'get')) {
|
| 145 | + if (getBoolArg(_skipIfResolvingFailsFlag)) { |
| 146 | + // Re-run, capturing output, to see if the failure was a resolver |
| 147 | + // failure. (This is slightly inefficient, but this should be a |
| 148 | + // very rare case.) |
| 149 | + const String resolverFailureMessage = 'version solving failed'; |
| 150 | + final io.ProcessResult result = await processRunner.run( |
| 151 | + flutterCommand, <String>['pub', 'get'], |
| 152 | + workingDir: packageToGet.directory); |
| 153 | + if ((result.stderr as String).contains(resolverFailureMessage) || |
| 154 | + (result.stdout as String).contains(resolverFailureMessage)) { |
| 155 | + logWarning('Skipping package due to pub resolution failure.'); |
| 156 | + return PackageResult.skip('Resolution failed.'); |
| 157 | + } |
| 158 | + } |
137 | 159 | return PackageResult.fail(<String>['Unable to get dependencies']);
|
138 | 160 | }
|
139 | 161 | }
|
|
0 commit comments