Skip to content

Commit f8439e3

Browse files
committed
Add new code for resolving deps graphs in a phased build.
1 parent e8122b2 commit f8439e3

18 files changed

+1457
-125
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:built_collection/built_collection.dart';
6+
import 'package:built_value/built_value.dart';
7+
8+
import '../asset/id.dart';
9+
10+
part 'deps_cycle.g.dart';
11+
12+
abstract class DepsCycle implements Built<DepsCycle, DepsCycleBuilder> {
13+
BuiltSet<AssetId> get nodes;
14+
15+
factory DepsCycle([void Function(DepsCycleBuilder) updates]) = _$DepsCycle;
16+
DepsCycle._();
17+
}

build/lib/src/deps_graph/deps_cycle.g.dart

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:built_collection/built_collection.dart';
6+
import 'package:built_value/built_value.dart';
7+
8+
import '../asset/id.dart';
9+
import 'deps_cycle.dart';
10+
11+
part 'deps_graph.g.dart';
12+
13+
abstract class DepsGraph implements Built<DepsGraph, DepsGraphBuilder> {
14+
DepsCycle get root;
15+
BuiltList<DepsGraph> get children;
16+
17+
factory DepsGraph([void Function(DepsGraphBuilder) updates]) = _$DepsGraph;
18+
DepsGraph._();
19+
20+
// TODO(davidmorgan): the graph should usually stay as a graph rather than
21+
// being expanded into an explicit set of nodes. So, remove uses of this.
22+
// If in the end it's still needed, investigate if it needs to be optimized.
23+
Iterable<AssetId> get transitiveDeps sync* {
24+
final seenCycles = Set<DepsCycle>.identity()..add(root);
25+
final graphs = [this];
26+
27+
while (graphs.isNotEmpty) {
28+
final graph = graphs.removeLast();
29+
if (seenCycles.add(graph.root)) {
30+
yield* graph.root.nodes;
31+
}
32+
graphs.addAll(graph.children);
33+
}
34+
}
35+
}

build/lib/src/deps_graph/deps_graph.g.dart

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)