Skip to content

Commit 1329b6e

Browse files
committed
Add option to skip based on primary input content.
1 parent c77755f commit 1329b6e

File tree

22 files changed

+1021
-35
lines changed

22 files changed

+1021
-35
lines changed

build_config/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## 1.1.3-wip
1+
## 1.2.0-wip
22

3+
- Add top level key `triggers`. See
4+
[the docs](https://github.com/dart-lang/build/blob/master/build_config/README.md#triggers)
5+
for more information.
36
- Bump the min sdk to 3.7.0.
47
- Remove unused dep: `yaml`.
58

build_config/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,80 @@ these options should be used rarely.
232232
and `applies_builder` to configure both ordering and ensure that steps are not
233233
skipped.
234234

235+
## Triggers
236+
237+
Triggers are a performance heuristic that allow builders to quickly decide
238+
_not_ to run.
239+
240+
A builder runs only if triggered if the option `run_only_if_triggered` is
241+
`true`. This can be enabled for the builder:
242+
243+
```yaml
244+
builders:
245+
my_builder:
246+
import: "package:my_package/builder.dart"
247+
builder_factories: ["myBuilder"]
248+
build_extensions: {".dart": [".my_package.dart"]}
249+
defaults:
250+
options:
251+
run_only_if_triggered: true
252+
```
253+
254+
Or, enabled/disabled in the `build.yaml` of the package applying the builder:
255+
256+
```yaml
257+
targets:
258+
$default:
259+
builders:
260+
my_package:my_builder:
261+
options:
262+
run_only_if_triggered: true # or `false`
263+
```
264+
265+
Triggers are defined in a new top-level section called `triggers`:
266+
267+
```yaml
268+
triggers:
269+
my_package:my_builder:
270+
- annotation MyAnnotation
271+
- import my_package/my_builder_annotation.dart
272+
```
273+
274+
An `annotation` trigger causes the builder to run if an annotation is used.
275+
So, `- annotation MyAnnotation` is a check for `@MyAnnotation` being used.
276+
277+
An `import` trigger says that the builder runs if there is a direct import
278+
of the specified library. This might be useful if a builder can run on code
279+
without annotations, for example on all classes that `implement` a particular
280+
type. Then, the import of the type used to trigger generation can be the
281+
trigger.
282+
283+
Only one trigger has to match for the builder to run; adding more triggers
284+
can never prevent a builder from running. So, a builder usually only needs
285+
either an `import` trigger or an `annotation` trigger, not both.
286+
287+
Triggers are collected from all packages in the codebase, not just packages
288+
defining or applying builders. This allows a package to provide new ways to
289+
trigger a builder from an unrelated package. For example, if
290+
`third_party_package` re-exports the annotation in
291+
`package:my_package/my_builder_annotation.dart` then it should also add a
292+
trigger:
293+
294+
```yaml
295+
triggers:
296+
my_package:my_builder:
297+
- import third_party_package/annotations.dart
298+
```
299+
300+
Or, if `third_party_package` defines a new constant `NewAnnotation` that can be
301+
used as an annotation for `my_builder`, it should add a trigger:
302+
303+
```yaml
304+
triggers:
305+
my_package:my_builder:
306+
- annotation NewAnnotation
307+
```
308+
235309
# Publishing `build.yaml` files
236310

237311
`build.yaml` configuration should be published to pub with the package and

build_config/lib/src/build_config.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class BuildConfig {
7878

7979
final List<String> additionalPublicAssets;
8080

81+
/// Triggers for builders with the option `run_only_if_triggered`.
82+
///
83+
/// Keys are builder names, values are not defined here: validity and meaning
84+
/// is up to `build_runner`.
85+
@JsonKey(name: 'triggers')
86+
final Map<String, Object> triggersByBuilder;
87+
8188
/// The default config if you have no `build.yaml` file.
8289
factory BuildConfig.useDefault(
8390
String packageName,
@@ -148,6 +155,7 @@ class BuildConfig {
148155
Map<String, PostProcessBuilderDefinition>? postProcessBuilderDefinitions =
149156
const {},
150157
this.additionalPublicAssets = const [],
158+
this.triggersByBuilder = const {},
151159
}) : buildTargets =
152160
identical(buildTargets, BuildConfig._placeholderBuildTarget)
153161
? {

build_config/lib/src/build_config.g.dart

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

build_config/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_config
2-
version: 1.1.3-wip
2+
version: 1.2.0-wip
33
description: >-
44
Format definition and support for parsing `build.yaml` configuration.
55
repository: https://github.com/dart-lang/build/tree/master/build_config

build_resolvers/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 3.0.2-wip
22

33
- Use `build` 3.0.2.
4+
- Use `build_runner` 2.7.0.
45

56
## 3.0.1
67

build_runner/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## 2.7.0-wip
22

3+
- Performance: builders can choose to run only when "triggered". A builder runs
4+
only if triggered if the option `run_only_if_triggered` is `true`. Triggers
5+
are configured in new a top-level section of `build.yaml` called `triggers`.
6+
See [the `build_config` docs](https://pub.dev/packages/build_config#triggers)
7+
for more information.
38
- Remove interactive prompts for whether to delete files.
49
- Ignore `-d` flag: always delete files as if `-d` was passed.
510

build_runner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
args: ^2.0.0
1717
async: ^2.5.0
1818
build: '3.0.2-wip'
19-
build_config: ">=1.1.0 <1.2.0"
19+
build_config: ">=1.2.0-wip <1.3.0"
2020
build_daemon: ^4.0.0
2121
build_runner_core: '9.3.0-wip'
2222
code_builder: ^4.2.0

build_runner_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 9.3.0-wip
22

3+
- Add support for build.yaml `triggers`. See `build_runner` 2.7.0 for usage.
34
- Remove interactive prompts for whether to delete files.
45
- Ignore `-d` flag: always delete files as if `-d` was passed.
56

build_runner_core/lib/src/asset_graph/graph.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class AssetGraph implements GeneratedAssetHider {
6060
final Map<String, Map<PostProcessBuildStepId, Set<AssetId>>>
6161
_postProcessBuildStepOutputs = {};
6262

63+
/// Digest of the previous build's `BuildTriggers`, or `null` if this is a
64+
/// clean build.
65+
Digest? previousBuildTriggersDigest;
66+
6367
/// Digests from the previous build's [BuildPhases], or `null` if this is a
6468
/// clean build.
6569
BuiltList<Digest>? previousInBuildPhasesOptionsDigests;

0 commit comments

Comments
 (0)