Skip to content
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

Change cache location #84

Merged
merged 3 commits into from
Mar 10, 2016
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ build/
.pub/
pubspec.lock

# Files generated by build runs
.build
# Files generated by dart tools
.dart_tool

# Generated by tool/create_all_test.dart
tool/test_all.dart
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.2.0
- Updated the top level classes to take a `PhaseGroup` instead of a
`List<List<Phase>>`.
- Added logic to handle nested package directories.
- Basic windows support added, although it may still be unstable.
- Significantly increased the resolving speed by using the same sources cache.
- Added a basic README.
- Moved the `.build` folder to `.dart_tool/build`. Other packages in the future
may also use this folder.

## 0.1.4
- Added top level `serve` function.
- Just like `watch`, but it provides a server which blocks on any ongoing
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ Outputs from previous builds will not be treated as inputs to later ones.

### Source control

This package creates a top level `.build` folder in your package, which should
not be submitted to your source control repo (likely this just means adding
'.build' to your '.gitignore' file).
This package creates a top level `.dart_tool` folder in your package, which
should not be submitted to your source control repo (likely this just means
adding '.dart_tool' to your '.gitignore' file).

When it comes to generated files it is generally best to not submit them to
source control, but a specific `Builder` may provide a recommendation otherwise.
Expand Down
33 changes: 16 additions & 17 deletions lib/src/generate/build_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../builder/build_step_impl.dart';
import '../builder/builder.dart';
import '../logging/logging.dart';
import '../package_graph/package_graph.dart';
import '../util/constants.dart';
import 'build_result.dart';
import 'exceptions.dart';
import 'input_set.dart';
Expand All @@ -32,24 +33,26 @@ import 'phase.dart';

