Skip to content

Commit 9b157b6

Browse files
jensjohaCommit Queue
authored andcommitted
Format {_fe_analyzer_shared,front_end,kernel}/lib; update generated files to match package version
For the generated files (e.g. codes) we had gotten into a scenario where the auto generated files was forced to be formatted as short style, but if asking the dart formatter to format the _fe_analyzer_shared file it would be formatted in long style because the minimum version for _fe_analyzer_shared is now 3.7. This CL updates the generators for the generated files to pass the language version from the package config to the formatter. Change-Id: I986ce1b5ff65244499ab5a277e78124f372ee46d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444300 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 5c5ecda commit 9b157b6

17 files changed

+2784
-3220
lines changed

pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart

Lines changed: 241 additions & 202 deletions
Large diffs are not rendered by default.

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 2481 additions & 2980 deletions
Large diffs are not rendered by default.

pkg/front_end/lib/src/api_prototype/kernel_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Future<CompilerResult?> kernelForProgramInternal(
7272
if (component == null) return null;
7373

7474
if (requireMain && component.mainMethod == null) {
75-
context.options.report(context,
75+
context.options.report(
76+
context,
7677
codeMissingMain.withLocation(source, -1, noLength),
7778
CfeSeverity.error);
7879
return null;

pkg/front_end/lib/src/api_unstable/dart2js.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ Future<Component?> compile(
164164
Component? component = compilerResult.component;
165165
if (component == null) return null;
166166
if (component.mainMethod == null) {
167-
context.options.report(context,
167+
context.options.report(
168+
context,
168169
codeMissingMain.withLocation(inputs.single, -1, 0),
169170
CfeSeverity.error);
170171
return null;

pkg/front_end/lib/src/base/processed_options.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ class ProcessedOptions {
711711
CfeSeverity.error);
712712
} catch (e) {
713713
// Coverage-ignore-block(suite): Not run.
714-
reportWithoutLocation(
715-
codeCantReadFile.withArguments(requestedUri, "$e"),
714+
reportWithoutLocation(codeCantReadFile.withArguments(requestedUri, "$e"),
716715
CfeSeverity.error);
717716
}
718717
// Coverage-ignore(suite): Not run.

pkg/front_end/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ dev_dependencies:
3232
expect: any
3333
json_rpc_2: any
3434
path: any
35+
pub_semver: any
3536
test_reflective_loader: any
3637
test: any
3738
testing: any
38-
vm: any
3939
vm_service: any
40+
vm: any
4041
web_socket_channel: any

pkg/front_end/test/parser_test_listener_creator.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:_fe_analyzer_shared/src/scanner/token.dart';
1010
import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart';
1111
import 'package:dart_style/dart_style.dart' show DartFormatter;
1212

13-
import 'utils/io_utils.dart' show computeRepoDirUri;
13+
import 'utils/io_utils.dart' show computeRepoDirUri, getPackageVersionFor;
1414

1515
void main(List<String> args) {
1616
final Uri repoDir = computeRepoDirUri();
@@ -111,8 +111,7 @@ class ParserTestListener implements Listener {
111111

112112
out.writeln("}");
113113

114-
return new DartFormatter(
115-
languageVersion: DartFormatter.latestShortStyleLanguageVersion)
114+
return new DartFormatter(languageVersion: getPackageVersionFor("front_end"))
116115
.format("$out");
117116
}
118117

pkg/front_end/test/parser_test_parser_creator.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:_fe_analyzer_shared/src/scanner/token.dart';
1010
import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart';
1111
import 'package:dart_style/dart_style.dart' show DartFormatter;
1212

13-
import 'utils/io_utils.dart' show computeRepoDirUri;
13+
import 'utils/io_utils.dart' show computeRepoDirUri, getPackageVersionFor;
1414

1515
void main(List<String> args) {
1616
final Uri repoDir = computeRepoDirUri();
@@ -114,8 +114,7 @@ class TestParser extends Parser {
114114

115115
out.writeln("}");
116116

117-
return new DartFormatter(
118-
languageVersion: DartFormatter.latestShortStyleLanguageVersion)
117+
return new DartFormatter(languageVersion: getPackageVersionFor("front_end"))
119118
.format("$out");
120119
}
121120

pkg/front_end/test/utils/io_utils.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import 'dart:io' show Directory, File, Platform, Process, ProcessResult;
66

77
import 'package:_fe_analyzer_shared/src/util/filenames.dart';
8+
import 'package:package_config/package_config.dart'
9+
show PackageConfig, Package, LanguageVersion;
10+
import 'package:pub_semver/pub_semver.dart' show Version;
811

912
String computeRepoDir() {
1013
Uri uri;
@@ -56,3 +59,26 @@ Uri computeRepoDirUri() {
5659
String dirPath = computeRepoDir();
5760
return new Directory(dirPath).uri;
5861
}
62+
63+
Package? getPackageFor(String name) {
64+
Uri packageConfigUri =
65+
computeRepoDirUri().resolve(".dart_tool/package_config.json");
66+
PackageConfig packageConfig = PackageConfig.parseBytes(
67+
new File.fromUri(packageConfigUri).readAsBytesSync(), packageConfigUri);
68+
for (Package package in packageConfig.packages) {
69+
if (package.name == name) {
70+
return package;
71+
}
72+
}
73+
return null;
74+
}
75+
76+
Version getPackageVersionFor(String name) {
77+
Package? package = getPackageFor(name);
78+
if (package == null) throw "Didn't find '$name' as a package.";
79+
LanguageVersion? languageVersion = package.languageVersion;
80+
if (languageVersion == null) {
81+
throw "'$name' does not have a language version.";
82+
}
83+
return new Version(languageVersion.major, languageVersion.minor, 0);
84+
}

pkg/front_end/tool/generate_experimental_flags.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import 'package:_fe_analyzer_shared/src/sdk/allowed_experiments.dart';
1010
import 'package:dart_style/dart_style.dart' show DartFormatter;
1111
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
1212

13-
import '../test/utils/io_utils.dart' show computeRepoDirUri;
13+
import '../test/utils/io_utils.dart'
14+
show computeRepoDirUri, getPackageVersionFor;
1415

1516
void main(List<String> arguments) {
1617
final Uri repoDir = computeRepoDirUri();
@@ -180,7 +181,7 @@ class Version {
180181
''');
181182

182183
return new DartFormatter(
183-
languageVersion: DartFormatter.latestShortStyleLanguageVersion)
184+
languageVersion: getPackageVersionFor("_fe_analyzer_shared"))
184185
.format("$sb");
185186
}
186187

@@ -215,8 +216,7 @@ import "ast.dart";
215216
const Version defaultLanguageVersion = const Version($currentVersionMajor, $currentVersionMinor);
216217
''');
217218

218-
return new DartFormatter(
219-
languageVersion: DartFormatter.latestShortStyleLanguageVersion)
219+
return new DartFormatter(languageVersion: getPackageVersionFor("kernel"))
220220
.format("$sb");
221221
}
222222

@@ -530,8 +530,7 @@ const AllowedExperimentalFlags defaultAllowedExperimentalFlags =
530530
};
531531
''');
532532

533-
return new DartFormatter(
534-
languageVersion: DartFormatter.latestShortStyleLanguageVersion)
533+
return new DartFormatter(languageVersion: getPackageVersionFor("front_end"))
535534
.format("$sb");
536535
}
537536

0 commit comments

Comments
 (0)