From d6a94ed92d7e66f71caf0eaa32be4a14c85d563a Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Tue, 10 Sep 2024 16:06:43 +0800 Subject: [PATCH] uicontext.abc fix Signed-off-by: fangzhiyuan Change-Id: I87c7e9f934666ed2079b0ecab56c03247fe359f2 --- adapter/preview/sdk/BUILD.gn | 2 + build/tools/gen_uicontext_ohos.py | 52 +++++++++++++++++++ .../bridge/declarative_frontend/BUILD.gn | 36 ++++++++++++- .../declarative_frontend/engine/jsPreload.js | 20 +++++++ .../declarative_frontend/engine/jsi/BUILD.gn | 27 +++++++++- .../engine/jsi/jsi_declarative_engine.cpp | 9 ++++ 6 files changed, 143 insertions(+), 3 deletions(-) create mode 100755 build/tools/gen_uicontext_ohos.py create mode 100644 frameworks/bridge/declarative_frontend/engine/jsPreload.js diff --git a/adapter/preview/sdk/BUILD.gn b/adapter/preview/sdk/BUILD.gn index 9b9baffde22..a78f88343c4 100644 --- a/adapter/preview/sdk/BUILD.gn +++ b/adapter/preview/sdk/BUILD.gn @@ -106,6 +106,7 @@ if (is_ohos_standard_system) { deps = [ "$ace_root/frameworks/bridge/declarative_frontend:ark_modifier", "$ace_root/frameworks/bridge/declarative_frontend:ark_theme_control", + "$ace_root/frameworks/bridge/declarative_frontend:uicontext", "$ace_root/frameworks/bridge/declarative_frontend:x_node", ] out_path = get_label_info( @@ -115,6 +116,7 @@ if (is_ohos_standard_system) { "${out_path}/arkui/ace_engine/modifier.abc", "${out_path}/arkui/ace_engine/node.abc", "${out_path}/arkui/ace_engine/theme.abc", + "${out_path}/arkui/ace_engine/uicontext.abc", ] outputs = [ target_out_dir + diff --git a/build/tools/gen_uicontext_ohos.py b/build/tools/gen_uicontext_ohos.py new file mode 100755 index 00000000000..3a271448b60 --- /dev/null +++ b/build/tools/gen_uicontext_ohos.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re +import sys + + +def main(input_path, output_path): + with open(output_path, "w", encoding="utf-8") as ohos: + export_content = "export default { " + with open(input_path, "r", encoding="utf-8") as f: + line = f.readline() + isFirstClass = True + class_num = 0 + while (line): + ohos.write(line) + if (line.startswith("class ")): + class_num += 1 + if class_num % 5 == 0: + class_num = 0 + isFirstClass = True + export_content += ",\n\t" + + class_name = re.match(r"class\s+(\w+)", line).group(1) + if isFirstClass: + isFirstClass = False + else: + export_content += ", " + export_content += class_name + line = f.readline() + ohos.write("\n") + export_content += " };\n" + export_content += "globalThis.__getUIContext__ = __getUIContext__;\n" + export_content += "globalThis.__getFrameNodeByNodeId__ = __getFrameNodeByNodeId__;\n" + export_content += "globalThis.__checkRegexValid__ = __checkRegexValid__;" + ohos.write("\n" + export_content) + + +if __name__ == "__main__": + main(sys.argv[1], sys.argv[2]) diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index d80ba45e462..bd39aa1a69b 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -181,7 +181,6 @@ template("declarative_js_engine") { ":gen_obj_src_ark_theme", ":gen_obj_src_js_enum_style", ":gen_obj_src_js_proxyclass", - ":gen_obj_src_js_uicontext", ":mock", ":prefetcher", ":shape", @@ -190,6 +189,12 @@ template("declarative_js_engine") { "engine/$engine_path:declarative_js_engine_bridge_${engine_name}_$platform", ] + if (!is_arkui_x) { + deps += [ ":uicontext" ] + } else { + deps += [ ":gen_obj_src_js_uicontext" ] + } + configs = [ "$ace_root:ace_config" ] if (ace_engine_feature_enable_point_light) { defines += [ "POINT_LIGHT_ENABLE" ] @@ -709,7 +714,6 @@ template("declarative_js_engine_ng") { ":gen_obj_src_ark_theme", ":gen_obj_src_js_enum_style", ":gen_obj_src_js_proxyclass", - ":gen_obj_src_js_uicontext", ":mock", ":prefetcher", ":shape", @@ -718,6 +722,12 @@ template("declarative_js_engine_ng") { "engine/$engine_path:declarative_js_engine_bridge_${engine_name}_$platform", ] + if (!is_arkui_x) { + deps += [ ":uicontext" ] + } else { + deps += [ ":gen_obj_src_js_uicontext" ] + } + configs = [ "$ace_root:ace_config" ] sources = [ @@ -1163,6 +1173,28 @@ ohos_abc("prefetcher") { part_name = ace_engine_part } +action("gen_uicontext_ohos") { + script = "$ace_root/build/tools/gen_uicontext_ohos.py" + inputs = [ + "$ace_root/frameworks/bridge/declarative_frontend/engine/jsUIContext.js", + ] + outputs = [ "$base_output_path/jsUIContext_ohos.js" ] + args = [ + rebase_path(inputs[0]), + rebase_path(outputs[0]), + ] +} + +ohos_abc("uicontext") { + sources = [ "$base_output_path/jsUIContext_ohos.js" ] + output_name = "uicontext" + deps = [ ":gen_uicontext_ohos" ] + install_images = [ "system" ] + module_install_dir = "etc/abc/arkui" + subsystem_name = ace_engine_subsystem + part_name = ace_engine_part +} + ohos_abc("ark_theme_control") { sources = [ "engine/arkThemeControl.js" ] output_name = "theme" diff --git a/frameworks/bridge/declarative_frontend/engine/jsPreload.js b/frameworks/bridge/declarative_frontend/engine/jsPreload.js new file mode 100644 index 00000000000..fa0fcdcd86e --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/jsPreload.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +if (globalThis.requireNapi === undefined) { + const UIContext = globalThis.requireNapiPreview('arkui.uicontext'); +} else { + const UIContext = globalThis.requireNapi('arkui.uicontext'); +} diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/BUILD.gn b/frameworks/bridge/declarative_frontend/engine/jsi/BUILD.gn index b6cc8c9424a..2a62c37d686 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/engine/jsi/BUILD.gn @@ -21,6 +21,7 @@ base_output_path = get_label_info(":gen_abc_proxyclass", "target_out_dir") abcproxyclass_obj_path = base_output_path + "/abc_proxy_class.o" abcenumstyle_obj_path = base_output_path + "/abc_enum_style.o" abcuicontext_obj_path = base_output_path + "/abc_uicontext.o" +abcpreload_obj_path = base_output_path + "/abc_preload.o" jsmocksystemplugin_obj_path = base_output_path + "/abc_js_mock_system_plugin.o" arkTheme_obj_path = base_output_path + "/abc_ark_theme.o" arkcomponent_obj_path = base_output_path + "/abc_ark_component.o" @@ -65,6 +66,16 @@ es2abc_gen_abc("gen_jsUIContext_abc") { out_puts = [ base_output_path + "/jsUIContext.abc" ] } +es2abc_gen_abc("gen_jsPreload_abc") { + extra_visibility = [ ":*" ] # Only targets in this file can depend on this. + src_js = rebase_path( + "//foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/jsPreload.js") + dst_file = rebase_path(base_output_path + "/jsPreload.abc") + + in_puts = [ "//foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/jsPreload.js" ] + out_puts = [ base_output_path + "/jsPreload.abc" ] +} + es2abc_gen_abc("gen_arkComponent_abc") { extra_visibility = [ ":*" ] # Only targets in this file can depend on this. src_js = rebase_path( @@ -126,6 +137,15 @@ gen_obj("abc_uicontext") { snapshot_dep = [ ":gen_jsUIContext_abc" ] } +gen_obj("abc_preload") { + input = base_output_path + "/jsPreload.abc" + if (use_mac || use_mingw_win || use_linux || use_ios) { + abcpreload_obj_path = base_output_path + "/jsPreload.c" + } + output = abcpreload_obj_path + snapshot_dep = [ ":gen_jsPreload_abc" ] +} + gen_obj("abc_ark_component") { input = base_output_path + "/arkComponent.abc" if (use_mac || use_mingw_win || use_ios || use_linux) { @@ -428,9 +448,14 @@ template("declarative_js_engine_ark") { ":gen_obj_src_abc_ark_theme", ":gen_obj_src_abc_enum_style", ":gen_obj_src_abc_proxyclass", - ":gen_obj_src_abc_uicontext", ] + if (is_arkui_x) { + deps += [ ":gen_obj_src_abc_uicontext" ] + } else { + deps += [ ":gen_obj_src_abc_preload" ] + } + foreach(item, abc_sources) { deps += [ ":copy_" + item + "_abc" ] } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp index fe71d04eb2a..18185519694 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp @@ -84,6 +84,10 @@ extern const char _binary_jsEnumStyle_abc_start[]; extern const char _binary_jsUIContext_abc_start[]; extern const char _binary_arkComponent_abc_start[]; extern const char _binary_arkTheme_abc_start[]; +#if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) +extern const char _binary_jsPreload_abc_start[]; +extern const char _binary_jsPreload_abc_end[]; +#endif #if !defined(IOS_PLATFORM) extern const char _binary_stateMgmt_abc_end[]; extern const char _binary_jsEnumStyle_abc_end[]; @@ -199,8 +203,13 @@ inline bool PreloadStateManagement(const shared_ptr& runtime) inline bool PreloadUIContent(const shared_ptr& runtime) { +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) uint8_t* codeStart = const_cast(reinterpret_cast(_binary_jsUIContext_abc_start)); int32_t codeLength = _binary_jsUIContext_abc_end - _binary_jsUIContext_abc_start; +#else + uint8_t* codeStart = const_cast(reinterpret_cast(_binary_jsPreload_abc_start)); + int32_t codeLength = _binary_jsPreload_abc_end - _binary_jsPreload_abc_start; +#endif return runtime->EvaluateJsCode(codeStart, codeLength); }