/// Class which manages running builds.
class BuildImpl {
AssetGraph _assetGraph;
AssetGraph get assetGraph => _assetGraph;

final AssetReader _reader;
final AssetWriter _writer;
final PackageGraph _packageGraph;
final AssetId _assetGraphId;
final List<List<BuildAction>> _buildActions;
final _inputsByPackage = <String, Set<AssetId>>{};
bool _buildRunning = false;
final _logger = new Logger('Build');
final PackageGraph _packageGraph;
final AssetReader _reader;
final AssetWriter _writer;

AssetGraph _assetGraph;
AssetGraph get assetGraph => _assetGraph;
bool _buildRunning = false;
bool _isFirstBuild = true;

BuildImpl(BuildOptions options, PhaseGroup phaseGroup)
: _reader = options.reader,
_writer = options.writer,
: _assetGraphId =
new AssetId(options.packageGraph.root.name, assetGraphPath),
_buildActions = phaseGroup.buildActions,
_packageGraph = options.packageGraph,
_buildActions = phaseGroup.buildActions;
_reader = options.reader,
_writer = options.writer;

/// Runs a build
///
Expand Down Expand Up @@ -166,10 +169,6 @@ class BuildImpl {
return result;
}

/// Asset containing previous asset dependency graph.
AssetId get _assetGraphId =>
new AssetId(_packageGraph.root.name, '.build/asset_graph.json');

/// Reads in the [assetGraph] from disk.
Future<AssetGraph> _readAssetGraph() async {
if (!await _reader.hasInput(_assetGraphId)) return new AssetGraph();
Expand Down Expand Up @@ -359,9 +358,9 @@ class BuildImpl {
if (conflictingOutputs.isEmpty) return;

stdout.writeln('\n\nFound ${conflictingOutputs.length} declared outputs '
'which already exist on disk. This is likely because the `.build` '
'folder was deleted, or you are submitting generated files to your '
'source repository.');
'which already exist on disk. This is likely because the'
'`$cacheDir` folder was deleted, or you are submitting generated '
'files to your source repository.');
var done = false;
while (!done) {
stdout.write('\nDelete these files (y/n) (or list them (l))?: ');
Expand Down
3 changes: 2 additions & 1 deletion lib/src/generate/watch_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../asset_graph/graph.dart';
import '../asset_graph/node.dart';
import '../logging/logging.dart';
import '../package_graph/package_graph.dart';
import '../util/constants.dart';
import 'build_impl.dart';
import 'build_result.dart';
import 'directory_watcher_factory.dart';
Expand Down Expand Up @@ -228,7 +229,7 @@ class WatchImpl {

/// Checks if we should skip a watch event for this [id].
bool _shouldSkipInput(AssetId id, ChangeType type) {
if (id.path.contains('.build/')) return true;
if (id.path.contains(cacheDir)) return true;
var node = _assetGraph.get(id);
return node is GeneratedAssetNode && type != ChangeType.REMOVE;
}
Expand Down
9 changes: 9 additions & 0 deletions lib/src/util/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2016, 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.

/// Relative path to the asset graph from the root package dir.
const assetGraphPath = '$cacheDir/asset_graph.json';

/// Relative path to the cache directory from the root package dir.
const cacheDir = '.dart_tool/build';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build
version: 0.1.4
version: 0.2.0
description: A build system for Dart.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/build
Expand Down
2 changes: 2 additions & 0 deletions test/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'in_memory_reader.dart';
import 'in_memory_writer.dart';
import 'matchers.dart';

export 'package:build/src/util/constants.dart';

export 'assets.dart';
export 'copy_builder.dart';
export 'fake_watcher.dart';
Expand Down
21 changes: 12 additions & 9 deletions test/generate/build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ main() {
{
'a|lib/a.txt': 'a',
'a|lib/a.txt.copy': 'a',
'a|.build/asset_graph.json': JSON.encode(emptyGraph.serialize()),
'a|$assetGraphPath':
JSON.encode(emptyGraph.serialize()),
},
status: BuildStatus.Failure,
exceptionMatcher: invalidOutputException);
Expand All @@ -153,7 +154,7 @@ main() {
outputs: {'a|web/a.txt.copy': 'a', 'a|lib/b.txt.copy': 'b'},
writer: writer);

var graphId = makeAssetId('a|.build/asset_graph.json');
var graphId = makeAssetId('a|$assetGraphPath');
expect(writer.assets, contains(graphId));
var cachedGraph =
new AssetGraph.deserialize(JSON.decode(writer.assets[graphId].value));
Expand Down Expand Up @@ -194,7 +195,7 @@ main() {
await testPhases(copyAPhaseGroup, inputs, outputs: outputs, writer: writer);

// Delete the `asset_graph.json` file!
var outputId = makeAssetId('a|.build/asset_graph.json');
var outputId = makeAssetId('a|$assetGraphPath');
await writer.delete(outputId);

// Second run, should have no extra outputs.
Expand Down Expand Up @@ -223,7 +224,7 @@ main() {
'a|web/a.txt': 'a',
'a|lib/b.txt.copy': 'b',
'a|lib/c.txt': 'c',
'a|.build/asset_graph.json': JSON.encode(graph.serialize()),
'a|$assetGraphPath': JSON.encode(graph.serialize()),
}, outputs: {
'a|web/a.txt.copy': 'a',
'a|lib/c.txt.copy': 'c',
Expand Down Expand Up @@ -268,7 +269,8 @@ main() {
'a|lib/a.txt.copy.clone': 'a',
'a|lib/b.txt.copy': 'b',
'a|lib/b.txt.copy.clone': 'b',
'a|.build/asset_graph.json': JSON.encode(graph.serialize()),
'a|$assetGraphPath':
JSON.encode(graph.serialize()),
},
outputs: {'a|lib/a.txt.copy': 'b', 'a|lib/a.txt.copy.clone': 'b',},
writer: writer);
Expand Down Expand Up @@ -297,14 +299,15 @@ main() {
{
'a|lib/a.txt.copy': 'a',
'a|lib/a.txt.copy.clone': 'a',
'a|.build/asset_graph.json': JSON.encode(graph.serialize()),
'a|$assetGraphPath':
JSON.encode(graph.serialize()),
},
outputs: {},
writer: writer);

/// Should be deleted using the writer, and removed from the new graph.
var newGraph = new AssetGraph.deserialize(JSON.decode(
writer.assets[makeAssetId('a|.build/asset_graph.json')].value));
var newGraph = new AssetGraph.deserialize(JSON.decode(writer
.assets[makeAssetId('a|$assetGraphPath')].value));
expect(newGraph.contains(aNode.id), isFalse);
expect(newGraph.contains(aCopyNode.id), isFalse);
expect(newGraph.contains(aCloneNode.id), isFalse);
Expand All @@ -331,7 +334,7 @@ main() {
await testPhases(copyAPhaseGroup, {
'a|web/a.txt': 'a',
'a|web/a.txt.copy': 'a',
'a|.build/asset_graph.json': JSON.encode(graph.serialize()),
'a|$assetGraphPath': JSON.encode(graph.serialize()),
}, outputs: {
'a|web/a.txt.copy': 'a',
});
Expand Down
4 changes: 2 additions & 2 deletions test/generate/watch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ main() {
result = await nextResult(results);
checkOutputs({'a|web/c.txt.copy': 'c'}, result, writer.assets);

var cachedGraph = new AssetGraph.deserialize(JSON.decode(
writer.assets[makeAssetId('a|.build/asset_graph.json')].value));
var cachedGraph = new AssetGraph.deserialize(JSON.decode(writer
.assets[makeAssetId('a|$assetGraphPath')].value));

var expectedGraph = new AssetGraph();
var bCopyNode = makeAssetNode('a|web/b.txt.copy');
Expand Down