Skip to content

Track dart version and invalidate if it changes #1009

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 4 commits into from
Feb 13, 2018
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
1 change: 1 addition & 0 deletions build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
`--track-performance` flag to enable it.
- The heartbeat logger will now log the current number of completed versus
scheduled actions, and it will log once a second instead of every 5 seconds.
- Builds will now be invalidated when the dart SDK is updated.

## 0.7.10+1

Expand Down
10 changes: 8 additions & 2 deletions build_runner/lib/src/asset_graph/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:build/build.dart';
import 'package:convert/convert.dart';
Expand Down Expand Up @@ -38,7 +39,11 @@ class AssetGraph {
/// the new [BuildAction]s and throw away the graph if it doesn't.
final Digest buildActionsDigest;

AssetGraph._(this.buildActionsDigest, {Map<int, Set<AssetId>> failedActions})
/// The [Platform.version] this graph was created with.
final String dartVersion;

AssetGraph._(this.buildActionsDigest, this.dartVersion,
{Map<int, Set<AssetId>> failedActions})
: _failedActions = failedActions ?? new Map<int, Set<AssetId>>();

/// Deserializes this graph.
Expand All @@ -51,7 +56,8 @@ class AssetGraph {
Set<AssetId> internalSources,
PackageGraph packageGraph,
AssetReader digestReader) async {
var graph = new AssetGraph._(computeBuildActionsDigest(buildActions));
var graph = new AssetGraph._(
computeBuildActionsDigest(buildActions), Platform.version);
var placeholders = graph._addPlaceHolderNodes(packageGraph);
var sourceNodes = graph._addSources(sources);
graph._addBuilderOptionsNodes(buildActions);
Expand Down
4 changes: 3 additions & 1 deletion build_runner/lib/src/asset_graph/serialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class _AssetGraphDeserializer {
}

var graph = new AssetGraph._(
_deserializeDigest(_serializedGraph['buildActionsDigest'] as String));
_deserializeDigest(_serializedGraph['buildActionsDigest'] as String),
_serializedGraph['dart_version'] as String);

var packageNames = _serializedGraph['packages'] as List<String>;

Expand Down Expand Up @@ -159,6 +160,7 @@ class _AssetGraphSerializer {

var result = <String, dynamic>{
'version': _version,
'dart_version': _graph.dartVersion,
'nodes': _graph.allNodes.map(_serializeNode).toList(growable: false),
'buildActionsDigest': _serializeDigest(_graph.buildActionsDigest),
'packages': packages,
Expand Down
7 changes: 6 additions & 1 deletion build_runner/lib/src/generate/build_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ class _Loader {
'Throwing away cached asset graph because the build actions have '
'changed. This most commonly would happen as a result of adding a '
'new dependency or updating your dependencies.');

await _cleanupOldOutputs(cachedGraph);
return null;
}
if (cachedGraph.dartVersion != Platform.version) {
_logger.warning(
'Throwing away cached asset graph due to Dart SDK update.');
await _cleanupOldOutputs(cachedGraph);
return null;
}
Expand Down
38 changes: 38 additions & 0 deletions build_runner/test/generate/build_definition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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:async';
import 'dart:convert';
import 'dart:io';

import 'package:build/build.dart';
Expand Down Expand Up @@ -340,6 +341,43 @@ main() {
expect(originalAssetGraph.buildActionsDigest,
isNot(newAssetGraph.buildActionsDigest));
});
test('invalidates the graph if the dart sdk version changes', () async {
// Gets rid of console spam during tests, we are setting up a new options
// object.
await options.logListener.cancel();

var buildActions = [
new BuildAction(new TestBuilder(), 'a', hideOutput: true)
];
var logs = <LogRecord>[];
environment = new OverrideableEnvironment(environment, onLog: logs.add);
options = new BuildOptions(environment,
packageGraph: options.packageGraph,
logLevel: Level.WARNING,
skipBuildScriptCheck: true);

var originalAssetGraph = await AssetGraph.build(buildActions,
<AssetId>[].toSet(), new Set(), aPackageGraph, environment.reader);

var bytes = originalAssetGraph.serialize();
var serialized = JSON.decode(UTF8.decode(bytes));
serialized['dart_version'] = 'some_fake_version';
var encoded = UTF8.encode(JSON.encode(serialized));
await createFile(assetGraphPath, encoded);

logs.clear();

await BuildDefinition.prepareWorkspace(
environment, options, buildActions);
expect(
logs.any(
(log) =>
log.level == Level.WARNING &&
log.message.contains(
'Throwing away cached asset graph due to Dart SDK update.'),
),
isTrue);
});

test('does not invalidate the graph if the BuilderOptions change',
() async {
Expand Down