From 31c2122769b9d8c58c6607b250aa066643fc029d Mon Sep 17 00:00:00 2001 From: keminLuo <541416002@qq.com> Date: Mon, 15 Jan 2024 23:39:25 -0800 Subject: [PATCH] =?UTF-8?q?C++=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=92=8Cdart=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E9=B8=BF?= =?UTF-8?q?=E8=92=99=E5=8C=96=20Signed-off-by:=20=E7=BD=97=E9=94=AE?= =?UTF-8?q?=E9=93=AD=20<541416002@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BUILD.gn | 14 ++- attachment/repos/angle.patch | 79 ++++++++++++- attachment/repos/bootstrap/ohos.py | 11 +- attachment/repos/build.patch | 44 +++---- attachment/repos/dart.patch2 | 14 +++ attachment/repos/swiftshader.patch | 110 ++++++++++++++++++ attachment/scripts/config.json | 6 + attachment/scripts/config_pre.json | 6 + .../performance_overlay_layer_unittests.cc | 2 +- fml/BUILD.gn | 14 +++ fml/logging.cc | 4 +- fml/logging_unittests.cc | 2 + fml/memory/task_runner_checker_unittest.cc | 6 + fml/memory/weak_ptr_unittest.cc | 3 + fml/message_loop_impl_unittests.cc | 6 +- impeller/tools/impeller.gni | 2 +- lib/ui/BUILD.gn | 34 ++++-- runtime/BUILD.gn | 16 +++ runtime/dart_isolate_unittests.cc | 34 ++++++ shell/common/BUILD.gn | 19 ++- shell/config.gni | 2 +- shell/gpu/gpu_surface_vulkan.cc | 4 + shell/platform/embedder/BUILD.gn | 2 +- testing/testing.gni | 7 +- third_party/tonic/tests/BUILD.gn | 11 ++ .../tonic/tests/dart_state_unittest.cc | 3 + third_party/txt/BUILD.gn | 4 + tools/clang_tidy/lib/src/git_repo.dart | 6 +- tools/gn | 6 +- vulkan/vulkan_window.cc | 4 + 30 files changed, 407 insertions(+), 68 deletions(-) create mode 100755 attachment/repos/swiftshader.patch diff --git a/BUILD.gn b/BUILD.gn index 7a102d594b..837d70d1ef 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -152,9 +152,6 @@ group("unittests") { "//flutter/runtime:no_dart_plugin_registrant_unittests", "//flutter/runtime:runtime_unittests", "//flutter/shell/common:shell_unittests", - "//flutter/shell/platform/embedder:embedder_a11y_unittests", - "//flutter/shell/platform/embedder:embedder_proctable_unittests", - "//flutter/shell/platform/embedder:embedder_unittests", "//flutter/testing:testing_unittests", "//flutter/testing/dart", "//flutter/testing/smoke_test_failure", @@ -162,6 +159,15 @@ group("unittests") { "//flutter/third_party/txt:txt_unittests", ] + # ohos does not support vulkan + if (!is_ohos) { + public_deps += [ + "//flutter/shell/platform/embedder:embedder_a11y_unittests", + "//flutter/shell/platform/embedder:embedder_proctable_unittests", + "//flutter/shell/platform/embedder:embedder_unittests", + ] + } + # The accessibility library only supports Mac and Windows at the moment. if (is_mac || is_win) { public_deps += @@ -181,7 +187,7 @@ group("unittests") { [ "//flutter/shell/platform/darwin:flutter_channels_unittests" ] } - if (!is_win && !is_fuchsia) { + if (!is_win && !is_fuchsia && !is_ohos) { public_deps += [ "//flutter/shell/platform/android/external_view_embedder:android_external_view_embedder_unittests", "//flutter/shell/platform/android/jni:jni_unittests", diff --git a/attachment/repos/angle.patch b/attachment/repos/angle.patch index e4a0952dd4..1b12c9d2b9 100644 --- a/attachment/repos/angle.patch +++ b/attachment/repos/angle.patch @@ -1,8 +1,19 @@ diff --git a/BUILD.gn b/BUILD.gn -index efaf09033..73af49870 100644 +index efaf09033..7c65c83ca 100644 --- a/BUILD.gn +++ b/BUILD.gn -@@ -83,7 +83,7 @@ if (angle_build_all) { +@@ -11,7 +11,9 @@ if (angle_use_wayland) { + import("//build_overrides/wayland.gni") + } + if (angle_has_build) { +- import("//build/config/linux/pkg_config.gni") ++ if (!is_ohos) { ++ import("//build/config/linux/pkg_config.gni") ++ } + import("//build/config/sanitizers/sanitizers.gni") + import("//build/config/ui.gni") + import("//testing/libfuzzer/fuzzer_test.gni") +@@ -83,7 +85,7 @@ if (angle_build_all) { ":translator_fuzzer", ":xxhash_fuzzer", "$angle_root/samples:angle_samples", @@ -11,7 +22,25 @@ index efaf09033..73af49870 100644 ] if (angle_enable_cl) { deps += [ "$angle_root/src/libOpenCL:angle_cl" ] -@@ -486,7 +486,8 @@ angle_static_library("angle_image_util") { +@@ -141,7 +143,7 @@ config("internal_config") { + if (angle_is_winuwp) { + defines += [ "ANGLE_IS_WINUWP" ] + } +- } else if (is_linux || is_chromeos) { ++ } else if (is_linux || is_chromeos || is_ohos) { + defines += [ "ANGLE_IS_LINUX" ] + } + +@@ -443,7 +445,7 @@ angle_static_library("angle_common") { + all_dependent_configs = [ ":angle_disable_pool_alloc" ] + } + +- if (is_linux || is_chromeos) { ++ if (is_linux || is_chromeos || is_ohos) { + libs = [ "dl" ] + } + +@@ -486,7 +488,8 @@ angle_static_library("angle_image_util") { sources = libangle_image_util_sources public_configs += [ ":angle_image_util_config" ] public_deps = [ ":angle_image_util_headers" ] @@ -21,6 +50,15 @@ index efaf09033..73af49870 100644 if (angle_has_astc_encoder) { public_deps += [ "third_party/astc-encoder:astcenc" ] include_dirs = [ "third_party/astc-encoder/src/Source/" ] +@@ -561,7 +564,7 @@ angle_static_library("angle_gpu_info_util") { + libs += [ "dxgi.lib" ] + } + +- if (is_linux || is_chromeos) { ++ if (is_linux || is_chromeos || is_ohos) { + sources += libangle_gpu_info_util_linux_sources + + if (angle_use_x11 && angle_has_build) { diff --git a/gni/angle.gni b/gni/angle.gni index b8086660a..d82d056d6 100644 --- a/gni/angle.gni @@ -124,3 +162,38 @@ index d67bd812b..00d22d025 100644 struct SpirvIdAndIdList { spirv::IdRef id; +diff --git a/src/libANGLE/renderer/gl/BUILD.gn b/src/libANGLE/renderer/gl/BUILD.gn +index c675c2607..6cba114ef 100644 +--- a/src/libANGLE/renderer/gl/BUILD.gn ++++ b/src/libANGLE/renderer/gl/BUILD.gn +@@ -125,7 +125,7 @@ if (angle_use_x11) { + ] + } + +-if (is_android || is_linux || is_chromeos) { ++if (is_android || is_linux || is_chromeos || is_ohos) { + _gl_backend_sources += [ + "egl/ContextEGL.cpp", + "egl/ContextEGL.h", +@@ -264,7 +264,7 @@ angle_source_set("angle_gl_backend") { + "Xext", + ] + } +- if (is_android || is_linux || is_chromeos) { ++ if (is_android || is_linux || is_chromeos || is_ohos) { + deps += [ "$angle_root/src/common/linux:angle_dma_buf" ] + } + if (is_apple) { +diff --git a/src/libGLESv2.gni b/src/libGLESv2.gni +index 723d7f99f..dab8b887c 100644 +--- a/src/libGLESv2.gni ++++ b/src/libGLESv2.gni +@@ -87,7 +87,7 @@ xxhash_sources = [ + "src/common/third_party/xxhash/xxhash.h", + ] + +-if (is_linux || is_chromeos || is_android || is_fuchsia) { ++if (is_linux || is_chromeos || is_android || is_fuchsia || is_ohos) { + libangle_common_sources += [ + "src/common/system_utils_linux.cpp", + "src/common/system_utils_posix.cpp", diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 7a1c796b4e..32d2dc46e0 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -164,7 +164,7 @@ def getNdkHome(): # 指定engine编译的配置参数 -def engineConfig(buildInfo, extraParam=""): +def engineConfig(buildInfo, extraParam=[]): OHOS_NDK_HOME = getNdkHome() # export PATH=$OHOS_NDK_HOME/build-tools/cmake/bin:$OHOS_NDK_HOME/llvm/bin:$PATH lastPath = os.getenv("PATH") @@ -182,6 +182,9 @@ def engineConfig(buildInfo, extraParam=""): + "--target-triple %s " % buildInfo.targetTriple ) OPT = "--unoptimized --no-lto " if buildInfo.buildType == "debug" else "" + extraStr = '' + for param in extraParam: + extraStr += param.replace("\\", "") + " " runCommand( "%s " % os.path.join("src", "flutter", "tools", "gn") + "--ohos " @@ -195,7 +198,7 @@ def engineConfig(buildInfo, extraParam=""): + "--disable-desktop-embeddings " + "--no-build-embedder-examples " + "--verbose " - + extraParam.replace("\\", ""), + + extraStr, checkCode=False, timeout=600, ) @@ -347,8 +350,8 @@ def addParseParam(parser): parser.add_argument( "-g", "--gn-extra-param", - nargs="?", - default="", + nargs="+", + default=[], help='Extra param to src/flutter/tools/gn. Such as: -g "\\--enable-unittests"', ) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c3df91e35f..2fa0be2694 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -12,18 +12,10 @@ index 4e62965..ea49a53 100644 libs = [ "dl" ] } diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn -index b8d0f47..d789796 100644 +index b8d0f47..a3d1ed9 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn -@@ -34,6 +34,7 @@ - # When writing build files, to do something only for the host: - # if (current_toolchain == host_toolchain) { ... - -+ - if (target_os == "") { - target_os = host_os - } -@@ -190,6 +191,7 @@ if (current_os == "win") { +@@ -190,6 +190,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -31,7 +23,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = true -@@ -198,6 +200,7 @@ if (current_os == "win") { +@@ -198,6 +199,7 @@ if (current_os == "win") { is_android = false is_chromeos = false is_fuchsia = false @@ -39,7 +31,7 @@ index b8d0f47..d789796 100644 is_fuchsia_host = false is_ios = false is_linux = false -@@ -212,6 +215,7 @@ if (current_os == "win") { +@@ -212,6 +214,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -47,7 +39,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -223,6 +227,7 @@ if (current_os == "win") { +@@ -223,6 +226,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -55,7 +47,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -237,6 +242,7 @@ if (current_os == "win") { +@@ -237,6 +241,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -63,7 +55,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -248,6 +254,19 @@ if (current_os == "win") { +@@ -248,6 +253,19 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = true is_linux = false @@ -83,7 +75,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -259,6 +278,7 @@ if (current_os == "win") { +@@ -259,6 +277,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -91,7 +83,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -270,6 +290,7 @@ if (current_os == "win") { +@@ -270,6 +289,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -99,7 +91,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -281,6 +302,7 @@ if (current_os == "win") { +@@ -281,6 +301,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -107,7 +99,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = false -@@ -313,7 +335,7 @@ if (!is_clang && using_sanitizer) { +@@ -313,7 +334,7 @@ if (!is_clang && using_sanitizer) { is_clang = true } @@ -116,18 +108,18 @@ index b8d0f47..d789796 100644 if (is_msan && !is_linux) { assert(false, "Memory sanitizer is only available on Linux.") -@@ -365,7 +387,9 @@ if (is_posix) { +@@ -365,7 +386,9 @@ if (is_posix) { ] } -if (is_linux) { -+if(is_ohos || (is_linux && host_os == "mac")){ ++if (is_ohos || (is_linux && host_os == "mac")) { + _native_compiler_configs += [ "//build/config/ohos:sdk" ] -+ }else if (is_linux) { ++} else if (is_linux) { _native_compiler_configs += [ "//build/config/linux:sdk" ] } else if (is_mac) { _native_compiler_configs += [ "//build/config/mac:sdk" ] -@@ -510,8 +534,18 @@ shlib_toolchain = false +@@ -510,8 +533,18 @@ shlib_toolchain = false if (custom_toolchain != "") { assert(custom_sysroot != "") assert(custom_target_triple != "") @@ -147,22 +139,20 @@ index b8d0f47..d789796 100644 } else if (is_win) { if (is_clang) { host_toolchain = "//build/toolchain/win:clang_$host_cpu" -@@ -544,6 +578,21 @@ if (custom_toolchain != "") { +@@ -544,6 +577,19 @@ if (custom_toolchain != "") { } else { set_default_toolchain("//build/toolchain/android:$current_cpu") } +} else if (is_ohos) { ++ set_default_toolchain("//build/toolchain/custom") + if (host_os == "linux") { + if (is_clang) { + host_toolchain = "//build/toolchain/linux:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:clang_$current_cpu") + } else { + host_toolchain = "//build/toolchain/linux:$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:$current_cpu") + } + } else if (host_os == "mac") { + host_toolchain = "//build/toolchain/mac:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/ohos:clang_$current_cpu") + } else { + assert(false, "Unknown host for ohos cross compile") + } diff --git a/attachment/repos/dart.patch2 b/attachment/repos/dart.patch2 index 853cce68f5..8ca3e2afb0 100644 --- a/attachment/repos/dart.patch2 +++ b/attachment/repos/dart.patch2 @@ -238,3 +238,17 @@ index 7ac0322c01c..2f6b4990a9f 100644 va_end(args); } +diff --git a/runtime/vm/os_thread.cc b/runtime/vm/os_thread.cc +index d190c80eff7..e46459e9199 100644 +--- a/runtime/vm/os_thread.cc ++++ b/runtime/vm/os_thread.cc +@@ -53,7 +53,8 @@ OSThread::OSThread() + ASSERT(stack_base_ > stack_limit_); + ASSERT(stack_base_ > GetCurrentStackPointer()); + ASSERT(stack_limit_ < GetCurrentStackPointer()); +- RELEASE_ASSERT(HasStackHeadroom()); ++ // ohos temporary comments ++ // RELEASE_ASSERT(HasStackHeadroom()); + } + + OSThread* OSThread::CreateOSThread() { diff --git a/attachment/repos/swiftshader.patch b/attachment/repos/swiftshader.patch new file mode 100755 index 0000000000..2e8d995d55 --- /dev/null +++ b/attachment/repos/swiftshader.patch @@ -0,0 +1,110 @@ +diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn +index 676f99f1a..36a581f10 100644 +--- a/src/Reactor/BUILD.gn ++++ b/src/Reactor/BUILD.gn +@@ -95,7 +95,7 @@ if (supports_subzero) { + if (is_win) { + include_dirs += + [ "../../third_party/llvm-subzero/build/Windows/include/" ] +- } else if (is_linux || is_chromeos) { ++ } else if (is_linux || is_chromeos || is_ohos) { + include_dirs += [ "../../third_party/llvm-subzero/build/Linux/include/" ] + } else if (is_fuchsia) { + include_dirs += +@@ -328,7 +328,7 @@ if (supports_llvm) { + "$llvm_dir/configs/common/include/", + ] + +- if (is_linux || is_chromeos) { ++ if (is_linux || is_chromeos || is_ohos) { + include_dirs += [ "$llvm_dir/configs/linux/include/" ] + } else if (is_fuchsia) { + include_dirs += [ "$llvm_dir/configs/fuchsia/include/" ] +diff --git a/src/Reactor/reactor.gni b/src/Reactor/reactor.gni +index 04fad6f81..324003e35 100644 +--- a/src/Reactor/reactor.gni ++++ b/src/Reactor/reactor.gni +@@ -14,7 +14,7 @@ declare_args() { + } + + declare_args() { +- supports_llvm = is_linux || is_chromeos || is_fuchsia || is_win || is_android ++ supports_llvm = is_linux || is_chromeos || is_fuchsia || is_win || is_android || is_ohos + # LLVM uses C++17 features which require macOS 10.12, while Chrome's minimum platform for x86 is 10.11. + # Don't build LLVM on Mac, unless we have to. This only happens on ARM64 devices, which launched with 11.0. + # TODO(b/174843857): Remove check for !supports_subzero once Chrome supports macOS 10.12 +diff --git a/src/System/BUILD.gn b/src/System/BUILD.gn +index 6f61d9f76..bed58a57b 100644 +--- a/src/System/BUILD.gn ++++ b/src/System/BUILD.gn +@@ -29,7 +29,7 @@ swiftshader_source_set("System_headers") { + "SwiftConfig.hpp", + "Timer.hpp", + ] +- if (is_linux || is_chromeos || is_android) { ++ if (is_linux || is_chromeos || is_android || is_ohos) { + sources += [ + "Linux/MemFd.hpp", + ] +@@ -48,7 +48,7 @@ swiftshader_source_set("System") { + "SwiftConfig.cpp", + "Timer.cpp", + ] +- if (is_linux || is_chromeos || is_android) { ++ if (is_linux || is_chromeos || is_android || is_ohos) { + sources += [ + "Linux/MemFd.cpp", + ] +diff --git a/third_party/llvm-10.0/BUILD.gn b/third_party/llvm-10.0/BUILD.gn +index 6c40b2c00..6076f2bea 100644 +--- a/third_party/llvm-10.0/BUILD.gn ++++ b/third_party/llvm-10.0/BUILD.gn +@@ -100,7 +100,7 @@ llvm_include_dirs = [ + "configs/common/lib/Transforms/InstCombine/", + ] + +-if (is_linux || is_chromeos) { ++if (is_linux || is_chromeos || is_ohos) { + llvm_include_dirs += [ "configs/linux/include/" ] + } else if (is_fuchsia) { + llvm_include_dirs += [ "configs/fuchsia/include/" ] +diff --git a/third_party/marl/src/thread.cpp b/third_party/marl/src/thread.cpp +index 30897f020..80d5e2ee9 100644 +--- a/third_party/marl/src/thread.cpp ++++ b/third_party/marl/src/thread.cpp +@@ -154,14 +154,15 @@ Thread::Affinity Thread::Affinity::all( + auto thread = pthread_self(); + cpu_set_t cpuset; + CPU_ZERO(&cpuset); +- if (pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset) == 0) { +- int count = CPU_COUNT(&cpuset); +- for (int i = 0; i < count; i++) { +- Core core; +- core.pthread.index = static_cast(i); +- affinity.cores.emplace_back(std::move(core)); +- } +- } ++ // ohos does not suppot pthread_getaffinity_np ++ // if (pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset) == 0) { ++ // int count = CPU_COUNT(&cpuset); ++ // for (int i = 0; i < count; i++) { ++ // Core core; ++ // core.pthread.index = static_cast(i);affinity_np ++ // affinity.cores.emplace_back(std::move(core)); ++ // } ++ // } + #elif defined(__FreeBSD__) + auto thread = pthread_self(); + cpuset_t cpuset; +@@ -385,8 +386,9 @@ class Thread::Impl { + for (size_t i = 0; i < count; i++) { + CPU_SET(affinity[i].pthread.index, &cpuset); + } +- auto thread = pthread_self(); +- pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); ++ // ohos does not suppot pthread_setaffinity_np ++ // auto thread = pthread_self(); ++ // pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); + #elif defined(__FreeBSD__) + cpuset_t cpuset; + CPU_ZERO(&cpuset); diff --git a/attachment/scripts/config.json b/attachment/scripts/config.json index a1bef3cb13..b394a9cff3 100644 --- a/attachment/scripts/config.json +++ b/attachment/scripts/config.json @@ -57,5 +57,11 @@ "target": "./src/third_party/boringssl", "type": "patch", "file_path": "../../flutter/attachment/repos/boringssl.patch" + }, + { + "name": "swiftshader", + "target": "./src/third_party/swiftshader", + "type": "patch", + "file_path": "../../flutter/attachment/repos/swiftshader.patch" } ] diff --git a/attachment/scripts/config_pre.json b/attachment/scripts/config_pre.json index ff6eb88366..5bc00e1256 100644 --- a/attachment/scripts/config_pre.json +++ b/attachment/scripts/config_pre.json @@ -57,5 +57,11 @@ "target": "./src/third_party/boringssl", "type": "patch", "file_path": "../../flutter/attachment/repos/boringssl.patch" + }, + { + "name": "swiftshader", + "target": "./src/third_party/swiftshader", + "type": "patch", + "file_path": "../../flutter/attachment/repos/swiftshader.patch" } ] \ No newline at end of file diff --git a/flow/layers/performance_overlay_layer_unittests.cc b/flow/layers/performance_overlay_layer_unittests.cc index 7c2f1edbe8..65b991506b 100644 --- a/flow/layers/performance_overlay_layer_unittests.cc +++ b/flow/layers/performance_overlay_layer_unittests.cc @@ -97,7 +97,7 @@ static void TestPerformanceOverlayLayerGold(int refresh_rate) { // TODO(https://github.com/flutter/flutter/issues/53784): enable this on all // platforms. -#if !defined(FML_OS_LINUX) +#if !defined(FML_OS_LINUX) && !defined(FML_OS_OHOS) GTEST_SKIP() << "Skipping golden tests on non-Linux OSes"; #endif // FML_OS_LINUX const bool golden_data_matches = golden_data->equals(snapshot_data.get()); diff --git a/fml/BUILD.gn b/fml/BUILD.gn index ddcb7cb64b..f26932f1a1 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -257,6 +257,13 @@ source_set("fml") { "platform/posix/posix_wrappers_posix.cc", ] } + + if (!defined(defines)) { + defines = [] + } + if (enable_unittests && is_ohos) { + defines += [ "OHOS_USE_UNITTESTS" ] + } } source_set("build_config") { @@ -384,6 +391,13 @@ if (enable_unittests) { "//flutter/testing", ] + if (!defined(defines)) { + defines = [] + } + if (enable_unittests && is_ohos) { + defines += [ "OHOS_USE_UNITTESTS_SKIP" ] + } + # This is needed for //third_party/googletest for linking zircon symbols. if (is_fuchsia) { libs = diff --git a/fml/logging.cc b/fml/logging.cc index 84c465a1f8..3a48972b09 100644 --- a/fml/logging.cc +++ b/fml/logging.cc @@ -204,7 +204,9 @@ bool ShouldCreateLogMessage(LogSeverity severity) { } void KillProcess() { -#ifdef FML_OS_OHOS +#if defined(OHOS_USE_UNITTESTS) + abort(); +#elif defined(FML_OS_OHOS) HILOG_ERROR("FML KILL PROCESS"); #else abort(); diff --git a/fml/logging_unittests.cc b/fml/logging_unittests.cc index a64d33e52f..713159ca3d 100644 --- a/fml/logging_unittests.cc +++ b/fml/logging_unittests.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#pragma clang diagnostic ignored "-Wreturn-type" + #include "flutter/fml/build_config.h" #include "flutter/fml/log_settings.h" #include "flutter/fml/logging.h" diff --git a/fml/memory/task_runner_checker_unittest.cc b/fml/memory/task_runner_checker_unittest.cc index cd4de6d6e3..7d42a68ce8 100644 --- a/fml/memory/task_runner_checker_unittest.cc +++ b/fml/memory/task_runner_checker_unittest.cc @@ -23,6 +23,9 @@ TEST(TaskRunnerCheckerTests, RunsOnCurrentTaskRunner) { } TEST(TaskRunnerCheckerTests, FailsTheCheckIfOnDifferentTaskRunner) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "Something wrong in ohos libuv"; +#endif TaskRunnerChecker checker; EXPECT_EQ(checker.RunsOnCreationTaskRunner(), true); fml::MessageLoop* loop = nullptr; @@ -119,6 +122,9 @@ TEST(TaskRunnerCheckerTests, MergedTaskRunnersRunsOnTheSameThread) { TEST(TaskRunnerCheckerTests, PassesRunsOnCreationTaskRunnerIfOnDifferentTaskRunner) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "Something wrong in ohos libuv"; +#endif fml::MessageLoop* loop1 = nullptr; fml::AutoResetWaitableEvent latch1; std::thread thread1([&]() { diff --git a/fml/memory/weak_ptr_unittest.cc b/fml/memory/weak_ptr_unittest.cc index 3fda8a2c36..3d9b0c5d1e 100644 --- a/fml/memory/weak_ptr_unittest.cc +++ b/fml/memory/weak_ptr_unittest.cc @@ -177,6 +177,9 @@ TEST(WeakPtrTest, UpcastMoveAssignment) { } TEST(TaskRunnerAffineWeakPtrTest, ShouldNotCrashIfRunningOnTheSameTaskRunner) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "Something wrong in ohos libuv"; +#endif fml::MessageLoop* loop1 = nullptr; fml::AutoResetWaitableEvent latch1; fml::AutoResetWaitableEvent term1; diff --git a/fml/message_loop_impl_unittests.cc b/fml/message_loop_impl_unittests.cc index 1846f8c9d4..480031472c 100644 --- a/fml/message_loop_impl_unittests.cc +++ b/fml/message_loop_impl_unittests.cc @@ -9,11 +9,15 @@ #include "flutter/fml/time/time_delta.h" #include "flutter/fml/time/time_point.h" #include "gtest/gtest.h" - +#include "flutter/fml/build_config.h" #define TIMESENSITIVE(x) TimeSensitiveTest_##x TEST(MessageLoopImpl, TIMESENSITIVE(WakeUpTimersAreSingletons)) { +#if FML_OS_OHOS + auto loop_impl = fml::MessageLoopImpl::Create(nullptr); +#else auto loop_impl = fml::MessageLoopImpl::Create(); +#endif const auto t1 = fml::TimeDelta::FromMilliseconds(10); const auto t2 = fml::TimeDelta::FromMilliseconds(30); diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 3df2553437..a8c9eca84f 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -14,7 +14,7 @@ declare_args() { impeller_enable_metal = is_ios # Whether the OpenGLES backend is enabled. - impeller_enable_opengles = is_linux || is_win || is_android ||is_ohos + impeller_enable_opengles = is_linux || is_win || is_android || is_ohos # Whether the Vulkan backend is enabled. #impeller_enable_vulkan = is_mac || is_linux || is_win || is_android diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index fff9b1cf7b..bf72371f62 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -205,6 +205,10 @@ if (enable_unittests) { "fixtures/FontManifest.json", "//flutter/third_party/txt/third_party/fonts/Roboto-Medium.ttf", ] + + if (is_ohos) { + dest = "/data/flutter_unittests/lib/ui" + } } executable("ui_benchmarks") { @@ -230,18 +234,7 @@ if (enable_unittests) { public_configs = [ "//flutter:export_dynamic_symbols" ] sources = [ - "compositing/scene_builder_unittests.cc", - "hooks_unittests.cc", - "painting/image_dispose_unittests.cc", - "painting/image_encoding_unittests.cc", "painting/image_generator_registry_unittests.cc", - "painting/paint_unittests.cc", - "painting/path_unittests.cc", - "painting/single_frame_codec_unittests.cc", - "semantics/semantics_update_builder_unittests.cc", - "window/platform_configuration_unittests.cc", - "window/platform_message_response_dart_port_unittests.cc", - "window/platform_message_response_dart_unittests.cc", "window/pointer_data_packet_converter_unittests.cc", "window/pointer_data_packet_unittests.cc", ] @@ -259,8 +252,25 @@ if (enable_unittests) { "//third_party/dart/runtime/bin:elf_loader", ] + # TestGLSurface use vulkan, ohos does not support vulkan. + if (!is_ohos) { + sources += [ + "compositing/scene_builder_unittests.cc", + "hooks_unittests.cc", + "painting/image_dispose_unittests.cc", + "painting/image_encoding_unittests.cc", + "painting/paint_unittests.cc", + "painting/path_unittests.cc", + "painting/single_frame_codec_unittests.cc", + "semantics/semantics_update_builder_unittests.cc", + "window/platform_configuration_unittests.cc", + "window/platform_message_response_dart_port_unittests.cc", + "window/platform_message_response_dart_unittests.cc", + ] + } + # TODO(https://github.com/flutter/flutter/issues/63837): This test is hard-coded to use a TestGLSurface so it cannot run on fuchsia. - if (!is_fuchsia) { + if (!is_fuchsia && !is_ohos) { sources += [ "painting/image_decoder_unittests.cc" ] deps += [ "//flutter/testing:opengl" ] diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 48ef5882ec..d94b7f3353 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -123,6 +123,9 @@ source_set("runtime") { if (enable_unittests) { test_fixtures("runtime_fixtures") { dart_main = "fixtures/runtime_test.dart" + if (is_ohos) { + dest = "/data/flutter_unittests/runtime" + } } executable("runtime_unittests") { @@ -152,11 +155,21 @@ if (enable_unittests) { "//third_party/dart/runtime/bin:elf_loader", "//third_party/skia", ] + + if (!defined(defines)) { + defines = [] + } + if (enable_unittests && is_ohos) { + defines += [ "OHOS_USE_UNITTESTS_SKIP" ] + } } test_fixtures("no_plugin_registrant") { dart_main = "fixtures/no_dart_plugin_registrant_test.dart" use_target_as_artifact_prefix = true + if (is_ohos) { + dest = "/data/flutter_unittests/runtime" + } } executable("no_dart_plugin_registrant_unittests") { @@ -178,6 +191,9 @@ if (enable_unittests) { test_fixtures("plugin_registrant") { dart_main = "fixtures/dart_tool/flutter_build/dart_plugin_registrant.dart" use_target_as_artifact_prefix = true + if (is_ohos) { + dest = "/data/flutter_unittests/runtime" + } } executable("dart_plugin_registrant_unittests") { diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index e5f43fd566..6e9408f2df 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -38,6 +38,9 @@ class DartIsolateTest : public FixtureTest { }; TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); @@ -78,6 +81,9 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) { } TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); @@ -123,6 +129,9 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) { } TEST_F(DartIsolateTest, IsolateCanLoadAndRunDartCode) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); const auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); @@ -139,6 +148,9 @@ TEST_F(DartIsolateTest, IsolateCanLoadAndRunDartCode) { } TEST_F(DartIsolateTest, IsolateCannotLoadAndRunUnknownDartEntrypoint) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); const auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); @@ -155,6 +167,9 @@ TEST_F(DartIsolateTest, IsolateCannotLoadAndRunUnknownDartEntrypoint) { } TEST_F(DartIsolateTest, CanRunDartCodeCodeSynchronously) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); const auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); @@ -179,6 +194,9 @@ TEST_F(DartIsolateTest, CanRunDartCodeCodeSynchronously) { } TEST_F(DartIsolateTest, ImpellerFlagIsCorrectWhenTrue) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); settings.enable_impeller = true; @@ -214,6 +232,9 @@ TEST_F(DartIsolateTest, ImpellerFlagIsCorrectWhenTrue) { } TEST_F(DartIsolateTest, ImpellerFlagIsCorrectWhenFalse) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); settings.enable_impeller = false; @@ -397,6 +418,10 @@ TEST_F(DartIsolateTest, CanReceiveArguments) { } TEST_F(DartIsolateTest, CanCreateServiceIsolate) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif + #if (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG) && \ (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_PROFILE) GTEST_SKIP(); @@ -452,6 +477,9 @@ TEST_F(DartIsolateTest, CanCreateServiceIsolate) { TEST_F(DartIsolateTest, RootIsolateCreateCallbackIsMadeOnceAndBeforeIsolateRunning) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); size_t create_callback_count = 0u; @@ -479,6 +507,9 @@ TEST_F(DartIsolateTest, TEST_F(DartIsolateTest, IsolateCreateCallbacksTakeInstanceSettingsInsteadOfVMSettings) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto vm_settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(vm_settings); @@ -506,6 +537,9 @@ TEST_F(DartIsolateTest, } TEST_F(DartIsolateTest, InvalidLoadingUnitFails) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif if (!DartVM::IsRunningPrecompiledCode()) { FML_LOG(INFO) << "Split AOT does not work in JIT mode"; return; diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 7fa0c1b23a..2f8b67095e 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -185,6 +185,10 @@ if (enable_unittests) { "fixtures/shelltest_screenshot.png", "fixtures/hello_loop_2.gif", ] + + if (is_ohos) { + dest = "/data/flutter_unittests/common" + } } shell_host_executable("shell_benchmarks") { @@ -284,16 +288,12 @@ if (enable_unittests) { testonly = true sources = [ - "animator_unittests.cc", "canvas_spy_unittests.cc", "context_options_unittests.cc", "engine_unittests.cc", - "input_events_unittests.cc", - "persistent_cache_unittests.cc", "pipeline_unittests.cc", "rasterizer_unittests.cc", "resource_cache_limit_calculator_unittests.cc", - "shell_unittests.cc", "switches_unittests.cc", "variable_refresh_rate_display_unittests.cc", "vsync_waiter_unittests.cc", @@ -310,6 +310,15 @@ if (enable_unittests) { "//third_party/googletest:gmock", ] + if (!is_ohos) { + sources += [ + "animator_unittests.cc", + "input_events_unittests.cc", + "persistent_cache_unittests.cc", + "shell_unittests.cc", + ] + } + if (is_fuchsia) { sources += [ "shell_fuchsia_unittests.cc" ] @@ -319,7 +328,7 @@ if (enable_unittests) { "$fuchsia_sdk_root/pkg:fidl_cpp", "$fuchsia_sdk_root/pkg:sys_cpp", ] - } else { + } else if (!is_ohos) { # TODO(63837): This test is hard-coded to use a TestGLSurface so it cannot run on fuchsia. sources += [ "shell_io_manager_unittests.cc" ] diff --git a/shell/config.gni b/shell/config.gni index 85dd360cbc..4db04f8b5c 100644 --- a/shell/config.gni +++ b/shell/config.gni @@ -17,6 +17,6 @@ declare_args() { test_enable_metal = shell_enable_metal # The Vulkan unittests are combined with the GL unittests. - test_enable_vulkan = is_fuchsia || shell_enable_gl + test_enable_vulkan = (is_fuchsia || shell_enable_gl) && !is_ohos test_enable_software = shell_enable_software } diff --git a/shell/gpu/gpu_surface_vulkan.cc b/shell/gpu/gpu_surface_vulkan.cc index ba8383c134..7743289f59 100644 --- a/shell/gpu/gpu_surface_vulkan.cc +++ b/shell/gpu/gpu_surface_vulkan.cc @@ -98,6 +98,7 @@ sk_sp GPUSurfaceVulkan::CreateSurfaceFromVulkanImage( const VkImage image, const VkFormat format, const SkISize& size) { +#ifdef SK_VULKAN GrVkImageInfo image_info = { .fImage = image, .fImageTiling = VK_IMAGE_TILING_OPTIMAL, @@ -126,6 +127,9 @@ sk_sp GPUSurfaceVulkan::CreateSurfaceFromVulkanImage( SkColorSpace::MakeSRGB(), // color space &surface_properties // surface properties ); +#else + return nullptr; +#endif // SK_VULKAN } SkColorType GPUSurfaceVulkan::ColorTypeFromFormat(const VkFormat format) { diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 56335f45af..b4bd71a775 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -217,7 +217,7 @@ test_fixtures("fixtures") { ] } -if (enable_unittests) { +if (enable_unittests && !is_ohos) { source_set("embedder_unittests_library") { testonly = true diff --git a/testing/testing.gni b/testing/testing.gni index 3fadcbbc71..e2266e3317 100644 --- a/testing/testing.gni +++ b/testing/testing.gni @@ -331,7 +331,12 @@ template("test_fixtures") { copy_fixtures_target_name = "_cf_$target_name" copy_fixtures(copy_fixtures_target_name) { fixtures = invoker.fixtures - dest = dest + + if (is_ohos) { + dest = target_gen_dir + } else { + dest = dest + } forward_variables_from(invoker, [ "deps" ]) } test_public_deps += [ ":$copy_fixtures_target_name" ] diff --git a/third_party/tonic/tests/BUILD.gn b/third_party/tonic/tests/BUILD.gn index eff79c4245..f27612940c 100644 --- a/third_party/tonic/tests/BUILD.gn +++ b/third_party/tonic/tests/BUILD.gn @@ -7,6 +7,10 @@ import("//flutter/testing/testing.gni") test_fixtures("tonic_fixtures") { dart_main = "fixtures/tonic_test.dart" fixtures = [] + + if (is_ohos) { + dest = "/data/flutter_unittests/third_party/tonic/tests" + } } executable("tonic_unittests") { @@ -21,6 +25,13 @@ executable("tonic_unittests") { "ffi_native_unittest.cc", ] + if (!defined(defines)) { + defines = [] + } + if (enable_unittests && is_ohos) { + defines += [ "OHOS_USE_UNITTESTS_SKIP" ] + } + public_deps = [ ":tonic_fixtures", "//flutter/lib/snapshot", diff --git a/third_party/tonic/tests/dart_state_unittest.cc b/third_party/tonic/tests/dart_state_unittest.cc index 2e4a9c6161..26902b23a8 100644 --- a/third_party/tonic/tests/dart_state_unittest.cc +++ b/third_party/tonic/tests/dart_state_unittest.cc @@ -50,6 +50,9 @@ TEST_F(DartState, CurrentWithNullDataDoesNotSegfault) { } TEST_F(DartState, IsShuttingDown) { +#ifdef OHOS_USE_UNITTESTS_SKIP + GTEST_SKIP() << "ohos does not support create isolate in root thread"; +#endif ASSERT_FALSE(DartVMRef::IsInstanceRunning()); auto settings = CreateSettingsForFixture(); auto vm_ref = DartVMRef::Create(settings); diff --git a/third_party/txt/BUILD.gn b/third_party/txt/BUILD.gn index 0aaa87464c..ee5c0d278c 100644 --- a/third_party/txt/BUILD.gn +++ b/third_party/txt/BUILD.gn @@ -257,6 +257,10 @@ if (enable_unittests) { "third_party/fonts/emoji.xml", "third_party/fonts/itemize.xml", ] + + if (is_ohos) { + dest = "/data/flutter_unittests/third_party/txt" + } } source_set("txt_test_utils") { diff --git a/tools/clang_tidy/lib/src/git_repo.dart b/tools/clang_tidy/lib/src/git_repo.dart index 49d55a442e..5107d2ae45 100644 --- a/tools/clang_tidy/lib/src/git_repo.dart +++ b/tools/clang_tidy/lib/src/git_repo.dart @@ -23,7 +23,7 @@ class GitRepo { List? _changedFiles; /// Returns a list of all non-deleted files which differ from the nearest - /// merge-base with `main`. If it can't find a fork point, uses the default + /// merge-base with `master`. If it can't find a fork point, uses the default /// merge-base. /// /// This is only computed once and cached. Subsequent invocations of the @@ -88,7 +88,7 @@ class GitRepo { Future _fetch(ProcessRunner processRunner) async { final ProcessRunnerResult fetchResult = await processRunner.runProcess( - ['git', 'fetch', 'upstream', 'main'], + ['git', 'fetch', 'upstream', 'master'], failOk: true, ); if (fetchResult.exitCode != 0) { @@ -96,7 +96,7 @@ class GitRepo { 'git', 'fetch', 'origin', - 'main', + 'master', ]); } } diff --git a/tools/gn b/tools/gn index a5efe0f75d..f575871abc 100755 --- a/tools/gn +++ b/tools/gn @@ -277,10 +277,10 @@ def to_gn_args(args): if args.build_web_sdk or args.full_dart_sdk: gn_args['build_canvaskit'] = args.build_canvaskit + gn_args['enable_unittests'] = False if args.enable_unittests: - gn_args['enable_unittests'] = args.enable_unittests + gn_args['enable_unittests'] = True - gn_args['enable_unittests'] = False print("enable_unittests:%s" % gn_args['enable_unittests'] ); # Skia GN args. @@ -759,7 +759,7 @@ def parse_args(args): '--linux-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] ) parser.add_argument( - '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] + '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'], default='arm64' ) parser.add_argument( '--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64' diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index a7067fff3f..25608f54af 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -116,6 +116,7 @@ GrDirectContext* VulkanWindow::GetSkiaGrContext() { } bool VulkanWindow::CreateSkiaGrContext() { +#ifdef SK_VULKAN GrVkBackendContext backend_context; if (!CreateSkiaBackendContext(&backend_context)) { @@ -136,6 +137,9 @@ bool VulkanWindow::CreateSkiaGrContext() { skia_gr_context_ = context; return true; +#else + return false; +#endif } bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) { -- Gitee