Skip to content

Commit ef9ecd1

Browse files
authored
Simplify outdated analyzer warnings. Use buildLog instead of log. (#4050)
1 parent 46a3b30 commit ef9ecd1

File tree

6 files changed

+15
-77
lines changed

6 files changed

+15
-77
lines changed

build_resolvers/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 2.5.2-wip
22

3+
- Simplify warnings for outdated `analyzer`.
4+
35
## 2.5.1
46

57
- Use `build_runner_core` 2.5.1.

build_resolvers/lib/src/resolver.dart

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import 'dart:async';
88
import 'dart:collection';
9-
import 'dart:convert';
10-
import 'dart:io';
119
import 'dart:isolate';
1210

1311
import 'package:analyzer/dart/analysis/features.dart';
@@ -26,7 +24,6 @@ import 'package:collection/collection.dart' show IterableExtension;
2624
import 'package:package_config/package_config.dart';
2725
import 'package:path/path.dart' as p;
2826
import 'package:pool/pool.dart';
29-
import 'package:yaml/yaml.dart';
3027

3128
import 'analysis_driver.dart';
3229
import 'analysis_driver_filesystem.dart';
@@ -553,84 +550,21 @@ class AnalyzerResolvers implements Resolvers {
553550
void _warnOnLanguageVersionMismatch() async {
554551
if (sdkLanguageVersion <= ExperimentStatus.currentVersion) return;
555552

556-
HttpClient? client;
557-
try {
558-
client = HttpClient();
559-
var request = await client.getUrl(
560-
Uri.https('pub.dartlang.org', 'api/packages/analyzer'),
561-
);
562-
var response = await request.close();
563-
var content = StringBuffer();
564-
await response
565-
.transform(utf8.decoder)
566-
.listen(content.write)
567-
.asFuture<void>();
568-
var json = jsonDecode(content.toString()) as Map<String, Object?>;
569-
var latestAnalyzer = (json['latest'] as Map<String, Object?>)['version'];
570-
var analyzerPubspecPath = p.join(
571-
await packagePath('analyzer'),
572-
'pubspec.yaml',
573-
);
574-
var currentAnalyzer =
575-
(loadYaml(await File(analyzerPubspecPath).readAsString())
576-
as YamlMap)['version'];
577-
578-
if (latestAnalyzer == currentAnalyzer) {
579-
log.warning('''
580-
The latest `analyzer` version may not fully support your current SDK version.
581-
582-
Analyzer language version: ${ExperimentStatus.currentVersion}
583-
SDK language version: $sdkLanguageVersion
584-
585-
Check for an open issue at:
586-
https://github.com/dart-lang/sdk/issues?q=is%3Aissue+is%3Aopen+No+published+analyzer+$sdkLanguageVersion
587-
and thumbs up and/or subscribe to the existing issue, or file a new issue at
588-
https://github.com/dart-lang/sdk/issues/new with the title
589-
"No published analyzer available for language version $sdkLanguageVersion".
590-
''');
591-
} else {
592-
var upgradeCommand =
593-
isFlutter ? 'flutter packages upgrade' : 'dart pub upgrade';
594-
log.warning('''
595-
Your current `analyzer` version may not fully support your current SDK version.
596-
597-
Analyzer language version: ${ExperimentStatus.currentVersion}
598-
SDK language version: $sdkLanguageVersion
599-
600-
Please update to the latest `analyzer` version ($latestAnalyzer) by running
601-
`$upgradeCommand`.
602-
603-
If you are not getting the latest version by running the above command, you
604-
can try adding a constraint like the following to your pubspec to start
605-
diagnosing why you can't get the latest version:
606-
607-
dev_dependencies:
608-
analyzer: ^$latestAnalyzer
609-
''');
610-
}
611-
} catch (_) {
612-
// Fall back on a basic message if we fail to detect the latest version for
613-
// any reason.
614-
log.warning('''
615-
Your current `analyzer` version may not fully support your current SDK version.
616-
617-
Analyzer language version: ${ExperimentStatus.currentVersion}
618-
SDK language version: $sdkLanguageVersion
619-
620-
Please ensure you are on the latest `analyzer` version, which can be seen at
621-
https://pub.dev/packages/analyzer.
622-
''');
623-
} finally {
624-
client?.close();
625-
}
553+
final upgradeCommand =
554+
isFlutter ? 'flutter packages upgrade' : 'dart pub upgrade';
555+
buildLog.warning(
556+
'SDK language version $sdkLanguageVersion is newer than `analyzer` '
557+
'language version ${ExperimentStatus.currentVersion}. '
558+
'Run `$upgradeCommand`.',
559+
);
626560
}
627561

628562
/// The current feature set based on the current sdk version and enabled
629563
/// experiments.
630564
FeatureSet _featureSet({List<String> enableExperiments = const []}) {
631565
if (enableExperiments.isNotEmpty &&
632566
sdkLanguageVersion > ExperimentStatus.currentVersion) {
633-
log.warning('''
567+
buildLog.warning('''
634568
Attempting to enable experiments `$enableExperiments`, but the current SDK
635569
language version does not match your `analyzer` package language version:
636570

build_resolvers/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ dependencies:
2222
pool: ^1.5.0
2323
pub_semver: ^2.0.0
2424
stream_transform: ^2.0.0
25-
yaml: ^3.0.0
2625

2726
dev_dependencies:
2827
build_test: ^3.0.0

build_runner/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 2.5.2-wip
22

3+
- Simplify warnings for outdated `analyzer`.
4+
35
## 2.5.1
46

57
- Don't log stack traces for subclasses of `Exception`.

build_runner_core/lib/src/generate/build_definition.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class _Loader {
157157
.where(inputSources.contains)
158158
.toSet();
159159
if (conflictsInDeps.isNotEmpty) {
160-
log.severe(
160+
buildLog.error(
161161
'There are existing files in dependencies which conflict '
162162
'with files that a Builder may produce. These must be removed or '
163163
'the Builders disabled before a build can continue: '

build_runner_core/lib/src/package_graph/target_graph.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:glob/glob.dart';
1010

1111
import '../generate/input_matcher.dart';
1212
import '../generate/options.dart' show defaultNonRootVisibleAssets;
13+
import '../logging/build_log.dart';
1314
import 'package_graph.dart';
1415

1516
/// Like a [PackageGraph] but packages are further broken down into modules
@@ -105,7 +106,7 @@ class TargetGraph {
105106
);
106107
var missing = _missingSources(nodes, requiredIds);
107108
if (missing.isNotEmpty) {
108-
log.warning(
109+
buildLog.warning(
109110
'The package `${package.name}` does not include some required '
110111
'sources in any of its targets (see their build.yaml file).\n'
111112
'The missing sources are:\n'

0 commit comments

Comments
 (0)