Skip to content

Commit 285b9fd

Browse files
committed
Merge branch 'main' into try_protocol_v0.9
2 parents aa8dbfb + 2d28ae9 commit 285b9fd

File tree

4 files changed

+79
-39
lines changed

4 files changed

+79
-39
lines changed

.github/workflows/flutter_packages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
env:
4545
GH_TOKEN: ${{ github.token }}
4646
run: |
47-
# Find all directories containing pubspec.yaml in packages and examples.
48-
ALL_DIRS=$(find packages examples -name pubspec.yaml -not -path "*/.dart_tool/*" -exec dirname {} \;)
47+
# Find all directories containing pubspec.yaml in packages, tools, and examples.
48+
ALL_DIRS=$(find packages examples tool -name pubspec.yaml -not -path "*/.dart_tool/*" -exec dirname {} \;)
4949
5050
# Get the list of changed files. The method depends on the event type.
5151
if [[ "${{ github.event_name }}" == "pull_request" ]]; then

examples/catalog_gallery/lib/samples_view.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ class _SamplesViewState extends State<SamplesView> {
8080
if (!widget.samplesDir.existsSync()) {
8181
return;
8282
}
83-
final List<File> files = await widget.samplesDir
84-
.list()
85-
.where((entity) => entity is File && entity.path.endsWith('.sample'))
86-
.cast<File>()
83+
final List<File> files = (await widget.samplesDir.list().toList())
84+
.whereType<File>()
85+
.where((file) => file.path.endsWith('.sample'))
8786
.toList();
8887
setState(() {
8988
_sampleFiles = files;
@@ -113,17 +112,19 @@ class _SamplesViewState extends State<SamplesView> {
113112
_messageSubscription = sample.messages.listen(
114113
_genUiManager.handleMessage,
115114
onError: (Object e) {
116-
print('Error processing message: $e');
115+
debugPrint('Error processing message: $e');
116+
if (!context.mounted) return;
117117
ScaffoldMessenger.of(context).showSnackBar(
118118
SnackBar(content: Text('Error processing sample: $e')),
119119
);
120120
},
121121
);
122-
} catch (exception, stackTrace) {
123-
print('Error parsing sample: $exception\n$stackTrace');
124-
ScaffoldMessenger.of(context).showSnackBar(
125-
SnackBar(content: Text('Error parsing sample: $exception')),
126-
);
122+
} catch (e) {
123+
debugPrint('Error parsing sample: $e');
124+
if (!context.mounted) return;
125+
ScaffoldMessenger.of(
126+
context,
127+
).showSnackBar(SnackBar(content: Text('Error parsing sample: $e')));
127128
}
128129
}
129130

@@ -136,23 +137,20 @@ class _SamplesViewState extends State<SamplesView> {
136137
width: 250,
137138
child: Column(
138139
children: [
139-
AppBar(
140-
title: const Text('Samples'),
141-
automaticallyImplyLeading: false,
142-
elevation: 0,
143-
),
144140
Expanded(
145141
child: ListView.builder(
146142
itemCount: _sampleFiles.length,
147143
itemBuilder: (context, index) {
148144
final File file = _sampleFiles[index];
149-
final String fileName = widget.fs.path.basename(file.path);
145+
final String fileName = widget.fs.path
146+
.basenameWithoutExtension(file.path);
150147

151148
return ListTile(
152149
title: Text(fileName),
153-
selected:
154-
_selectedFile?.path ==
155-
file.path, // Compare file paths for selection
150+
selected: _selectedFile?.path == file.path,
151+
selectedTileColor: Theme.of(
152+
context,
153+
).colorScheme.primary.withValues(alpha: 0.1),
156154
onTap: () => _selectSample(file),
157155
);
158156
},
@@ -190,9 +188,7 @@ class _SamplesViewState extends State<SamplesView> {
190188
vertical: 8,
191189
),
192190
color: isSelected
193-
? Theme.of(
194-
context,
195-
).primaryColor.withValues(alpha: 0.1)
191+
? Theme.of(context).colorScheme.primary
196192
: null,
197193
alignment: Alignment.center,
198194
child: Text(
@@ -202,7 +198,9 @@ class _SamplesViewState extends State<SamplesView> {
202198
? FontWeight.bold
203199
: FontWeight.normal,
204200
color: isSelected
205-
? Theme.of(context).primaryColor
201+
? Theme.of(
202+
context,
203+
).colorScheme.onPrimary
206204
: null,
207205
),
208206
),

tool/test_and_fix/lib/test_and_fix.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,56 @@ class TestAndFix {
121121
bool all = false,
122122
}) async {
123123
final projects = <Directory>[];
124-
await for (final FileSystemEntity entity in root.list(recursive: true)) {
125-
if (entity is! File || path.basename(entity.path) != 'pubspec.yaml') {
126-
continue;
127-
}
128-
final File pubspec = entity;
129-
final Directory projectDir = pubspec.parent;
130-
if (isProjectAllowed(projectDir, all: all)) {
131-
projects.add(projectDir);
124+
await _findProjectsRecursive(root, projects, all: all);
125+
return projects;
126+
}
127+
128+
Future<void> _findProjectsRecursive(
129+
Directory dir,
130+
List<Directory> projects, {
131+
required bool all,
132+
}) async {
133+
final Set<String> excludedDirs = _getExcludedDirectories(all: all);
134+
try {
135+
await for (final FileSystemEntity entity in dir.list(
136+
followLinks: false,
137+
)) {
138+
if (entity is File && fs.path.basename(entity.path) == 'pubspec.yaml') {
139+
final Directory projectDir = entity.parent;
140+
if (isProjectAllowed(projectDir, all: all)) {
141+
projects.add(projectDir);
142+
}
143+
} else if (entity is Directory) {
144+
if (!excludedDirs.contains(fs.path.basename(entity.path))) {
145+
await _findProjectsRecursive(entity, projects, all: all);
146+
}
147+
}
132148
}
149+
} on FileSystemException catch (exception) {
150+
print(
151+
'Warning: Failed to list directory contents while searching for '
152+
'projects: $exception',
153+
);
133154
}
134-
return projects;
135155
}
136156

137-
bool isProjectAllowed(Directory projectPath, {bool all = false}) {
138-
// Skip the things that we really don't ever want to traverse, but skip the
139-
// non-essential packages unless --all is specified.
140-
final excluded = [
157+
Set<String> _getExcludedDirectories({required bool all}) {
158+
return {
141159
'.dart_tool',
142160
'ephemeral',
143161
'firebase_core',
144162
'build',
145163
if (!all) 'spikes',
146164
if (!all) 'fix_copyright',
165+
if (!all) 'release',
147166
if (!all) 'test_and_fix',
148-
];
167+
};
168+
}
169+
170+
bool isProjectAllowed(Directory projectPath, {bool all = false}) {
171+
// Skip the things that we really don't ever want to traverse, but skip the
172+
// non-essential packages unless --all is specified.
173+
final Set<String> excluded = _getExcludedDirectories(all: all);
149174
final List<String> components = fs.path.split(projectPath.path);
150175
for (final exclude in excluded) {
151176
if (components.contains(exclude)) {

tool/test_and_fix/test/project_discovery_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ void main() {
6464
expect(projects, isEmpty);
6565
});
6666

67+
test('ignores nested projects in excluded directories', () async {
68+
final excluded = ['.dart_tool', 'build', 'ephemeral', 'firebase_core'];
69+
70+
for (final exclude in excluded) {
71+
final Directory project = fs.directory(
72+
path.join(root.path, exclude, 'nested_project'),
73+
)..createSync(recursive: true);
74+
fs
75+
.file(path.join(project.path, 'pubspec.yaml'))
76+
.writeAsStringSync('sdk: flutter');
77+
}
78+
79+
final List<Directory> projects = await testAndFix.findProjects(root);
80+
81+
expect(projects, isEmpty);
82+
});
83+
6784
test('ignores some excluded directories with --all', () async {
6885
final excluded = ['.dart_tool', 'ephemeral', 'firebase_core', 'build'];
6986

0 commit comments

Comments
 (0)