Skip to content
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
134 changes: 114 additions & 20 deletions .github/workflows/dart.yml

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

4 changes: 4 additions & 0 deletions build_runner_core/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ stages:
os:
- linux
- windows
- leak_check:
- group:
- command: ../tool/leak_check.sh
sdk: dev
39 changes: 39 additions & 0 deletions build_runner_core/test/invalidation/invalidation_leak_checker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// 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:io';

import 'invalidation_tester.dart';

/// Checks for memory leaks.
///
/// Runs many incremental builds, prints the average increase in memory usage
/// per build.
///
/// Run using `tool/leak_check.sh`.
void main(List<String> arguments) async {
final tester = InvalidationTester(testIsRunning: false);

tester.sources(['a.1']);

tester.builder(from: '.1', to: '.2')
..reads('.1')
..resolvesOther('a.1')
..writes('.2');

await tester.build();
await tester.build(change: 'a.1');

// `.dart_tool/build_resolvers/sdk.sum` will be calculated and written if it
// does not yet exist, leading to very different memory usage. Users should
// run with the arg `setup` first to make sure this has happened.
if (arguments.contains('setup')) return;

final before = ProcessInfo.currentRss;
for (var i = 0; i != 5000; ++i) {
await tester.build(change: 'a.1');
}
final after = ProcessInfo.currentRss;
print((after - before) ~/ 5000);
}
16 changes: 11 additions & 5 deletions build_runner_core/test/invalidation/invalidation_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import 'package:test/test.dart';
/// to the path `lib/a.dart`; all names map to the package `pkg`. "Hidden" asset
/// IDs under `.dart_tool` are mapped back to the same namespace.
class InvalidationTester {
final bool testIsRunning;

/// The source assets on disk before the first build.
final Set<AssetId> _sourceAssets = {};

Expand Down Expand Up @@ -65,6 +67,8 @@ class InvalidationTester {
/// Output number, for writing outputs that are different.
int _outputNumber = 0;

InvalidationTester({this.testIsRunning = true});

/// Starts logging test setup.
///
/// Useful if test setup is random or generated.
Expand Down Expand Up @@ -231,11 +235,13 @@ class InvalidationTester {
testingBuilderConfig: false,
);
final logString = log.toString();
printOnFailure(
'=== build log #${++_buildNumber} ===\n\n'
'${_setupLog.map((l) => ' $l\n').join('')}'
'${logString.trimAndIndent}',
);
if (testIsRunning) {
printOnFailure(
'=== build log #${++_buildNumber} ===\n\n'
'${_setupLog.map((l) => ' $l\n').join('')}'
'${logString.trimAndIndent}',
);
}
if (_logSetup) _setupLog.clear();
readerWriter = testBuildResult.readerWriter;

Expand Down
6 changes: 5 additions & 1 deletion tool/ci.sh

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

Loading