dependency_checker.dart 1.5 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'asset.dart';
6
import 'base/file_system.dart';
7
import 'dart/dependencies.dart';
8
import 'globals.dart';
9 10

class DependencyChecker {
11 12
  DependencyChecker(this.builder, this.assets);

13
  final DartDependencySetBuilder builder;
14
  final Set<String> _dependencies = Set<String>();
15 16 17 18 19 20 21 22
  final AssetBundle assets;

  /// Returns [true] if any components have been modified after [threshold] or
  /// if it cannot be determined.
  bool check(DateTime threshold) {
    _dependencies.clear();
    // Build the set of Dart dependencies.
    try {
23
      _dependencies.addAll(builder.build());
24 25 26 27 28 29 30 31
    } catch (e, st) {
      printTrace('DependencyChecker: error determining .dart dependencies:\n$e\n$st');
      return true;
    }
    // TODO(johnmccutchan): Extract dependencies from the AssetBundle too.

    // Check all dependency modification times.
    for (String path in _dependencies) {
32 33
      final File file = fs.file(path);
      final FileStat stat = file.statSync();
34
      if (stat.type == FileSystemEntityType.notFound) {
35 36 37 38 39 40 41 42
        printTrace('DependencyChecker: Error stating $path.');
        return true;
      }
      if (stat.modified.isAfter(threshold)) {
        printTrace('DependencyChecker: $path is newer than $threshold');
        return true;
      }
    }
43
    printTrace('DependencyChecker: nothing is modified after $threshold.');
44 45 46
    return false;
  }
}