Include or remove stray pubspec.yaml files.

There were `pubspec.yaml` files in `tools/` that were not
included in the global package config.
That means that their imports were irrelevant, which could
be misleading. And if any tool would look at the
`pubspec.yaml` file, it might be inconsistent with
the actual package resolution.

Makes every `pubspec.yaml` file either be included by the
`tools/generate_package_config.dart` script, or deletes them
if they seem to be stale and unused.
(Compare vs. `git ls-files '**/pubspec.yaml'`.)

Excepted `tools/dart2js/sourceMapViewer/pubspec.yaml`.
The entire directory might be stale. The dependencies of
that pubspec are not SDK dependencies otherwise,
the pubspec has no SDK min-version, which is now a requirement,
and the README refers to a *packages directory*.
Keeping as-is and filing issue to have owners take a look.

Added `lib/` directory to `tools/` to avoid `tools/bots/`
being inside the package URI root of the `tools/` package,
which would cause its `../../pkg/...` import to fail.

Makes every `pubspec.yaml` file use a `^...` SDK constraint instead
of the longer `>= ... < ...` format.

Tested: No new tests, goal is to keep running the same way
Change-Id: I688e463fe985fc4de43550a1f4c7ff350536cffc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414020
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Lasse R.H. Nielsen
2025-03-31 08:30:33 -07:00
committed by Commit Queue
parent 93df675c5e
commit a824ee3206
12 changed files with 78 additions and 60 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ name: dev_compiler
publish_to: none
environment:
sdk: '>=3.6.0 <4.0.0'
sdk: ^3.6.0
resolution: workspace
+1 -1
View File
@@ -5,7 +5,7 @@ description: >
Small framework for testing hot reload and hot restart across Dart backends.
environment:
sdk: '>=3.6.0 <4.0.0'
sdk: ^3.6.0
resolution: workspace
+1 -1
View File
@@ -4,7 +4,7 @@ description: VM specific Dart code and helper scripts
publish_to: none
environment:
sdk: '>=3.7.0 <4.0.0'
sdk: ^3.7.0
resolution: workspace
+4 -2
View File
@@ -6,7 +6,7 @@
name: _
publish_to: none
environment:
# This constraint decides the langage-version for all dart code in the
# This constraint decides the language-version for all dart code in the
# repository that doesn't have its own package. Mainly the code in `tests/`.
#
# It needs to be updated before testing language features introduced in the
@@ -77,12 +77,14 @@ workspace:
- pkg/vm_service_protos
- pkg/vm_snapshot_analysis
- pkg/wasm_builder
- runtime/tools/profiling
- samples/ffi/http
# dap and language_server_protocol are checked in to and
# developed in the sdk repo, though they are located in `third_party/`.
# developed in the SDK repo, though they are located in `third_party/`.
- third_party/pkg/dap
- third_party/pkg/language_server_protocol
- tools/package_deps
- tools/verify_docs
- tools
# All third_party packages here are retrieved via the DEPS-file and overridden
+1 -1
View File
@@ -1,7 +1,7 @@
name: observatory
environment:
sdk: '>=2.19.0 <3.0.0'
sdk: ^2.19.0
# dependencies:
@@ -1,4 +1,4 @@
name: observatory_test_package
publish_to: none
environment:
sdk: '>=2.19.0 <3.0.0'
sdk: ^2.19.0
+3 -1
View File
@@ -4,7 +4,9 @@ version: 0.1.0
publish_to: none
environment:
sdk: '>=3.6.0 <4.0.0'
sdk: ^3.6.0
resolution: workspace
dependencies:
protobuf: ^3.1.0
+1
View File
@@ -3,6 +3,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore: implementation_imports
import 'package:bisect_dart/src/run_bisection.dart';
Future<void> main(List<String> args) async {
+11 -12
View File
@@ -12,7 +12,7 @@ import 'dart:io';
final repoRoot = File(Platform.script.toFilePath()).parent.parent.uri;
void main(List<String> args) {
void main() {
final fluteExists =
Directory.fromUri(repoRoot.resolve('third_party/flute')).existsSync();
final overridesFile = File.fromUri(
@@ -24,9 +24,9 @@ void main(List<String> args) {
final pubspec =
File.fromUri(repoRoot.resolve('pubspec.yaml')).readAsStringSync();
final overrides = RegExp(
'dependency_overrides:\n([\\S\\s]*?)^\$',
r'^dependency_overrides:\n([^]*?)^$',
multiLine: true,
).firstMatch(pubspec)![1];
).firstMatch(pubspec)![1]!;
overridesFile.writeAsStringSync('''
# Created by tools/generate_package_config.dart to support flute.
@@ -48,9 +48,7 @@ $overrides
} else {
// Delete the overrides file if it exists.
if (overridesFile.existsSync()) {
File.fromUri(
repoRoot.resolve('pubspec_overrides.yaml'),
).deleteSync(recursive: true);
overridesFile.deleteSync();
}
}
@@ -59,7 +57,7 @@ $overrides
Platform.resolvedExecutable,
['pub', 'get'],
workingDirectory: repoRoot.toFilePath(),
environment: {}, // Prevent overriding eg. PUB_CACHE
environment: {}, // Prevent overriding, e.g., PUB_CACHE
);
if (result.exitCode != 0) {
print('`pub get` failed');
@@ -71,21 +69,22 @@ $overrides
File.fromUri(
repoRoot.resolve('.dart_tool/package_config.json'),
).readAsStringSync(),
);
) as Map<String, Object?>;
if (!fluteExists) {
for (final package in packageConfig['packages']) {
final rootUri = package['rootUri'];
final packages = packageConfig['packages'] as List<Object?>;
for (final (package as Map<String, Object?>) in packages) {
final rootUri = package['rootUri'] as String;
if (!(rootUri.startsWith('../third_party/') || // Third-party package
rootUri.startsWith('../pkg/') || // SDK package
rootUri.startsWith('../samples/') || // sample package
rootUri.startsWith('../runtime/') || // VM package
rootUri.startsWith(
'../tools',
) || // A tool package for developing the sdk.
) || // A tool package for developing the SDK.
rootUri == '../' // The main workspace package
)) {
print('Package ${package['name']} is imported from outside the sdk.');
print('Package ${package['name']} is imported from outside the SDK.');
print('It has rootUri $rootUri.');
print(
'See https://github.com/dart-lang/sdk/blob/main/docs/Adding-and-Updating-Dependencies.md',
+3
View File
@@ -0,0 +1,3 @@
A lib/ directory for the synthetic package introduced by ../pubspec.yaml.
Avoids files in nested packages, like ../verify_docs/, having package: URIS
in the parent directory package.
+48 -39
View File
@@ -7,7 +7,7 @@
import 'dart:collection';
import 'dart:io';
import 'package:_fe_analyzer_shared/src/sdk/allowed_experiments.dart';
import 'package:_fe_analyzer_shared/src/sdk/allowed_experiments.dart'; // ignore: implementation_imports
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
@@ -19,9 +19,9 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/overlay_file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/util/comment.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart'; // ignore: implementation_imports
import 'package:analyzer/src/error/codes.dart'; // ignore: implementation_imports
import 'package:analyzer/src/util/comment.dart'; // ignore: implementation_imports
import 'package:path/path.dart' as path;
final libDir = Directory(path.join('sdk', 'lib'));
@@ -35,8 +35,10 @@ void main(List<String> args) async {
print('');
print('To run this tool, run `dart tools/verify_docs/bin/verify_docs.dart`.');
print('');
print('For documentation about how to author dart: code samples,'
' see tools/verify_docs/README.md.');
print(
'For documentation about how to author dart: code samples,'
' see tools/verify_docs/README.md.',
);
print('');
final coreLibraries = args.isEmpty
@@ -52,7 +54,7 @@ void main(List<String> args) async {
'vmservice',
'web_audio',
'web_gl',
'web_sql'
'web_sql',
};
coreLibraries.removeWhere(
(lib) => skipLibraries.contains(path.basename(lib.path)),
@@ -87,8 +89,9 @@ Future<bool> validateLibrary(Directory dir) async {
}
final Future<AllowedExperiments> allowedExperiments = () async {
final allowedExperimentsFile =
File('sdk/lib/_internal/allowed_experiments.json');
final allowedExperimentsFile = File(
'sdk/lib/_internal/allowed_experiments.json',
);
final contents = await allowedExperimentsFile.readAsString();
return parseAllowedExperiments(contents);
}();
@@ -187,7 +190,10 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
while (offset != -1) {
// Collect template directives, like "```dart import:async".
final codeFenceSuffix = text
.substring(offset + sampleStart.length, text.indexOf('\n', offset))
.substring(
offset + sampleStart.length,
text.indexOf('\n', offset),
)
.trim();
offset = text.indexOf('\n', offset) + 1;
@@ -236,11 +242,13 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
// 1/libdecl: Non-null if matching a `library` declaration.
// 2: Internal use, quote around import URI.
// 3/importuri: Import URI.
final _toplevelDeclarationRE = RegExp(r'^\s*(?:'
r'library\b(?<libdecl>)|'
r'''import (['"])(?<importuri>.*?)\2|'''
r'final class\b|class\b|mixin\b|enum\b|extension\b|typedef\b|.*\bmain\('
r')');
final _toplevelDeclarationRE = RegExp(
r'^\s*(?:'
r'library\b(?<libdecl>)|'
r'''import (['"])(?<importuri>.*?)\2|'''
r'final class\b|class\b|mixin\b|enum\b|extension\b|typedef\b|.*\bmain\('
r')',
);
Future<void> validateCodeSample(CodeSample sample) async {
final lines = sample.lines;
@@ -323,22 +331,17 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
final result = await analysisHelper.resolveFile(text);
if (result is ResolvedUnitResult) {
var errors = SplayTreeSet<AnalysisError>.from(
result.errors,
(a, b) {
var value = a.offset.compareTo(b.offset);
if (value == 0) {
value = a.message.compareTo(b.message);
}
return value;
},
);
var errors = SplayTreeSet<AnalysisError>.from(result.errors, (a, b) {
var value = a.offset.compareTo(b.offset);
if (value == 0) {
value = a.message.compareTo(b.message);
}
return value;
});
// Filter out unused imports, since we speculatively add imports to some
// samples.
errors.removeWhere(
(e) => e.errorCode == WarningCode.UNUSED_IMPORT,
);
errors.removeWhere((e) => e.errorCode == WarningCode.UNUSED_IMPORT);
// Also, don't worry about 'unused_local_variable' and related; this may
// be intentional in samples.
@@ -372,10 +375,14 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
print('');
// Print out the code sample.
print(sample.lines
.map((line) =>
' >${line.length >= 5 ? line.substring(5) : line.trimLeft()}')
.join('\n'));
print(
sample.lines
.map(
(line) =>
' >${line.length >= 5 ? line.substring(5) : line.trimLeft()}',
)
.join('\n'),
);
print('');
}
} else {
@@ -437,7 +444,7 @@ class CodeSample {
if (coreLibName != 'internal' && coreLibName != 'core') coreLibName,
for (var directive in directives)
if (directive.startsWith('import:'))
directive.substring('import:'.length)
directive.substring('import:'.length),
};
/// Creates a new code sample by appending [lines] to this sample.
@@ -448,10 +455,11 @@ class CodeSample {
CodeSample append(List<String> lines, int lineStartOffset) {
var gapSize = lineStartOffset - (this.lineStartOffset + this.lines.length);
return CodeSample(
[...this.lines, for (var i = 0; i < gapSize; i++) " //", ...lines],
coreLibName: coreLibName,
directives: directives,
lineStartOffset: this.lineStartOffset);
[...this.lines, for (var i = 0; i < gapSize; i++) " //", ...lines],
coreLibName: coreLibName,
directives: directives,
lineStartOffset: this.lineStartOffset,
);
}
}
@@ -486,8 +494,9 @@ String _severity(Severity severity) {
class AnalysisHelper {
final String libraryName;
final resourceProvider =
OverlayResourceProvider(PhysicalResourceProvider.INSTANCE);
final resourceProvider = OverlayResourceProvider(
PhysicalResourceProvider.INSTANCE,
);
late final String separator = resourceProvider.pathContext.separator;
late final pathRoot = Directory('sdk${separator}lib$separator').absolute.path;
late AnalysisContextCollection collection;
+3 -1
View File
@@ -5,7 +5,9 @@ description: A tool to validate the documentation comments for the `dart:` libra
publish_to: none
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: ^3.5.0
resolution: workspace
dependencies:
_fe_analyzer_shared: any