Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions script/configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ Expected format:
# Reason for exclusion
- name_of_package
```

If there are no exclusions there should be an file with [].
Copy link
Member Author

@loic-sharma loic-sharma Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary as the --exclude arg now handles the null case. Please let me know if you prefer it as it was before, I can undo these changes.

2 changes: 0 additions & 2 deletions script/configs/dart_unit_tests_wasm_exceptions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@
#
# This is only used for the rare case where a package fails in Wasm, but works
# in JS mode.

[] # Needed so the contents of this file are an empty array, not `null`!
2 changes: 0 additions & 2 deletions script/configs/exclude_all_packages_app_wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
#
# This is only used for the rare case where a package fails in Wasm, but works
# in JS mode.

[] # Needed so the contents of this file are an empty array, not `null`!
2 changes: 0 additions & 2 deletions script/configs/exclude_integration_web_wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
#
# This is only used for the rare case where a package fails in Wasm, but works
# in JS mode.

[] # Needed so the contents of this file are an empty array, not `null`!
18 changes: 3 additions & 15 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:yaml/yaml.dart';

import 'common/output_utils.dart';
import 'common/package_looping_command.dart';
Expand Down Expand Up @@ -64,7 +63,7 @@ class AnalyzeCommand extends PackageLoopingCommand {
final bool hasLongOutput = false;

/// Checks that there are no unexpected analysis_options.yaml files.
bool _hasUnexpecetdAnalysisOptions(RepositoryPackage package) {
bool _hasUnexpectedAnalysisOptions(RepositoryPackage package) {
final List<FileSystemEntity> files =
package.directory.listSync(recursive: true, followLinks: false);
for (final FileSystemEntity file in files) {
Expand Down Expand Up @@ -94,18 +93,7 @@ class AnalyzeCommand extends PackageLoopingCommand {

@override
Future<void> initializeRun() async {
_allowedCustomAnalysisDirectories =
getStringListArg(_customAnalysisFlag).expand<String>((String item) {
if (item.endsWith('.yaml')) {
final File file = packagesDir.fileSystem.file(item);
final Object? yaml = loadYaml(file.readAsStringSync());
if (yaml == null) {
return <String>[];
}
return (yaml as YamlList).toList().cast<String>();
}
return <String>[item];
}).toSet();
_allowedCustomAnalysisDirectories = getYamlListArg(_customAnalysisFlag);

// Use the Dart SDK override if one was passed in.
final String? dartSdk = argResults![_analysisSdk] as String?;
Expand Down Expand Up @@ -161,7 +149,7 @@ class AnalyzeCommand extends PackageLoopingCommand {
}
}

if (_hasUnexpecetdAnalysisOptions(package)) {
if (_hasUnexpectedAnalysisOptions(package)) {
return PackageResult.fail(<String>['Unexpected local analysis options']);
}
final int exitCode = await processRunner.runAndStream(_dartBinaryPath,
Expand Down
42 changes: 21 additions & 21 deletions script/tool/lib/src/common/package_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class PackageCommand extends Command<void> {
argParser.addMultiOption(
_excludeArg,
abbr: 'e',
help: 'A list of packages to exclude from from this command.\n\n'
help: 'A list of packages to exclude from this command.\n\n'
'Alternately, a list of one or more YAML files that contain a list '
'of packages to exclude.',
defaultsTo: <String>[],
Expand Down Expand Up @@ -252,6 +252,22 @@ abstract class PackageCommand extends Command<void> {
return List<String>.from(argResults![key] as List<String>? ?? <String>[]);
}

/// Convenience accessor for arguments containing a list of strings and/or
/// YAML files containing lists of strings.
Set<String> getYamlListArg(String key) {
return getStringListArg(key).expand<String>((String item) {
if (item.endsWith('.yaml')) {
final File file = packagesDir.fileSystem.file(item);
final Object? yaml = loadYaml(file.readAsStringSync());
if (yaml == null) {
return const <String>[];
}
return (yaml as YamlList).toList().cast<String>();
}
return <String>[item];
}).toSet();
}

/// If true, commands should log timing information that might be useful in
/// analyzing their runtime (e.g., the per-package time for multi-package
/// commands).
Expand All @@ -277,25 +293,10 @@ abstract class PackageCommand extends Command<void> {
_shardCount = shardCount;
}

/// Converts a list of items which are either package names or yaml files
/// containing a list of package names to a flat list of package names by
/// reading all the file contents.
Set<String> _expandYamlInPackageList(List<String> items) {
return items.expand<String>((String item) {
if (item.endsWith('.yaml')) {
final File file = packagesDir.fileSystem.file(item);
return (loadYaml(file.readAsStringSync()) as YamlList)
.toList()
.cast<String>();
}
return <String>[item];
}).toSet();
}

/// Returns the set of packages to exclude based on the `--exclude` argument.
Set<String> getExcludedPackageNames() {
final Set<String> excludedPackages = _excludedPackages ??
_expandYamlInPackageList(getStringListArg(_excludeArg));
final Set<String> excludedPackages =
_excludedPackages ?? getYamlListArg(_excludeArg);
// Cache for future calls.
_excludedPackages = excludedPackages;
return excludedPackages;
Expand Down Expand Up @@ -460,9 +461,8 @@ abstract class PackageCommand extends Command<void> {

final Set<String> excludedPackageNames = getExcludedPackageNames();
final bool hasFilter = argResults?.wasParsed(_filterPackagesArg) ?? false;
final Set<String>? excludeAllButPackageNames = hasFilter
? _expandYamlInPackageList(getStringListArg(_filterPackagesArg))
: null;
final Set<String>? excludeAllButPackageNames =
hasFilter ? getYamlListArg(_filterPackagesArg) : null;
if (excludeAllButPackageNames != null &&
excludeAllButPackageNames.isNotEmpty) {
final List<String> sortedList = excludeAllButPackageNames.toList()
Expand Down
20 changes: 2 additions & 18 deletions script/tool/lib/src/pubspec_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
}
}
// Load explicitly allowed packages.
_allowedUnpinnedPackages
.addAll(_getAllowedPackages(_allowDependenciesFlag));
_allowedPinnedPackages
.addAll(_getAllowedPackages(_allowPinnedDependenciesFlag));
}

Iterable<String> _getAllowedPackages(String flag) {
return getStringListArg(flag).expand<String>((String item) {
if (item.endsWith('.yaml')) {
final File file = packagesDir.fileSystem.file(item);
final Object? yaml = loadYaml(file.readAsStringSync());
if (yaml == null) {
return <String>[];
}
return (yaml as YamlList).toList().cast<String>();
}
return <String>[item];
});
_allowedUnpinnedPackages.addAll(getYamlListArg(_allowDependenciesFlag));
_allowedPinnedPackages.addAll(getYamlListArg(_allowPinnedDependenciesFlag));
}

@override
Expand Down
18 changes: 18 additions & 0 deletions script/tool/test/common/package_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ void main() {
expect(command.plugins, unorderedEquals(<String>[]));
});

test('exclude accepts empty config files', () async {
final RepositoryPackage plugin1 =
createFakePlugin('plugin1', packagesDir);
final File configFile1 = packagesDir.childFile('exclude1.yaml');
configFile1.createSync();
final File configFile2 = packagesDir.childFile('exclude2.yaml');
configFile2.writeAsStringSync('\n');
final File configFile3 = packagesDir.childFile('exclude3.yaml');
configFile3.writeAsStringSync('# - plugin1');

await runCapturingPrint(runner, <String>[
'sample',
'--packages=plugin1',
'--exclude=${configFile1.path},${configFile2.path},${configFile3.path}',
]);
expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
});

test('filter-packages-to accepts config files', () async {
final RepositoryPackage plugin1 =
createFakePlugin('plugin1', packagesDir);
Expand Down