Skip to content

Commit 24a6a1d

Browse files
authored
More bootstrap cleanup. (#4152)
1 parent 011c73a commit 24a6a1d

File tree

4 files changed

+6
-83
lines changed

4 files changed

+6
-83
lines changed

build_runner/lib/src/build_script_generate/bootstrap.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'dart:isolate';
99
import 'package:build_runner_core/build_runner_core.dart';
1010
import 'package:frontend_server_client/frontend_server_client.dart';
1111
import 'package:io/io.dart';
12-
import 'package:logging/logging.dart';
1312
import 'package:path/path.dart' as p;
1413
import 'package:stack_trace/stack_trace.dart';
1514

@@ -28,20 +27,8 @@ import 'build_script_generate.dart';
2827
Future<int> generateAndRun(
2928
List<String> args, {
3029
List<String>? experiments,
31-
Logger? logger,
3230
String? script,
33-
}) {
34-
return buildLog.runWithLoggerDisplay(
35-
logger,
36-
() => _generateAndRun(args, experiments, script),
37-
);
38-
}
39-
40-
Future<int> _generateAndRun(
41-
List<String> args,
42-
List<String>? experiments,
43-
String? script,
44-
) async {
31+
}) async {
4532
experiments ??= [];
4633
ReceivePort? exitPort;
4734
ReceivePort? errorPort;

build_runner/lib/src/build_script_generate/build_script_generate.dart

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,44 +72,16 @@ ${library.accept(emitter)}
7272
}
7373
}
7474

75-
/// Finds expressions to create all the `BuilderApplication` instances that
76-
/// should be applied packages in the build.
77-
///
78-
/// Adds `apply` expressions based on the BuildefDefinitions from any package
79-
/// which has a `build.yaml`.
80-
///
81-
/// Optionally, a custom [packageGraph] and [buildConfigOverrides] can be used
82-
/// to change which packages and build configurations are considered.
83-
/// By default, the [PackageGraph.forThisPackage] will be used and configuration
84-
/// overrides will be loaded from the root package.
85-
Future<Iterable<Expression>> findBuilderApplications({
86-
PackageGraph? packageGraph,
87-
Map<String, BuildConfig>? buildConfigOverrides,
88-
}) async {
89-
final info = await findBuildScriptOptions(
90-
packageGraph: packageGraph,
91-
buildConfigOverrides: buildConfigOverrides,
92-
);
93-
return info.builderApplications;
94-
}
95-
96-
Future<BuildScriptInfo> findBuildScriptOptions({
97-
PackageGraph? packageGraph,
98-
Map<String, BuildConfig>? buildConfigOverrides,
99-
}) async {
100-
packageGraph ??= await PackageGraph.forThisPackage();
75+
Future<BuildScriptInfo> findBuildScriptOptions() async {
76+
final packageGraph = await PackageGraph.forThisPackage();
10177
final orderedPackages = stronglyConnectedComponents<PackageNode>(
10278
[packageGraph.root],
10379
(node) => node.dependencies,
10480
equals: (a, b) => a.name == b.name,
10581
hashCode: (n) => n.name.hashCode,
10682
).expand((c) => c);
10783
var reader = ReaderWriter(packageGraph);
108-
var overrides =
109-
buildConfigOverrides ??= await findBuildConfigOverrides(
110-
packageGraph,
111-
reader,
112-
);
84+
var overrides = await findBuildConfigOverrides(packageGraph, reader);
11385
Future<BuildConfig> packageBuildConfig(PackageNode package) async {
11486
if (overrides.containsKey(package.name)) {
11587
return overrides[package.name]!;
@@ -141,7 +113,7 @@ Future<BuildScriptInfo> findBuildScriptOptions({
141113
// Make sure package is known in packageGraph (when present),
142114
// otherwise PackageNotFoundException will be thrown down the road
143115
final pkg = AssetId.resolve(Uri.parse(import)).package;
144-
if (packageGraph?.allPackages.containsKey(pkg) ?? true) {
116+
if (packageGraph.allPackages.containsKey(pkg)) {
145117
return true;
146118
}
147119
buildLog.warning(
@@ -152,7 +124,7 @@ Future<BuildScriptInfo> findBuildScriptOptions({
152124
return false;
153125
}
154126
// ignore: avoid_dynamic_calls
155-
return definition.package == packageGraph!.root.name;
127+
return definition.package == packageGraph.root.name;
156128
}
157129

158130
final orderedConfigs = await Future.wait(

build_runner/test/build_script_generate/experiments_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
library;
88

99
import 'package:build_runner/src/build_script_generate/bootstrap.dart';
10-
import 'package:logging/logging.dart';
1110
import 'package:test/test.dart';
1211

1312
void main() {
1413
test('build scripts can use experiments', () async {
15-
final logger = Logger.detached('test')..level = Level.ALL;
16-
logger.onRecord.listen((r) => printOnFailure(r.message));
1714
final exitCode = await generateAndRun(
1815
[],
1916
experiments: ['records'],
@@ -30,7 +27,6 @@ void main() {
3027
buildProcessState.send(sendPort);
3128
}
3229
''',
33-
logger: logger,
3430
);
3531
expect(exitCode, 2);
3632
});

build_runner_core/lib/src/logging/build_log.dart

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:math';
76

87
import 'package:build/build.dart' show AssetId;
98
// ignore: implementation_imports
109
import 'package:build_runner/src/internal.dart';
11-
import 'package:logging/logging.dart';
1210

1311
import '../generate/phase.dart';
1412
import 'ansi_buffer.dart';
@@ -148,36 +146,6 @@ class BuildLog {
148146
BuildLogLogger loggerForOther(String context) =>
149147
BuildLogLogger(context: context);
150148

151-
/// Runs [function] with all output sent to [logger] instead of the default
152-
/// display.
153-
///
154-
/// If [logger] is `null`, just runs [function].
155-
Future<T> runWithLoggerDisplay<T>(
156-
Logger? logger,
157-
Future<T> Function() function,
158-
) async {
159-
final previousOnLog = configuration.onLog;
160-
if (logger != null) {
161-
configuration = configuration.rebuild((b) {
162-
b.onLog =
163-
(record) => logger.log(
164-
record.level,
165-
record.message,
166-
record.error,
167-
record.stackTrace,
168-
record.zone,
169-
);
170-
});
171-
}
172-
try {
173-
return await function();
174-
} finally {
175-
if (logger != null) {
176-
configuration = configuration.rebuild((b) => b..onLog = previousOnLog);
177-
}
178-
}
179-
}
180-
181149
/// Logs why `build_runner` needs to do a full build.
182150
///
183151
/// The reason will be displayed when [startBuild] is called.

0 commit comments

Comments
 (0)