From 7bdc9e0ec9b374cb52dc02a985ecf3fe63703b12 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 10 Mar 2016 09:49:27 -0800 Subject: [PATCH] reorder properties, add constant which has the asset graph path --- lib/src/generate/build_impl.dart | 29 ++++++++++++++--------------- lib/src/generate/watch_impl.dart | 3 ++- lib/src/util/constants.dart | 9 +++++++++ test/common/common.dart | 4 ++-- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 lib/src/util/constants.dart diff --git a/lib/src/generate/build_impl.dart b/lib/src/generate/build_impl.dart index b90eeae0d..62633eed3 100644 --- a/lib/src/generate/build_impl.dart +++ b/lib/src/generate/build_impl.dart @@ -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'; @@ -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> _buildActions; final _inputsByPackage = >{}; - 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 /// @@ -166,10 +169,6 @@ class BuildImpl { return result; } - /// Asset containing previous asset dependency graph. - AssetId get _assetGraphId => - new AssetId(_packageGraph.root.name, '.dart_tool/build/asset_graph.json'); - /// Reads in the [assetGraph] from disk. Future _readAssetGraph() async { if (!await _reader.hasInput(_assetGraphId)) return new AssetGraph(); @@ -360,7 +359,7 @@ class BuildImpl { stdout.writeln('\n\nFound ${conflictingOutputs.length} declared outputs ' 'which already exist on disk. This is likely because the' - '`.dart_tool/build` folder was deleted, or you are submitting generated ' + '`$cacheDir` folder was deleted, or you are submitting generated ' 'files to your source repository.'); var done = false; while (!done) { diff --git a/lib/src/generate/watch_impl.dart b/lib/src/generate/watch_impl.dart index 1b2e81ee2..f2d4cc740 100644 --- a/lib/src/generate/watch_impl.dart +++ b/lib/src/generate/watch_impl.dart @@ -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'; @@ -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('.dart_tool/build/')) return true; + if (id.path.contains(cacheDir)) return true; var node = _assetGraph.get(id); return node is GeneratedAssetNode && type != ChangeType.REMOVE; } diff --git a/lib/src/util/constants.dart b/lib/src/util/constants.dart new file mode 100644 index 000000000..4a1a4ac8a --- /dev/null +++ b/lib/src/util/constants.dart @@ -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'; diff --git a/test/common/common.dart b/test/common/common.dart index 7080ceb06..0993269ed 100644 --- a/test/common/common.dart +++ b/test/common/common.dart @@ -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'; @@ -24,8 +26,6 @@ export 'matchers.dart'; export 'stub_reader.dart'; export 'stub_writer.dart'; -final String assetGraphPath = '.dart_tool/build/asset_graph.json'; - Future wait(int milliseconds) => new Future.delayed(new Duration(milliseconds: milliseconds));