Skip to content

Commit 0551fa2

Browse files
committed
Add option to skip based on primary input content.
1 parent 21eae68 commit 0551fa2

File tree

23 files changed

+658
-50
lines changed

23 files changed

+658
-50
lines changed

build/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.1-wip
2+
3+
- Use `build_runner 2.7.0`.
4+
15
## 3.0.0
26

37
- Removed unused deps: `meta`, `pool`.

build/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build
2-
version: 3.0.0
2+
version: 3.0.1-wip
33
description: A package for authoring build_runner compatible code generators.
44
repository: https://github.com/dart-lang/build/tree/master/build
55
resolution: workspace
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
analyzer: '>=7.4.0 <8.0.0'
1212
async: ^2.5.0
13-
build_runner_core: '9.2.0'
13+
build_runner_core: '9.3.0-wip'
1414
built_collection: ^5.1.1
1515
built_value: ^8.9.5
1616
convert: ^3.0.0

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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,61 @@ 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+
- import my_package/my_builder_annotation.dart
271+
```
272+
273+
An `import` triggers says that the builder only runs if there is a direct import
274+
of the specified library. Usually, this will be a library that defines the
275+
annotation that configures the generator.
276+
277+
Triggers are collected from all packages in the codebase, not just packages
278+
defining or applying builders. This allows a package to provide new ways to
279+
trigger a builder from an unrelated package. For example, if
280+
`third_party_package` re-exports the annotation in
281+
`package:my_package/my_builder_annotation.dart` then it should also add a
282+
trigger:
283+
284+
```yaml
285+
triggers:
286+
my_package:my_builder:
287+
- import third_party_package/annotations.dart
288+
```
289+
235290
# Publishing `build.yaml` files
236291

237292
`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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.1-wip
2+
3+
- Use `build_runner 2.7.0`.
4+
15
## 3.0.0
26

37
- Remove unused deps: `graphs`, `logging`, `stream_transform`.

build_resolvers/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_resolvers
2-
version: 3.0.0
2+
version: 3.0.1-wip
33
description: Resolve Dart code in a Builder
44
repository: https://github.com/dart-lang/build/tree/master/build_resolvers
55
resolution: workspace
@@ -10,8 +10,8 @@ environment:
1010
dependencies:
1111
analyzer: '>=7.4.0 <8.0.0'
1212
async: ^2.5.0
13-
build: '3.0.0'
14-
build_runner_core: '9.2.0'
13+
build: '3.0.1-wip'
14+
build_runner_core: '9.3.0-wip'
1515
collection: ^1.17.0
1616
convert: ^3.1.1
1717
crypto: ^3.0.0

build_runner/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.7.0-wip
2+
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://github.com/dart-lang/build/blob/master/build_config/README.md#triggers)
7+
for more information.
8+
19
## 2.6.0
210

311
- Remove unused deps: `analyzer`, `build_resolvers`, `collection`, `http`,

0 commit comments

Comments
 (0)