Skip to content

Commit c2ec328

Browse files
authored
Stop writing package_config_subset (flutter#169125)
Fixes flutter#168764 As of dart-lang/pub#4549 pub no longer rewrites the package_config.json file when nothing changes. And it doesn't write a timestamp in it.
1 parent 7b5e5ae commit c2ec328

File tree

5 files changed

+5
-45
lines changed

5 files changed

+5
-45
lines changed

packages/flutter_tools/lib/src/build_system/targets/common.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ class ReleaseCopyFlutterBundle extends CopyFlutterBundle {
125125
}
126126

127127
/// Generate a snapshot of the dart code used in the program.
128-
///
129-
/// This target depends on the `.dart_tool/package_config.json` file
130-
/// even though it is not listed as an input. Pub inserts a timestamp into
131-
/// the file which causes unnecessary rebuilds, so instead a subset of the contents
132-
/// are used an input instead.
133128
class KernelSnapshot extends Target {
134129
const KernelSnapshot();
135130

@@ -138,7 +133,7 @@ class KernelSnapshot extends Target {
138133

139134
@override
140135
List<Source> get inputs => const <Source>[
141-
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config_subset'),
136+
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config.json'),
142137
Source.pattern(
143138
'{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/common.dart',
144139
),

packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DartPluginRegistrantTarget extends Target {
6868

6969
@override
7070
List<Source> get inputs => <Source>[
71-
const Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config_subset'),
71+
const Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config.json'),
7272
];
7373

7474
@override

packages/flutter_tools/lib/src/build_system/targets/native_assets.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ abstract class DartBuild extends Target {
9999
'{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart',
100100
),
101101
// If different packages are resolved, different native assets might need to be built.
102-
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config_subset'),
102+
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config.json'),
103103
// TODO(mosuem): Should consume resources.json. https://github.com/flutter/flutter/issues/146263
104104
];
105105

@@ -187,7 +187,7 @@ class InstallCodeAssets extends Target {
187187
'{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart',
188188
),
189189
// If different packages are resolved, different native assets might need to be built.
190-
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config_subset'),
190+
Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config.json'),
191191
];
192192

193193
@override

packages/flutter_tools/lib/src/build_system/targets/web.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ abstract class Dart2WebTarget extends Target {
132132
const Source.hostArtifact(HostArtifact.flutterWebSdk),
133133
const Source.artifact(Artifact.engineDartBinary),
134134
const Source.pattern('{BUILD_DIR}/main.dart'),
135-
const Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config_subset'),
135+
const Source.pattern('{WORKSPACE_DIR}/.dart_tool/package_config.json'),
136136
];
137137

138138
@override

packages/flutter_tools/lib/src/dart/pub.dart

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ library;
88
import 'dart:async';
99

1010
import 'package:meta/meta.dart';
11-
import 'package:package_config/package_config.dart';
1211
import 'package:process/process.dart';
1312
import '../base/bot_detector.dart';
1413
import '../base/common.dart';
@@ -663,9 +662,6 @@ class _DefaultPub implements Pub {
663662
/// Updates the .dart_tool/version file to be equal to current Flutter
664663
/// version.
665664
///
666-
/// Calls [_updatePackageConfig] for [project] and [FlutterProject.example]
667-
/// (if it exists).
668-
///
669665
/// This should be called after pub invocations that are expected to update
670666
/// the packageConfig.
671667
Future<void> _updateVersionAndPackageConfig(FlutterProject project) async {
@@ -683,44 +679,13 @@ class _DefaultPub implements Pub {
683679
);
684680
lastVersion.writeAsStringSync(currentVersion.readAsStringSync());
685681

686-
await _updatePackageConfig(project, packageConfig);
687682
if (project.hasExampleApp && project.example.pubspecFile.existsSync()) {
688683
final File? examplePackageConfig = findPackageConfigFile(project.example.directory);
689684
if (examplePackageConfig == null) {
690685
throwToolExit(
691686
'${project.directory}: pub did not create example/.dart_tools/package_config.json file.',
692687
);
693688
}
694-
await _updatePackageConfig(project.example, examplePackageConfig);
695689
}
696690
}
697-
698-
/// Update the package configuration file in [project].
699-
///
700-
/// Creates a corresponding `package_config_subset` file that is used by the
701-
/// build system to avoid rebuilds caused by an updated pub timestamp.
702-
Future<void> _updatePackageConfig(FlutterProject project, File packageConfigFile) async {
703-
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
704-
packageConfigFile,
705-
logger: _logger,
706-
);
707-
708-
packageConfigFile.parent
709-
.childFile('package_config_subset')
710-
.writeAsStringSync(_computePackageConfigSubset(packageConfig, _fileSystem));
711-
}
712-
713-
// Subset the package config file to only the parts that are relevant for
714-
// rerunning the dart compiler.
715-
String _computePackageConfigSubset(PackageConfig packageConfig, FileSystem fileSystem) {
716-
final StringBuffer buffer = StringBuffer();
717-
for (final Package package in packageConfig.packages) {
718-
buffer.writeln(package.name);
719-
buffer.writeln(package.languageVersion);
720-
buffer.writeln(package.root);
721-
buffer.writeln(package.packageUriRoot);
722-
}
723-
buffer.writeln(packageConfig.version);
724-
return buffer.toString();
725-
}
726691
}

0 commit comments

Comments
 (0)