Skip to content

Commit ac65c07

Browse files
authored
Allow single builder cycles (#3532)
Fixes #3531 When a builder outputs a file with the same extension as a `required_input` it will be in a cycle with itself. When builders were ordered with `stronglyConnectedComponents` cycles were detected by looking for a component (cycle) with more than one builder. With the move to `topologicalSort` the single builder cycle causes an exception during the sort. Exclude the builder itself from the list of dependencies for the graph algorithm call.
1 parent 2030554 commit ac65c07

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

build_runner/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.4.5
2+
3+
- Fix a bug handling a builder which has a `required_input` that matches it's
4+
own output.
5+
16
## 2.4.4
27

38
- Use a stable order for builders without an order defined by dependencies.

build_runner/lib/src/build_script_generate/builder_ordering.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Iterable<BuilderDefinition> findBuilderOrder(
1818
..sort((a, b) => a.key.compareTo(b.key));
1919
Iterable<BuilderDefinition> dependencies(BuilderDefinition parent) =>
2020
consistentOrderBuilders.where((child) =>
21-
_hasInputDependency(parent, child) ||
22-
_mustRunBefore(parent, child, globalBuilderConfigs));
21+
parent != child &&
22+
(_hasInputDependency(parent, child) ||
23+
_mustRunBefore(parent, child, globalBuilderConfigs)));
2324
try {
2425
return topologicalSort<BuilderDefinition>(
2526
consistentOrderBuilders,

build_runner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_runner
2-
version: 2.4.4
2+
version: 2.4.5
33
description: A build system for Dart code generation and modular compilation.
44
repository: https://github.com/dart-lang/build/tree/master/build_runner
55

build_runner/test/build_script_generate/builder_ordering_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,28 @@ void main() {
185185
{}),
186186
throwsA(anything));
187187
});
188+
189+
test('allows self cycles with `required_inputs`', () async {
190+
final buildConfigs = parseBuildConfigs({
191+
'a': {
192+
'builders': {
193+
'self_cycle': {
194+
'builder_factories': ['createBuilder'],
195+
'build_extensions': {
196+
'.in': ['.out'],
197+
'.out': ['.another']
198+
},
199+
'target': '',
200+
'import': '',
201+
'required_inputs': ['.out'],
202+
},
203+
}
204+
}
205+
});
206+
final orderedBuilders = findBuilderOrder(
207+
buildConfigs.values.expand((v) => v.builderDefinitions.values), {});
208+
final orderedKeys = orderedBuilders.map((b) => b.key);
209+
expect(orderedKeys, ['a:self_cycle']);
210+
});
188211
});
189212
}

0 commit comments

Comments
 (0)