From ee512e0442fd8fcd38956c5018d2809547a8d58e Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 13 Dec 2024 15:58:07 -0800 Subject: [PATCH] Delete stale package_config.json in gclient sync hook (flutter/engine#57195) On the bots there were old and stale `package_config.json` files hanging around that confuse the `dart format` command. This PR adds a step to the `pub_get_offline.py` glcient sync hook to delete all of these files that are not under version control. --- engine/src/flutter/tools/pub_get_offline.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/engine/src/flutter/tools/pub_get_offline.py b/engine/src/flutter/tools/pub_get_offline.py index 2bf6b8ace5..154c08e6d5 100644 --- a/engine/src/flutter/tools/pub_get_offline.py +++ b/engine/src/flutter/tools/pub_get_offline.py @@ -127,6 +127,17 @@ def find_unlisted_packages(): return unlisted +def delete_config_files(): + # Find all package_config.json that are not under version control. + gitcmd = ['git', 'ls-files', '-o', '**/.dart_tool/package_config.json'] + files_to_delete = subprocess.check_output( + gitcmd, cwd=ENGINE_DIR, stderr=subprocess.STDOUT, text=True + ).splitlines() + for file in files_to_delete: + print('Deleting %s...' % file) + os.remove(os.path.join(ENGINE_DIR, file)) + + def main(): # Intentionally use the Dart SDK prebuilt instead of the Flutter prebuilt # (i.e. prebuilts/{platform}/dart-sdk/bin/dart) because the script has to run @@ -135,6 +146,10 @@ def main(): SRC_ROOT, 'flutter', 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin' ) + # Delete all package_config.json files. These may be stale. + # Required ones will be regenerated fresh below. + delete_config_files() + # Ensure all relevant packages are listed in ALL_PACKAGES. unlisted = find_unlisted_packages() if len(unlisted) > 0: