Skip to content

Commit

Permalink
Merge branch 'master' into log-error-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
natebosch committed Dec 13, 2023
2 parents 03b21a4 + 1fccc73 commit 9c0a5f3
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dart.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions _test/test/goldens/generated_build_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,16 @@ final _builders = <_i1.BuilderApplication>[
_i1.toAllPackages(),
isOptional: true,
hideOutput: true,
appliesBuilders: const [r'build_resolvers:transitive_digest_cleanup'],
),
_i1.applyPostProcess(
r'build_modules:module_cleanup',
_i6.moduleCleanup,
),
_i1.applyPostProcess(
r'build_resolvers:transitive_digest_cleanup',
_i8.transitiveDigestCleanup,
),
_i1.applyPostProcess(
r'build_web_compilers:dart2js_archive_extractor',
_i3.dart2jsArchiveExtractor,
Expand Down
2 changes: 1 addition & 1 deletion build/lib/src/asset/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class InvalidInputException implements Exception {
class BuildStepCompletedException implements Exception {
@override
String toString() => 'BuildStepCompletedException: '
'Attempt to use a BuildStep after is has completed';
'Attempt to use a BuildStep after it has completed';
}

class UnresolvableAssetException implements Exception {
Expand Down
4 changes: 3 additions & 1 deletion build_daemon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 4.0.1-wip
## 4.0.1

- Use a hash of the working dir to create the unique workspace dir. This
resolves an issue when file names become too long.
- Bump the min sdk to 3.0.0.

## 4.0.0
Expand Down
9 changes: 5 additions & 4 deletions build_daemon/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:path/path.dart' as p;

const readyToConnectLog = 'READY TO CONNECT';
Expand Down Expand Up @@ -42,10 +44,9 @@ var _username = Platform.environment['USER'] ?? '';
String daemonWorkspace(String workingDirectory) {
var segments = [Directory.systemTemp.path];
if (_username.isNotEmpty) segments.add(_username);
segments.add(workingDirectory
.replaceAll('/', '_')
.replaceAll(':', '_')
.replaceAll('\\', '_'));
final workingDirHash =
base64UrlEncode(md5.convert(workingDirectory.codeUnits).bytes);
segments.add(workingDirHash);
return p.joinAll(segments);
}

Expand Down
3 changes: 2 additions & 1 deletion build_daemon/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_daemon
version: 4.0.1-wip
version: 4.0.1
description: A daemon for running Dart builds.
repository: https://github.com/dart-lang/build/tree/master/build_daemon

Expand All @@ -9,6 +9,7 @@ environment:
dependencies:
built_collection: ^5.0.0
built_value: ^8.1.0
crypto: ^3.0.3
http_multi_server: ^3.0.0
logging: ^1.0.0
path: ^1.8.0
Expand Down
4 changes: 3 additions & 1 deletion build_modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 5.0.5-wip
## 5.0.5

- Allow version 3.3.x of the Dart SDK.

## 5.0.4

Expand Down
4 changes: 2 additions & 2 deletions build_modules/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: build_modules
version: 5.0.5-wip
version: 5.0.5
description: >-
Builders to analyze and split Dart code into individually compilable modules
based on imports.
repository: https://github.com/dart-lang/build/tree/master/build_modules

environment:
sdk: '>=3.0.0 <3.3.0'
sdk: '>=3.0.0 <3.4.0'

dependencies:
analyzer: '>=5.1.0 <7.0.0'
Expand Down
6 changes: 5 additions & 1 deletion build_resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 2.4.1-wip
## 2.4.2

- Add a builder to clean up transitive digest files from the build output.

## 2.4.1

- Fix an issue where deleted files were not removed from the analysis engine,
and were still accessible via the analyzer apis.
Expand Down
6 changes: 6 additions & 0 deletions build_resolvers/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ builders:
is_optional: True
required_inputs: [".dart"]
build_to: cache
applies_builders:
- :transitive_digest_cleanup
post_process_builders:
transitive_digest_cleanup:
import: "package:build_resolvers/builder.dart"
builder_factory: transitiveDigestCleanup
4 changes: 4 additions & 0 deletions build_resolvers/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import 'src/build_asset_uri_resolver.dart';

Builder transitiveDigestsBuilder(_) => _TransitiveDigestsBuilder();

PostProcessBuilder transitiveDigestCleanup(BuilderOptions options) =>
FileDeletingBuilder([transitiveDigestExtension],
isEnabled: options.config['enabled'] as bool? ?? true);

/// Computes a digest comprised of the current libraries digest as well as its
/// transitive dependency digests, and writes it to a file next to the library.
///
Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_resolvers
version: 2.4.1-wip
version: 2.4.2
description: Resolve Dart code in a Builder
repository: https://github.com/dart-lang/build/tree/master/build_resolvers

Expand Down
4 changes: 2 additions & 2 deletions build_resolvers/test/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ void main() {
group('language versioning', () {
test('gives a correct languageVersion based on comments', () async {
await resolveSources({
'a|web/main.dart': '// @dart=2.1\n\nmain() {}',
'a|web/main.dart': '// @dart=3.1\n\nmain() {}',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
expect(lib.languageVersion.effective.major, 2);
expect(lib.languageVersion.effective.major, 3);
expect(lib.languageVersion.effective.minor, 1);
}, resolvers: AnalyzerResolvers());
});
Expand Down
8 changes: 7 additions & 1 deletion build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
## 2.4.7-wip
## 2.4.8-wip

- Update README.md to point to the FAQ and other docs.
- Print stack traces for `Error` subtype exceptions in non-verbose mode.

## 2.4.7

- Fix broken link in README.md.
- Bump the min sdk to 3.0.0.
- Add a warning to the `doctor` command if a `build.yml` file is found (instead
of a `build.yaml` file).

## 2.4.6

Expand Down
22 changes: 15 additions & 7 deletions build_runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ rebuilds are _incremental_ - inspired by tools such as [Bazel][].

> **NOTE**: Are you a user of this package? You may be interested in
> simplified user-facing documentation, such as our
> [getting started guide][getting-started-link].
> [getting started guide][getting-started-link] and [faq][faq-link].
[getting-started-link]: https://goo.gl/b9o2j6
[getting-started-link]: https://github.com/dart-lang/build/blob/master/docs/getting_started.md
[faq-link]: https://github.com/dart-lang/build/blob/master/docs/faq.md
[other-docs-link]: https://github.com/dart-lang/build/tree/master/docs

* [Installation](#installation)
* [Usage](#usage)
Expand All @@ -32,18 +34,18 @@ rebuilds are _incremental_ - inspired by tools such as [Bazel][].
* [Outputs](#outputs)
* [Source control](#source-control)
* [Publishing packages](#publishing-packages)
* [Docs](#docs)
* [Contributing](#contributing)
* [Testing](#testing)

## Installation

This package is intended to support development of Dart projects with
[`package:build`][]. In general, put it under [dev_dependencies][], in your
[`pubspec.yaml`][pubspec].
[`package:build`][]. In general, add it to your [`pubspec.yaml`][pubspec]
as a [dev_dependencies][] by running the following command.

```yaml
dev_dependencies:
build_runner:
```console
$ dart pub add dev:build_runner
```

## Usage
Expand All @@ -57,6 +59,12 @@ also provide a `build.yaml` with the configuration. See the

To have web code compiled to js add a `dev_dependency` on `build_web_compilers`.

## Docs

More comprehensive documentation is stored in this repository, under the
[docs][other-docs-link] directory. If you find something is undocumented, please
file an issue.

### Built-in Commands

The `build_runner` package exposes a binary by the same name, which can be
Expand Down
10 changes: 10 additions & 0 deletions build_runner/lib/src/entrypoint/doctor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:build/build.dart';
import 'package:build_config/build_config.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:build_runner_core/build_runner_core.dart';
import 'package:build_runner_core/src/generate/phase.dart';
import 'package:io/io.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as p;

import '../logging/std_io_logging.dart';
import '../package_graph/build_config_overrides.dart';
Expand Down Expand Up @@ -40,6 +42,14 @@ class DoctorCommand extends BuildRunnerCommand {
isOk = isOk && builderOk;
}

if (File(p.join(p.current, 'build.yml')).existsSync() &&
!File(p.join(p.current, 'build.yaml')).existsSync()) {
logger.warning(
'Found a `build.yml` file but no `build.yaml` file, rename it with '
'the `.yaml` extension for it to take effect.');
isOk = false;
}

if (isOk) {
logger.info('No problems found!\n');
}
Expand Down
2 changes: 1 addition & 1 deletion build_runner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_runner
version: 2.4.7-wip
version: 2.4.8-wip
description: A build system for Dart code generation and modular compilation.
repository: https://github.com/dart-lang/build/tree/master/build_runner

Expand Down
9 changes: 8 additions & 1 deletion build_web_compilers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 4.0.6-wip
## 4.0.7

- Support `dart:js_interop_unsafe`.
- Require Dart 3.1 or greater.

## 4.0.6

- Allow version 3.3.x of the Dart SDK.

## 4.0.5

Expand Down
1 change: 1 addition & 0 deletions build_web_compilers/lib/src/platforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const _libraries = [
'indexed_db',
'js',
'js_interop',
'js_interop_unsafe',
'js_util',
'math',
'svg',
Expand Down
18 changes: 6 additions & 12 deletions build_web_compilers/lib/src/web_entrypoint_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@ class WebEntrypointBuilder implements Builder {
deprecatedOptions: _deprecatedOptions);
var compilerOption =
options.config[_compilerOption] as String? ?? 'dartdevc';
WebCompiler compiler;
switch (compilerOption) {
case 'dartdevc':
compiler = WebCompiler.DartDevc;
break;
case 'dart2js':
compiler = WebCompiler.Dart2Js;
break;
default:
throw ArgumentError.value(compilerOption, _compilerOption,
'Only `dartdevc` and `dart2js` are supported.');
}
var compiler = switch (compilerOption) {
'dartdevc' => WebCompiler.DartDevc,
'dart2js' => WebCompiler.Dart2Js,
_ => throw ArgumentError.value(compilerOption, _compilerOption,
'Only `dartdevc` and `dart2js` are supported.')
};

if (options.config[_dart2jsArgsOption] is! List) {
var message = options.config[_dart2jsArgsOption] is String
Expand Down
4 changes: 2 additions & 2 deletions build_web_compilers/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: build_web_compilers
version: 4.0.6-wip
version: 4.0.7
description: Builder implementations wrapping the dart2js and DDC compilers.
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers

environment:
sdk: '>=3.0.0 <3.3.0'
sdk: '>=3.1.0 <3.4.0'

dependencies:
analyzer: '>=5.1.0 <7.0.0'
Expand Down
33 changes: 9 additions & 24 deletions docs/writing_an_aggregate_builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ currently support the following synthetic files for this purpose:

* `lib/$lib$`
* `$package$`
* `test/$test$` (deprecated)
* `web/$web$` (deprecated)

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

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

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

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

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

```yaml
dependencies:
build_resolvers: ^1.3.0
# ...
```

### Workaround for older versions

If you want to support older versions of the build system as well, you can split
your aggregate builder into two steps:
Split the process across two builders:

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

This strategy has the benefit of improved invalidation - only the files that
_need_ to be re-read with the `Resolver` will be invalidated, the rest of the
`.info` files will be retained as-is.

[findLibraryByName]: https://pub.dev/documentation/build/latest/build/Resolver/findLibraryByName.html
[libraries]: https://pub.dev/documentation/build/latest/build/Resolver/libraries.html
Loading

0 comments on commit 9c0a5f3

Please sign in to comment.