Skip to content

Commit 2a66be2

Browse files
authored
Freshen docs for aggregate builders (#3590)
Remove some references to the behavior of older versions of build_runner and build_resolvers. The changes were made in 2020, and we have had a major version change since the version which introduced the change. Change some docs about compatibility with older build_resolvers to instead describe the utility of splitting steps for improved invalidation behavior.
1 parent 2ba1102 commit 2a66be2

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

docs/writing_an_aggregate_builder.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ currently support the following synthetic files for this purpose:
4848

4949
* `lib/$lib$`
5050
* `$package$`
51-
* `test/$test$` (deprecated)
52-
* `web/$web$` (deprecated)
5351

5452
When choosing whether to use `$package$` or `lib/$lib$`, there are two primary
5553
considerations.
@@ -151,8 +149,8 @@ class ListAllFilesBuilder implements Builder {
151149
## Using a `Resolver`
152150

153151
Since the input of aggregate builders isn't a real asset that could be read, we
154-
also can't use `buildStep.inputLibrary` to resolve it. However, recent versions
155-
of the build system allow us to resolve any asset our builder can read.
152+
also can't use `buildStep.inputLibrary` to resolve it. However some methods,
153+
such as `libraryFor`, allow resolving any asset the builder can read.
156154

157155
For instance, we could adapt the `ListAllFilesBuilder` from before to instead
158156
list the names of all classes defined in `lib/`:
@@ -197,24 +195,15 @@ As the resolver has no single entry point in aggregate builders, be aware that
197195
[`findLibraryByName`][findLibraryByName] and [`libraries`][libraries] can only
198196
find libraries that have been discovered through `libraryFor` or `isLibrary`.
199197

200-
Note that older versions of the build `Resolver` only picked up libraries based
201-
on the builder's input. As the synthetic input asset of an aggregate builder
202-
isn't readable, the `Resolver` wasn't available for aggregate builders in older
203-
versions of the build system.
198+
### Improving invalidation
204199

205-
To ensure your builder only runs in an environment where this is supported, you
206-
can set the minimum version in your `pubspec.yaml`:
200+
If the builder uses a `Resolver` the output will be invalidated, and the builder
201+
will be rerun, any time there is a change in any resolved library _or any of
202+
it's transitive imports_. If the builder output only depends on limited
203+
information from the resolved libraries, it may be possible to invalidate the
204+
output only when a library changes in a way that is meaningful to the builder.
207205

208-
```yaml
209-
dependencies:
210-
build_resolvers: ^1.3.0
211-
# ...
212-
```
213-
214-
### Workaround for older versions
215-
216-
If you want to support older versions of the build system as well, you can split
217-
your aggregate builder into two steps:
206+
Split the process across two builders:
218207

219208
1. A `Builder` with `buildExtensions` of `{'.dart': ['.some_name.info']}`. Use
220209
the `Resolver` to find the information about the code that will be necessary
@@ -233,9 +222,5 @@ definition case ordering should be handled by configuring the second step to
233222
have a `required_inputs: ['.some_name.info']` based on the build extensions of
234223
the first step.
235224

236-
This strategy has the benefit of improved invalidation - only the files that
237-
_need_ to be re-read with the `Resolver` will be invalidated, the rest of the
238-
`.info` files will be retained as-is.
239-
240225
[findLibraryByName]: https://pub.dev/documentation/build/latest/build/Resolver/findLibraryByName.html
241226
[libraries]: https://pub.dev/documentation/build/latest/build/Resolver/libraries.html

0 commit comments

Comments
 (0)