From f127ba2c1427efb1ff1b6753c8f77983981c427e Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 29 Aug 2023 11:19:42 -0700 Subject: [PATCH] Clean up engine repo Dart code (flutter/engine#45203) Also adds a test to ensure that all packages are accounted for. --- engine/src/flutter/ci/analyze.sh | 13 +- .../flutter/ci/licenses_golden/excluded_files | 2 + engine/src/flutter/ci/pylint.sh | 1 + .../tessellator/dart/lib/tessellator.dart | 6 +- .../tools/gen_web_locale_keymap/pubspec.yaml | 25 +++- engine/src/flutter/tools/pub_get_offline.py | 129 ++++++++++++------ 6 files changed, 119 insertions(+), 57 deletions(-) diff --git a/engine/src/flutter/ci/analyze.sh b/engine/src/flutter/ci/analyze.sh index 907544bdc3..ed24df20c7 100755 --- a/engine/src/flutter/ci/analyze.sh +++ b/engine/src/flutter/ci/analyze.sh @@ -46,17 +46,14 @@ echo "Using dart from $DART_BIN" "$DART" --version echo "" -"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/lib/ui" - "$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/ci" - "$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/flutter_frontend_server" - -(cd "$FLUTTER_DIR/tools/gen_web_locale_keymap"; "$DART" pub get) -"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools" - -(cd "$FLUTTER_DIR/testing/skia_gold_client"; "$DART" pub get) +"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/impeller/golden_tests_harvester" +"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/impeller/tessellator/dart" +"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/lib/gpu" +"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/lib/ui" "$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing" +"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools" echo "" diff --git a/engine/src/flutter/ci/licenses_golden/excluded_files b/engine/src/flutter/ci/licenses_golden/excluded_files index 6c7fb1ab54..968cc72f3e 100644 --- a/engine/src/flutter/ci/licenses_golden/excluded_files +++ b/engine/src/flutter/ci/licenses_golden/excluded_files @@ -167,6 +167,8 @@ ../../../flutter/impeller/scene/README.md ../../../flutter/impeller/scene/importer/importer_unittests.cc ../../../flutter/impeller/scene/scene_unittests.cc +../../../flutter/impeller/tessellator/dart/.dart_tool +../../../flutter/impeller/tessellator/dart/pubspec.lock ../../../flutter/impeller/tessellator/dart/pubspec.yaml ../../../flutter/impeller/tessellator/tessellator_unittests.cc ../../../flutter/impeller/tools/build_metal_library.py diff --git a/engine/src/flutter/ci/pylint.sh b/engine/src/flutter/ci/pylint.sh index d54444fd2e..a3e3422152 100755 --- a/engine/src/flutter/ci/pylint.sh +++ b/engine/src/flutter/ci/pylint.sh @@ -39,6 +39,7 @@ pylint-2.7 --rcfile=.pylintrc \ "impeller/" \ "sky/" \ "tools/gn" \ + "tools/pub_get_offline.py" \ "testing/" echo "$(date +%T) Linting complete" diff --git a/engine/src/flutter/impeller/tessellator/dart/lib/tessellator.dart b/engine/src/flutter/impeller/tessellator/dart/lib/tessellator.dart index d478d03e2c..f899b2f630 100644 --- a/engine/src/flutter/impeller/tessellator/dart/lib/tessellator.dart +++ b/engine/src/flutter/impeller/tessellator/dart/lib/tessellator.dart @@ -64,6 +64,8 @@ class SmoothingApproximation { /// Finally, use the [dispose] method to clean up native resources. After /// [dispose] has been called, this class must not be used again. class VerticesBuilder { + /// Constructs a [VerticesBuilder] instance to which path commands can be + /// added. VerticesBuilder() : _builder = _createPathFn(); ffi.Pointer<_PathBuilder>? _builder; @@ -98,7 +100,7 @@ class VerticesBuilder { /// Adds a close command to the start of the current contour. void close() { assert(_builder != null); - closeFn(_builder!, true); + _closeFn(_builder!, true); } /// Tessellates the path created by the previous method calls into a list of @@ -209,7 +211,7 @@ final _CubicToType _cubicToFn = typedef _CloseType = void Function(ffi.Pointer<_PathBuilder>, bool); typedef _close_type = ffi.Void Function(ffi.Pointer<_PathBuilder>, ffi.Bool); -final _CloseType closeFn = +final _CloseType _closeFn = _dylib.lookupFunction<_close_type, _CloseType>('Close'); typedef _TessellateType = ffi.Pointer<_Vertices> Function( diff --git a/engine/src/flutter/tools/gen_web_locale_keymap/pubspec.yaml b/engine/src/flutter/tools/gen_web_locale_keymap/pubspec.yaml index e7987d6338..888b500292 100644 --- a/engine/src/flutter/tools/gen_web_locale_keymap/pubspec.yaml +++ b/engine/src/flutter/tools/gen_web_locale_keymap/pubspec.yaml @@ -6,15 +6,30 @@ environment: dependencies: args: any - http: ^0.13.4 - path: ^1.8.1 + http: any + path: any meta: any -dev_dependencies: - test: ^1.21.1 - dependency_overrides: args: path: ../../../third_party/dart/third_party/pkg/args + async: + path: ../../../third_party/dart/third_party/pkg/async + collection: + path: ../../../third_party/dart/third_party/pkg/collection + http: + path: ../../../third_party/dart/third_party/pkg/http/pkgs/http + http_parser: + path: ../../../third_party/dart/third_party/pkg/http_parser meta: path: ../../../third_party/dart/pkg/meta + path: + path: ../../../third_party/dart/third_party/pkg/path + source_span: + path: ../../../third_party/dart/third_party/pkg/source_span + string_scanner: + path: ../../../third_party/dart/third_party/pkg/string_scanner + term_glyph: + path: ../../../third_party/dart/third_party/pkg/term_glyph + typed_data: + path: ../../../third_party/dart/third_party/pkg/typed_data diff --git a/engine/src/flutter/tools/pub_get_offline.py b/engine/src/flutter/tools/pub_get_offline.py index 8efd6efec2..e0fec55bde 100644 --- a/engine/src/flutter/tools/pub_get_offline.py +++ b/engine/src/flutter/tools/pub_get_offline.py @@ -20,78 +20,123 @@ SRC_ROOT = os.path.dirname( ENGINE_DIR = os.path.join(SRC_ROOT, 'flutter') ALL_PACKAGES = [ - os.path.join(ENGINE_DIR, "ci"), - os.path.join(ENGINE_DIR, "impeller", "golden_tests_harvester"), - os.path.join(ENGINE_DIR, "flutter_frontend_server"), - os.path.join(ENGINE_DIR, "shell", "vmservice"), - os.path.join(ENGINE_DIR, "testing", "benchmark"), - os.path.join(ENGINE_DIR, "testing", "dart"), - os.path.join(ENGINE_DIR, "testing", "litetest"), - os.path.join(ENGINE_DIR, "testing", "android_background_image"), - os.path.join(ENGINE_DIR, "testing", "scenario_app"), - os.path.join(ENGINE_DIR, "testing", "smoke_test_failure"), - os.path.join(ENGINE_DIR, "testing", "symbols"), - os.path.join(ENGINE_DIR, "tools", "api_check"), - os.path.join(ENGINE_DIR, "tools", "android_lint"), - os.path.join(ENGINE_DIR, "tools", "clang_tidy"), - os.path.join(ENGINE_DIR, "tools", "const_finder"), - os.path.join(ENGINE_DIR, "tools", "pkg", "engine_repo_tools"), - os.path.join(ENGINE_DIR, "tools", "githooks"), - os.path.join(ENGINE_DIR, "tools", "licenses"), - os.path.join(ENGINE_DIR, "tools", "path_ops", "dart") + os.path.join(ENGINE_DIR, 'ci'), + os.path.join(ENGINE_DIR, 'flutter_frontend_server'), + os.path.join(ENGINE_DIR, 'impeller', 'golden_tests_harvester'), + os.path.join(ENGINE_DIR, 'impeller', 'tessellator', 'dart'), + os.path.join(ENGINE_DIR, 'shell', 'vmservice'), + os.path.join(ENGINE_DIR, 'testing', 'android_background_image'), + os.path.join(ENGINE_DIR, 'testing', 'benchmark'), + os.path.join(ENGINE_DIR, 'testing', 'dart'), + os.path.join(ENGINE_DIR, 'testing', 'litetest'), + os.path.join(ENGINE_DIR, 'testing', 'scenario_app'), + os.path.join(ENGINE_DIR, 'testing', 'skia_gold_client'), + os.path.join(ENGINE_DIR, 'testing', 'smoke_test_failure'), + os.path.join(ENGINE_DIR, 'testing', 'symbols'), + os.path.join(ENGINE_DIR, 'tools', 'android_lint'), + os.path.join(ENGINE_DIR, 'tools', 'api_check'), + os.path.join(ENGINE_DIR, 'tools', 'clang_tidy'), + os.path.join(ENGINE_DIR, 'tools', 'const_finder'), + os.path.join(ENGINE_DIR, 'tools', 'gen_web_locale_keymap'), + os.path.join(ENGINE_DIR, 'tools', 'githooks'), + os.path.join(ENGINE_DIR, 'tools', 'licenses'), + os.path.join(ENGINE_DIR, 'tools', 'path_ops', 'dart'), + os.path.join(ENGINE_DIR, 'tools', 'pkg', 'engine_repo_tools'), ] -def FetchPackage(pub, package): +def fetch_package(pub, package): try: subprocess.check_output(pub, cwd=package, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: print( - "'%s' failed in '%s' with status %d:\n%s" % + '"%s" failed in "%s" with status %d:\n%s' % (' '.join(pub), package, err.returncode, err.output) ) return 1 return 0 -def CheckPackage(package): - package_config = os.path.join(package, ".dart_tool", "package_config.json") +def check_package(package): + package_config = os.path.join(package, '.dart_tool', 'package_config.json') pub_count = 0 - with open(package_config) as f: - data_dict = json.load(f) - packages_data = data_dict["packages"] + with open(package_config) as config_file: + data_dict = json.load(config_file) + packages_data = data_dict['packages'] for package_data in packages_data: - package_uri = package_data["rootUri"] - package_name = package_data["name"] - if ".pub-cache" in package_uri and "pub.dartlang.org" in package_uri: - print("Error: package '%s' was fetched from pub" % package_name) + package_uri = package_data['rootUri'] + package_name = package_data['name'] + if '.pub-cache' in package_uri and 'pub.dartlang.org' in package_uri: + print('Error: package "%s" was fetched from pub' % package_name) pub_count = pub_count + 1 if pub_count > 0: print( - "Error: %d packages were fetched from pub for %s" % + 'Error: %d packages were fetched from pub for %s' % (pub_count, package) ) print( - "Please fix the pubspec.yaml for %s " - "so that all dependencies are path dependencies" % package + 'Please fix the pubspec.yaml for %s ' + 'so that all dependencies are path dependencies' % package ) return pub_count -def Main(): +EXCLUDED_DIRS = [ + os.path.join(ENGINE_DIR, 'lib'), + os.path.join(ENGINE_DIR, 'prebuilts'), + os.path.join(ENGINE_DIR, 'shell', 'platform', 'fuchsia'), + os.path.join(ENGINE_DIR, 'shell', 'vmservice'), + os.path.join(ENGINE_DIR, 'sky', 'packages'), + os.path.join(ENGINE_DIR, 'third_party'), + os.path.join(ENGINE_DIR, 'web_sdk'), +] + + +# Returns a list of paths to directories containing pubspec.yaml files that +# are not listed in ALL_PACKAGES. Directory trees under the paths in +# EXCLUDED_DIRS are skipped. +def find_unlisted_packages(): + unlisted = [] + for root, dirs, files in os.walk(ENGINE_DIR): + excluded = [] + for dirname in dirs: + full_dirname = os.path.join(root, dirname) + if full_dirname in EXCLUDED_DIRS: + excluded.append(dirname) + for exclude in excluded: + dirs.remove(exclude) + for filename in files: + if filename == 'pubspec.yaml': + if root not in ALL_PACKAGES: + unlisted.append(root) + return unlisted + + +def main(): dart_sdk_bin = os.path.join( - SRC_ROOT, "third_party", "dart", "tools", "sdks", "dart-sdk", "bin" + SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin' ) - dart = "dart" - if os.name == "nt": - dart = "dart.exe" - pubcmd = [os.path.join(dart_sdk_bin, dart), "pub", "get", "--offline"] + + # Ensure all relevant packages are listed in ALL_PACKAGES. + unlisted = find_unlisted_packages() + if len(unlisted) > 0: + for pkg in unlisted: + print( + 'The Dart package "%s" must be checked in flutter/tools/pub_get_offline.py' + % pkg + ) + return 1 + + dart = 'dart' + if os.name == 'nt': + dart = 'dart.exe' + pubcmd = [os.path.join(dart_sdk_bin, dart), 'pub', 'get', '--offline'] pub_count = 0 for package in ALL_PACKAGES: - if FetchPackage(pubcmd, package) != 0: + if fetch_package(pubcmd, package) != 0: return 1 - pub_count = pub_count + CheckPackage(package) + pub_count = pub_count + check_package(package) if pub_count > 0: return 1 @@ -100,4 +145,4 @@ def Main(): if __name__ == '__main__': - sys.exit(Main()) + sys.exit(main())