Skip to content

Add --use-experimental-resolver flag. #3831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
`AnalysisDriverFilesystem`. Add new implementation of
`AnalysisDriverModel`.
- Make resolver only throw `SyntaxErrorInAssetException` on severe syntax errors
- Add `BuildAssetUriResolver.useExperimentalResolver` for
`--use-experimental-resolver` flag. This will be removed.

## 2.4.3

Expand Down
17 changes: 15 additions & 2 deletions build_resolvers/lib/src/build_asset_uri_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const _ignoredSchemes = ['dart', 'dart-ext'];

const transitiveDigestExtension = '.transitive_digest';

/// Switches [BuildAssetUriResolver.sharedInstance] from [BuildAssetUriResolver]
/// to [AnalysisDriverModel].
void useExperimentalResolver() {
BuildAssetUriResolver._sharedInstance = AnalysisDriverModel();
}

class BuildAssetUriResolver implements AnalysisDriverModel {
/// A cache of the directives for each Dart library.
///
Expand Down Expand Up @@ -61,7 +67,12 @@ class BuildAssetUriResolver implements AnalysisDriverModel {
/// what should be used by normal builds.
///
/// This is not used within testing contexts or similar custom contexts.
static final BuildAssetUriResolver sharedInstance = BuildAssetUriResolver();
static AnalysisDriverModel get sharedInstance => _sharedInstance;
static AnalysisDriverModel _sharedInstance = _sharedUriResolverInstance;
// Keep a [BuildAssetUriResolver] instance even if [useExperimentalResolver]
// is called, for [dependenciesOf].
static final BuildAssetUriResolver _sharedUriResolverInstance =
BuildAssetUriResolver();

@override
Future<void> performResolve(
Expand Down Expand Up @@ -219,9 +230,11 @@ Set<AssetId> _parseDependencies(String content, AssetId from) => HashSet.of(

/// Read the (potentially) cached dependencies of [id] based on parsing the
/// directives, and cache the results if they weren't already cached.
///
/// TODO(davidmorgan): remove this or make it use `AnalysisDriverModel`.
Future<Iterable<AssetId>?> dependenciesOf(
AssetId id, BuildStep buildStep) async =>
(await BuildAssetUriResolver.sharedInstance
(await BuildAssetUriResolver._sharedUriResolverInstance
._updateCachedAssetState(id, buildStep))
?.dependencies;

Expand Down
4 changes: 3 additions & 1 deletion build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 2.4.15
## 2.4.15-wip

- Update to package:web and dart:js_interop.
- Support the latest `package:shelf_web_socket`.
- Add hidden `--use-experimental-resolver` flag for issue #3811 performance
work. This flag will be removed.

## 2.4.14

Expand Down
3 changes: 2 additions & 1 deletion build_runner/lib/src/entrypoint/base_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ abstract class BuildRunnerCommand extends Command<int> {
'If multiple filters are applied then outputs matching any '
'filter will be built (they do not need to match all filters).')
..addMultiOption(enableExperimentOption,
help: 'A list of dart language experiments to enable.');
help: 'A list of dart language experiments to enable.')
..addFlag(useExperimentalResolverOption, hide: true);
}

/// Must be called inside [run] so that [argResults] is non-null.
Expand Down
7 changes: 7 additions & 0 deletions build_runner/lib/src/entrypoint/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import 'dart:async';

import 'package:build/experiments.dart';
// ignore: implementation_imports
import 'package:build_resolvers/src/build_asset_uri_resolver.dart'
as uri_resolver;
import 'package:build_runner_core/build_runner_core.dart';
import 'package:io/io.dart';

Expand Down Expand Up @@ -32,6 +35,10 @@ class BuildCommand extends BuildRunnerCommand {
}

Future<int> _run(SharedOptions options) async {
// TODO(davidmorgan): remove when experiment is over.
if (options.useExperimentalResolver) {
uri_resolver.useExperimentalResolver();
}
var result = await build(
builderApplications,
buildFilters: options.buildFilters,
Expand Down
15 changes: 15 additions & 0 deletions build_runner/lib/src/entrypoint/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const releaseOption = 'release';
const trackPerformanceOption = 'track-performance';
const skipBuildScriptCheckOption = 'skip-build-script-check';
const symlinkOption = 'symlink';
const useExperimentalResolverOption = 'use-experimental-resolver';
const usePollingWatcherOption = 'use-polling-watcher';
const verboseOption = 'verbose';

Expand Down Expand Up @@ -86,6 +87,8 @@ class SharedOptions {

final List<String> enableExperiments;

final bool useExperimentalResolver;

SharedOptions._({
required this.buildFilters,
required this.deleteFilesByDefault,
Expand All @@ -100,6 +103,7 @@ class SharedOptions {
required this.isReleaseBuild,
required this.logPerformanceDir,
required this.enableExperiments,
required this.useExperimentalResolver,
});

SharedOptions.fromParsedArgs(ArgResults argResults,
Expand All @@ -122,6 +126,8 @@ class SharedOptions {
isReleaseBuild: argResults[releaseOption] as bool,
logPerformanceDir: argResults[logPerformanceOption] as String?,
enableExperiments: argResults[enableExperimentOption] as List<String>,
useExperimentalResolver:
argResults[useExperimentalResolverOption] as bool,
);
}

Expand All @@ -147,6 +153,7 @@ class DaemonOptions extends WatchOptions {
required super.logPerformanceDir,
required super.usePollingWatcher,
required super.enableExperiments,
required super.useExperimentalResolver,
}) : super._();

factory DaemonOptions.fromParsedArgs(ArgResults argResults,
Expand Down Expand Up @@ -187,6 +194,8 @@ class DaemonOptions extends WatchOptions {
logPerformanceDir: argResults[logPerformanceOption] as String?,
usePollingWatcher: argResults[usePollingWatcherOption] as bool,
enableExperiments: argResults[enableExperimentOption] as List<String>,
useExperimentalResolver:
argResults[useExperimentalResolverOption] as bool,
);
}
}
Expand Down Expand Up @@ -214,6 +223,7 @@ class WatchOptions extends SharedOptions {
required super.isReleaseBuild,
required super.logPerformanceDir,
required super.enableExperiments,
required super.useExperimentalResolver,
}) : super._();

WatchOptions.fromParsedArgs(ArgResults argResults,
Expand All @@ -237,6 +247,8 @@ class WatchOptions extends SharedOptions {
logPerformanceDir: argResults[logPerformanceOption] as String?,
usePollingWatcher: argResults[usePollingWatcherOption] as bool,
enableExperiments: argResults[enableExperimentOption] as List<String>,
useExperimentalResolver:
argResults[useExperimentalResolverOption] as bool,
);
}

Expand Down Expand Up @@ -266,6 +278,7 @@ class ServeOptions extends WatchOptions {
required super.logPerformanceDir,
required super.usePollingWatcher,
required super.enableExperiments,
required super.useExperimentalResolver,
}) : super._();

factory ServeOptions.fromParsedArgs(ArgResults argResults,
Expand Down Expand Up @@ -337,6 +350,8 @@ class ServeOptions extends WatchOptions {
logPerformanceDir: argResults[logPerformanceOption] as String?,
usePollingWatcher: argResults[usePollingWatcherOption] as bool,
enableExperiments: argResults[enableExperimentOption] as List<String>,
useExperimentalResolver:
argResults[useExperimentalResolverOption] as bool,
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions build_runner/lib/src/entrypoint/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import 'dart:async';

import 'package:build/experiments.dart';
// ignore: implementation_imports
import 'package:build_resolvers/src/build_asset_uri_resolver.dart'
as uri_resolver;
import 'package:build_runner_core/build_runner_core.dart';
import 'package:io/io.dart';

Expand Down Expand Up @@ -46,6 +49,10 @@ class WatchCommand extends BuildRunnerCommand {
}

Future<int> _run(WatchOptions options) async {
// TODO(davidmorgan): remove when experiment is over.
if (options.useExperimentalResolver) {
uri_resolver.useExperimentalResolver();
}
var handler = await watch(
builderApplications,
deleteFilesByDefault: options.deleteFilesByDefault,
Expand Down
4 changes: 2 additions & 2 deletions build_runner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_runner
version: 2.4.15
version: 2.4.15-wip
description: A build system for Dart code generation and modular compilation.
repository: https://github.com/dart-lang/build/tree/master/build_runner
resolution: workspace
Expand All @@ -19,7 +19,7 @@ dependencies:
build: ">=2.1.0 <2.5.0"
build_config: ">=1.1.0 <1.2.0"
build_daemon: ^4.0.0
build_resolvers: ^2.0.0
build_resolvers: ^2.4.4-wip
build_runner_core: ^8.0.0
code_builder: ^4.2.0
collection: ^1.15.0
Expand Down
Loading