Skip to content

Commit

Permalink
generateRunScript: address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandercampbell-wk committed Mar 8, 2024
1 parent b395a77 commit 4f72e97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';

import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:args/command_runner.dart';
import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:dart_dev/dart_dev.dart';
import 'package:glob/glob.dart';
Expand Down Expand Up @@ -145,14 +146,19 @@ List<String> generateRunScript() {
return;
}

// Include the packageConfig so that when dependencies change, we recompile.
final packageConfig = File(_paths.packageConfig);

final digest = md5.convert([
...packageConfig.readAsBytesSync(),
if (configFile.existsSync()) ...configFile.readAsBytesSync(),
if (configHasRelativeImports)
for (final file in Glob('tool/**.dart', recursive: true)
.listSync()
.whereType<File>()
.where(
(f) => p.canonicalize(f.path) != p.canonicalize(_paths.config)))
(f) => p.canonicalize(f.path) != p.canonicalize(_paths.config))
.sortedBy((f) => f.path))
...file.readAsBytesSync(),
]);
encodedDigest = base64.encode(digest.bytes);
Expand All @@ -162,7 +168,10 @@ List<String> generateRunScript() {
(!runExecutableDigest.existsSync() ||
runExecutableDigest.readAsStringSync() != encodedDigest)) {
// Digest is missing or outdated, so we (re-)compile.
logTimedSync(log, 'Compiling run script', () {
final logMessage = runExecutable.existsSync()
? 'Recompiling run script (digest changed)'
: 'Compiling run script';
logTimedSync(log, logMessage, () {
// Delete the previous executable and digest so that if we hit a failure
// trying to compile, we don't leave the outdated one in place.
if (runExecutable.existsSync()) runExecutable.deleteSync();
Expand Down
4 changes: 4 additions & 0 deletions lib/src/tools/clean_tool.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:dart_dev/src/utils/logging.dart';
import 'package:io/io.dart';

import '../dart_dev_tool.dart';
Expand All @@ -14,7 +15,10 @@ class CleanTool extends DevTool {
FutureOr<int?> run([DevToolExecutionContext? context]) {
final cache = Directory(DartDevPaths().cache());
if (cache.existsSync()) {
log.info('Deleting ${cache.path}');
cache.deleteSync(recursive: true);
} else {
log.info('Nothing to do: no ${cache.path} found');
}
return ExitCode.success.code;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/utils/dart_dev_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DartDevPaths {
from: p.url.absolute(_cacheForDart),
);

String get packageConfig => _context.join('.dart_tool', 'package_config.json');

String get legacyConfig => _context.join('tool', 'dev.dart');

String get runScript => cache('run.dart');
Expand Down

0 comments on commit 4f72e97

Please sign in to comment.