From b94e759b256819fb33cb9d2b41565fc137cac733 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 30 Jan 2019 16:22:45 -0800 Subject: [PATCH] Expose the Flutter engine, Dart and Skia versions to Dart. (#7634) - Moved versions from shell to common - versions singleton contains all the required versions. --- ci/licenses_golden/licenses_flutter | 7 +++-- {shell => common}/version/BUILD.gn | 6 ++--- {shell => common}/version/version.cc | 12 ++++----- {shell => common}/version/version.gni | 24 ++++++++--------- {shell => common}/version/version.h | 10 ++++---- lib/ui/BUILD.gn | 3 +++ lib/ui/dart_ui.cc | 2 ++ lib/ui/dart_ui.gni | 1 + lib/ui/ui.dart | 1 + lib/ui/versions.cc | 31 ++++++++++++++++++++++ lib/ui/versions.dart | 37 +++++++++++++++++++++++++++ lib/ui/versions.h | 21 +++++++++++++++ shell/common/BUILD.gn | 2 +- shell/common/engine.cc | 1 + shell/common/persistent_cache.cc | 2 +- shell/common/switches.cc | 9 ++++--- testing/dart/versions_test.dart | 35 +++++++++++++++++++++++++ 17 files changed, 170 insertions(+), 34 deletions(-) rename {shell => common}/version/BUILD.gn (67%) rename {shell => common}/version/version.cc (60%) rename {shell => common}/version/version.gni (68%) rename {shell => common}/version/version.h (61%) create mode 100644 lib/ui/versions.cc create mode 100644 lib/ui/versions.dart create mode 100644 lib/ui/versions.h create mode 100644 testing/dart/versions_test.dart diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 4df1c866548c1..f917817ff677e 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -23,6 +23,8 @@ FILE: ../../../flutter/common/settings.cc FILE: ../../../flutter/common/settings.h FILE: ../../../flutter/common/task_runners.cc FILE: ../../../flutter/common/task_runners.h +FILE: ../../../flutter/common/version/version.cc +FILE: ../../../flutter/common/version/version.h FILE: ../../../flutter/flow/compositor_context.cc FILE: ../../../flutter/flow/compositor_context.h FILE: ../../../flutter/flow/debug_print.cc @@ -307,6 +309,9 @@ FILE: ../../../flutter/lib/ui/text/text_box.h FILE: ../../../flutter/lib/ui/ui.dart FILE: ../../../flutter/lib/ui/ui_dart_state.cc FILE: ../../../flutter/lib/ui/ui_dart_state.h +FILE: ../../../flutter/lib/ui/versions.cc +FILE: ../../../flutter/lib/ui/versions.dart +FILE: ../../../flutter/lib/ui/versions.h FILE: ../../../flutter/lib/ui/window.dart FILE: ../../../flutter/lib/ui/window/platform_message.cc FILE: ../../../flutter/lib/ui/window/platform_message.h @@ -570,8 +575,6 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_surface_software.h FILE: ../../../flutter/shell/platform/embedder/fixtures/simple_main.dart FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h -FILE: ../../../flutter/shell/version/version.cc -FILE: ../../../flutter/shell/version/version.h FILE: ../../../flutter/sky/packages/flutter_services/lib/empty.dart FILE: ../../../flutter/sky/tools/roll/patches/chromium/android_build.patch FILE: ../../../flutter/synchronization/pipeline.cc diff --git a/shell/version/BUILD.gn b/common/version/BUILD.gn similarity index 67% rename from shell/version/BUILD.gn rename to common/version/BUILD.gn index ca9ee7d1bf84e..d34928de8afaa 100644 --- a/shell/version/BUILD.gn +++ b/common/version/BUILD.gn @@ -11,9 +11,9 @@ source_set("version") { ] defines = [ - "SHELL_FLUTTER_ENGINE_VERSION=\"$shell_engine_version\"", - "SHELL_SKIA_VERSION=\"$shell_skia_version\"", - "SHELL_DART_VERSION=\"$shell_dart_version\"", + "FLUTTER_ENGINE_VERSION=\"$engine_version\"", + "SKIA_VERSION=\"$skia_version\"", + "DART_VERSION=\"$dart_version\"", ] public_configs = [ "$flutter_root:config" ] diff --git a/shell/version/version.cc b/common/version/version.cc similarity index 60% rename from shell/version/version.cc rename to common/version/version.cc index 4fac6a1043c92..e1d1c57d3baa8 100644 --- a/shell/version/version.cc +++ b/common/version/version.cc @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/version/version.h" +#include "flutter/common/version/version.h" -namespace shell { +namespace blink { const char* GetFlutterEngineVersion() { - return SHELL_FLUTTER_ENGINE_VERSION; + return FLUTTER_ENGINE_VERSION; } const char* GetSkiaVersion() { - return SHELL_SKIA_VERSION; + return SKIA_VERSION; } const char* GetDartVersion() { - return SHELL_DART_VERSION; + return DART_VERSION; } -} // namespace shell +} // namespace blink diff --git a/shell/version/version.gni b/common/version/version.gni similarity index 68% rename from shell/version/version.gni rename to common/version/version.gni index f06a89b8d555f..a4520c410006c 100644 --- a/shell/version/version.gni +++ b/common/version/version.gni @@ -3,42 +3,42 @@ # found in the LICENSE file. declare_args() { - shell_engine_version = "" + engine_version = "" - shell_skia_version = "" + skia_version = "" - shell_dart_version = "" + dart_version = "" } -if (shell_engine_version == "") { - shell_engine_version_lines = +if (engine_version == "") { + engine_version_lines = exec_script("$flutter_root/build/git_revision.py", [ "--repository", rebase_path(flutter_root, "", flutter_root), ], "list lines") - shell_engine_version = shell_engine_version_lines[0] + engine_version = engine_version_lines[0] } -if (shell_skia_version == "") { - shell_skia_version_lines = +if (skia_version == "") { + skia_version_lines = exec_script("$flutter_root/build/git_revision.py", [ "--repository", rebase_path("//third_party/skia", "", flutter_root), ], "list lines") - shell_skia_version = shell_skia_version_lines[0] + skia_version = skia_version_lines[0] } -if (shell_dart_version == "") { - shell_dart_version_lines = +if (dart_version == "") { + dart_version_lines = exec_script("$flutter_root/build/git_revision.py", [ "--repository", rebase_path("//third_party/dart", "", flutter_root), ], "list lines") - shell_dart_version = shell_dart_version_lines[0] + dart_version = dart_version_lines[0] } diff --git a/shell/version/version.h b/common/version/version.h similarity index 61% rename from shell/version/version.h rename to common/version/version.h index ce2647e0bddb6..d9ca8aa3f17e3 100644 --- a/shell/version/version.h +++ b/common/version/version.h @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_COMMON_VERSION_H_ -#define FLUTTER_SHELL_COMMON_VERSION_H_ +#ifndef FLUTTER_COMMON_VERSION_VERSION_H_ +#define FLUTTER_COMMON_VERSION_VERSION_H_ -namespace shell { +namespace blink { const char* GetFlutterEngineVersion(); @@ -13,6 +13,6 @@ const char* GetSkiaVersion(); const char* GetDartVersion(); -} // namespace shell +} // namespace blink -#endif // FLUTTER_SHELL_COMMON_VERSION_H_ +#endif // FLUTTER_COMMON_VERSION_VERSION_H_ diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index 940b377bad8de..cba7632ce0b60 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -83,6 +83,8 @@ source_set("ui") { "text/text_box.h", "ui_dart_state.cc", "ui_dart_state.h", + "versions.cc", + "versions.h", "window/platform_message.cc", "window/platform_message.h", "window/platform_message_response.cc", @@ -104,6 +106,7 @@ source_set("ui") { deps = [ "$flutter_root/assets", "$flutter_root/common", + "$flutter_root/common/version", "$flutter_root/flow", "$flutter_root/fml", "$flutter_root/runtime:test_font", diff --git a/lib/ui/dart_ui.cc b/lib/ui/dart_ui.cc index 7256a183cb2e8..f6aa54c1cb946 100644 --- a/lib/ui/dart_ui.cc +++ b/lib/ui/dart_ui.cc @@ -27,6 +27,7 @@ #include "flutter/lib/ui/text/font_collection.h" #include "flutter/lib/ui/text/paragraph.h" #include "flutter/lib/ui/text/paragraph_builder.h" +#include "flutter/lib/ui/versions.h" #include "flutter/lib/ui/window/window.h" #include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/logging/dart_error.h" @@ -87,6 +88,7 @@ void DartUI::InitForGlobal() { SceneHost::RegisterNatives(g_natives); SemanticsUpdate::RegisterNatives(g_natives); SemanticsUpdateBuilder::RegisterNatives(g_natives); + Versions::RegisterNatives(g_natives); Vertices::RegisterNatives(g_natives); Window::RegisterNatives(g_natives); diff --git a/lib/ui/dart_ui.gni b/lib/ui/dart_ui.gni index c52a9f025f231..67246f6ef8498 100644 --- a/lib/ui/dart_ui.gni +++ b/lib/ui/dart_ui.gni @@ -16,6 +16,7 @@ dart_ui_files = [ "$flutter_root/lib/ui/semantics.dart", "$flutter_root/lib/ui/text.dart", "$flutter_root/lib/ui/ui.dart", + "$flutter_root/lib/ui/versions.dart", "$flutter_root/lib/ui/window.dart", ] diff --git a/lib/ui/ui.dart b/lib/ui/ui.dart index cef4db81cee0e..5730f4e1378fa 100644 --- a/lib/ui/ui.dart +++ b/lib/ui/ui.dart @@ -34,4 +34,5 @@ part 'plugins.dart'; part 'pointer.dart'; part 'semantics.dart'; part 'text.dart'; +part 'versions.dart'; part 'window.dart'; diff --git a/lib/ui/versions.cc b/lib/ui/versions.cc new file mode 100644 index 0000000000000..37c18613240c8 --- /dev/null +++ b/lib/ui/versions.cc @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/lib/ui/versions.h" +#include "flutter/common/version/version.h" +#include "third_party/tonic/converter/dart_converter.h" +#include "third_party/tonic/dart_library_natives.h" + +#include +#include + +using tonic::DartConverter; + +namespace blink { + +// returns a vector with 3 versions. +// Dart, Skia and Flutter engine versions in this order. +void GetVersions(Dart_NativeArguments args) { + const std::vector versions_list = { + GetDartVersion(), GetSkiaVersion(), GetFlutterEngineVersion()}; + Dart_Handle dart_val = + DartConverter>::ToDart(versions_list); + Dart_SetReturnValue(args, dart_val); +} + +void Versions::RegisterNatives(tonic::DartLibraryNatives* natives) { + natives->Register({{"Versions_getVersions", GetVersions, 1, true}}); +} + +} // namespace blink diff --git a/lib/ui/versions.dart b/lib/ui/versions.dart new file mode 100644 index 0000000000000..9121234856082 --- /dev/null +++ b/lib/ui/versions.dart @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +part of dart.ui; + +/// Wraps version information for Dart, Skia and Flutter. +class Versions { + + /// Builds a versions object using the information + /// we get from calling the native getVersions. + factory Versions._internal() { + final List versions = _getVersions(); + return Versions._(versions[0], versions[1], versions[2]); + } + + /// Private constructor to capture the versions. + Versions._( + this.dartVersion, + this.skiaVersion, + this.flutterEngineVersion + ) : assert(dartVersion != null), + assert(skiaVersion != null), + assert(flutterEngineVersion != null); + + /// returns a vector with 3 versions. + /// Dart, Skia and Flutter engine versions in this order. + static List _getVersions() native 'Versions_getVersions'; + + final String dartVersion; + final String skiaVersion; + final String flutterEngineVersion; +} + +/// [Versions] singleton. This object exposes Dart, Skia and +/// Flutter engine versions. +final Versions versions = Versions._internal(); diff --git a/lib/ui/versions.h b/lib/ui/versions.h new file mode 100644 index 0000000000000..84737e5eb68e6 --- /dev/null +++ b/lib/ui/versions.h @@ -0,0 +1,21 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_LIB_UI_VERSIONS_H_ +#define FLUTTER_LIB_UI_VERSIONS_H_ + +namespace tonic { +class DartLibraryNatives; +} // namespace tonic + +namespace blink { + +class Versions final { + public: + static void RegisterNatives(tonic::DartLibraryNatives* natives); +}; + +} // namespace blink + +#endif // FLUTTER_LIB_UI_VERSIONS_H_ diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index c17dd8b60bd39..aa22968662c3b 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -105,7 +105,7 @@ source_set("common") { ] public_deps = [ - "$flutter_root/shell/version", + "$flutter_root/common/version", "$flutter_root/third_party/txt", "//third_party/rapidjson", "//third_party/tonic", diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 4e084fa9079c7..c0aec58ee9900 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -10,6 +10,7 @@ #include #include "flutter/common/settings.h" +#include "flutter/common/version/version.h" #include "flutter/fml/eintr_wrapper.h" #include "flutter/fml/file.h" #include "flutter/fml/make_copyable.h" diff --git a/shell/common/persistent_cache.cc b/shell/common/persistent_cache.cc index d6d027ffab25e..95d2b6f9ecfab 100644 --- a/shell/common/persistent_cache.cc +++ b/shell/common/persistent_cache.cc @@ -7,13 +7,13 @@ #include #include +#include "flutter/common/version/version.h" #include "flutter/fml/base32.h" #include "flutter/fml/file.h" #include "flutter/fml/make_copyable.h" #include "flutter/fml/mapping.h" #include "flutter/fml/paths.h" #include "flutter/fml/trace_event.h" -#include "flutter/shell/version/version.h" namespace shell { diff --git a/shell/common/switches.cc b/shell/common/switches.cc index 5b4f1abe2d566..dc25956fca9d6 100644 --- a/shell/common/switches.cc +++ b/shell/common/switches.cc @@ -9,10 +9,10 @@ #include #include +#include "flutter/common/version/version.h" #include "flutter/fml/native_library.h" #include "flutter/fml/paths.h" #include "flutter/fml/string_view.h" -#include "flutter/shell/version/version.h" // Include once for the default enum definition. #include "flutter/shell/common/switches.h" @@ -46,11 +46,12 @@ void PrintUsage(const std::string& executable_name) { std::cerr << "Versions: " << std::endl << std::endl; - std::cerr << "Flutter Engine Version: " << GetFlutterEngineVersion() + std::cerr << "Flutter Engine Version: " << blink::GetFlutterEngineVersion() << std::endl; - std::cerr << "Skia Version: " << GetSkiaVersion() << std::endl; + std::cerr << "Skia Version: " << blink::GetSkiaVersion() << std::endl; - std::cerr << "Dart Version: " << GetDartVersion() << std::endl << std::endl; + std::cerr << "Dart Version: " << blink::GetDartVersion() << std::endl + << std::endl; std::cerr << "Available Flags:" << std::endl; diff --git a/testing/dart/versions_test.dart b/testing/dart/versions_test.dart new file mode 100644 index 0000000000000..4de21ef252966 --- /dev/null +++ b/testing/dart/versions_test.dart @@ -0,0 +1,35 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// HACK: pretend to be dart.ui in order to access its internals +library dart.ui; + +import 'package:test/test.dart'; + +part '../../lib/ui/versions.dart'; + +bool _isNotEmpty(String s) { + if (s == null || s.isEmpty) { + return false; + } else { + return true; + } +} + +void main() { + test('dartVersion should not be empty', () { + final String dartVersion = versions.dartVersion; + expect(_isNotEmpty(dartVersion), equals(true)); + }); + + test('skiaVersion should not be empty', () { + final String skiaVersion = versions.skiaVersion; + expect(_isNotEmpty(skiaVersion), equals(true)); + }); + + test('flutterEngineVersion should not be empty', () { + final String flutterEngineVersion = versions.flutterEngineVersion; + expect(_isNotEmpty(flutterEngineVersion), equals(true)); + }); +}