From 66685e394ad9a14b6b2062cb30ea8d235e3dba31 Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Sat, 28 Jun 2025 18:36:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- ...s.app.ability.abilityDelegatorRegistry.ets | 27 ++ libs/arkts1.2/@ohos.hilog.ets | 20 ++ libs/arkts1.2/@ohos.systemDateTime.ets | 28 ++ libs/arkts1.2/AbilityDelegator.ets | 22 ++ libs/arkts1.2/AbilityDelegatorArgs.ets | 16 ++ libs/arkts1.2/ShellCmdResult.ets | 11 + libs/arkts1.2/build_test.py | 268 ++++++++++++++++++ 7 files changed, 392 insertions(+) create mode 100644 libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets create mode 100644 libs/arkts1.2/@ohos.hilog.ets create mode 100644 libs/arkts1.2/@ohos.systemDateTime.ets create mode 100644 libs/arkts1.2/AbilityDelegator.ets create mode 100644 libs/arkts1.2/AbilityDelegatorArgs.ets create mode 100644 libs/arkts1.2/ShellCmdResult.ets create mode 100644 libs/arkts1.2/build_test.py diff --git a/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets b/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets new file mode 100644 index 0000000..00ed08a --- /dev/null +++ b/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets @@ -0,0 +1,27 @@ +import { AbilityDelegator as _AbilityDelegator, AbilityDelegatorInner } from 'AbilityDelegator' +import { AbilityDelegatorArgs as _AbilityDelegatorArgs} from 'AbilityDelegatorArgs' +import { ShellCmdResult as _ShellCmdResult } from 'ShellCmdResult' + +export default namespace abilityDelegatorRegistry { + export type AbilityDelegator = _AbilityDelegator; + export type AbilityDelegatorArgs = _AbilityDelegatorArgs; + export type ShellCmdResult = _ShellCmdResult; + + export function getAbilityDelegator(): AbilityDelegator { + return new AbilityDelegatorInner(); + } + + export function getArguments(): AbilityDelegatorArgs { + return { + "bundleName": "com.example.myapplication", + "parameters": { + "-b": "com.example.myapplication", + "-m": "entry_test", + "-s": "600000", + "moduleName": "", + }, + "testCaseNames": "example", + "testRunnerClassName": "./OpenHarmonyTestRunner" + } + } +} \ No newline at end of file diff --git a/libs/arkts1.2/@ohos.hilog.ets b/libs/arkts1.2/@ohos.hilog.ets new file mode 100644 index 0000000..861ef07 --- /dev/null +++ b/libs/arkts1.2/@ohos.hilog.ets @@ -0,0 +1,20 @@ +export enum LogLevel { + DEBUG = 3, + INFO = 4, + WARN = 5, + ERROR = 6, + FATAL = 7 +} + +export default namespace hilog { + + export function debug(domain: number, tag: string, format: string, ...args: (number | boolean | string | object | null | undefined)[]): void{} + + export function info(domain: number, tag: string, format: string, ...args: (number | boolean | string | object | null | undefined)[]): void{} + + export function warn(domain: number, tag: string, format: string, ...args: (number | boolean | string | object | null | undefined)[]): void{} + + export function error(domain: number, tag: string, format: string, ...args: (number | boolean | string | object | null | undefined)[]): void{} + + export function fatal(domain: number, tag: string, format: string, ...args: (number | boolean | string | object | null | undefined)[]): void{} +} \ No newline at end of file diff --git a/libs/arkts1.2/@ohos.systemDateTime.ets b/libs/arkts1.2/@ohos.systemDateTime.ets new file mode 100644 index 0000000..fd99e08 --- /dev/null +++ b/libs/arkts1.2/@ohos.systemDateTime.ets @@ -0,0 +1,28 @@ +import { BusinessError } from '@ohos.base'; + +type AsyncCallback = (error: BusinessError, data: T) => void; + +export default namespace systemDateTime { + + export enum TimeType { + STARTUP, + ACTIVE + } + + export function getUptime(timeType: TimeType, isNanoseconds?: boolean): number { + const nowTime:number = new Date().getTime(); + return nowTime; + } + + const SYSTEM_ERROR: number = 401 + + export function getCurrentTime(isNano: boolean, callback: AsyncCallback): void {} + + export function getCurrentTime(callback: AsyncCallback): void {} + + export function getCurrentTime(isNano?: boolean): void {} + + export function getTimezone(callback: AsyncCallback): void {} + + export function getTimezone(): void {} +} \ No newline at end of file diff --git a/libs/arkts1.2/AbilityDelegator.ets b/libs/arkts1.2/AbilityDelegator.ets new file mode 100644 index 0000000..273921b --- /dev/null +++ b/libs/arkts1.2/AbilityDelegator.ets @@ -0,0 +1,22 @@ +import { BusinessError } from '@ohos.base'; +import { ShellCmdResult } from 'ShellCmdResult' + +type AsyncCallback = (error: BusinessError, data: T) => void; + +export interface AbilityDelegator { + + printSync(msg: string): void; + + finishTest(msg: string, code: number): void; + + executeShellCommand(cmd: String, timeoutSecs: number, callback: AsyncCallback): void; +} + +export class AbilityDelegatorInner implements AbilityDelegator { + + printSync(msg: string): void {}; + + finishTest(msg: string, code: number): void {}; + + executeShellCommand(cmd: String, timeoutSecs: number, callback: AsyncCallback): void {}; +} \ No newline at end of file diff --git a/libs/arkts1.2/AbilityDelegatorArgs.ets b/libs/arkts1.2/AbilityDelegatorArgs.ets new file mode 100644 index 0000000..e72d3a1 --- /dev/null +++ b/libs/arkts1.2/AbilityDelegatorArgs.ets @@ -0,0 +1,16 @@ +export interface AbilityDelegatorArgs { + bundleName: string; + parameters: Record; + testCaseNames: string; + testRunnerClassName: string; +} + +class AbilityDelegatorArgsInner implements AbilityDelegatorArgs { + public bundleName: string = ''; + + public parameters: Record = {}; + + public testCaseNames: string = ''; + + public testRunnerClassName: string = ''; +} \ No newline at end of file diff --git a/libs/arkts1.2/ShellCmdResult.ets b/libs/arkts1.2/ShellCmdResult.ets new file mode 100644 index 0000000..d4df080 --- /dev/null +++ b/libs/arkts1.2/ShellCmdResult.ets @@ -0,0 +1,11 @@ +export interface ShellCmdResult { + stdResult: string; + exitCode: number; +} + +export class ShellCmdResultImpl implements ShellCmdResult { + + public stdResult: string = ''; + + public exitCode: number = 0; +} \ No newline at end of file diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py new file mode 100644 index 0000000..6e0622a --- /dev/null +++ b/libs/arkts1.2/build_test.py @@ -0,0 +1,268 @@ +import os +import sys +import json +import subprocess + +es2PandaPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" +arkLinkPath = "arkcompiler/runtime_core/static_core/out/bin/ark_link" +arkPath = "arkcompiler/runtime_core/static_core/out/bin/ark" +etsStdLibPath = "arkcompiler/runtime_core/static_core/out/plugins/ets/etsstdlib.abc" +configPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" +hypiumPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" + +def build_tools(compileFileList): + """ + 编译工具类 + """ + + absEs2PandaPath = get_path_code_dir(es2PandaPath) + absTestPath = os.getcwd() + + # 1. 创建输出目录 + output_dir = os.path.join(absTestPath, "out") + os.makedirs(output_dir, exist_ok = True) + + # 逐个执行编译命令 + for ets_file in compileFileList: + try: + # 获取文件名(不带路径) + file_name = os.path.basename(ets_file) + base_name = os.path.splitext(file_name)[0] + output_file_path = os.path.join(output_dir, f"{base_name}.abc") + + # 构造编译命令 + command = [absEs2PandaPath, ets_file, "--output", output_file_path] + + # 执行命令并获取输出 + result = subprocess.run( + command, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + + # 成功编译 + print(f"成功编译'{ets_file}', 输出路径: {output_file_path}") + + except Exception as e: + print(f"'{ets_file}'编译失败") + + +def get_path_code_dircetory(after_dir): + """ + 拼接绝对路径工具类 + """ + + current_path = os.path.abspath(__file__) + current_dir = os.path.dirname(current_path) + + # 查找 /code/ 目录的位置 + code_maker = "/code/" + code_index = current_dir.find(code_maker) + + if code_index == -1: + raise FileNotFoundError( + f"路径中没有找到 '/code/',当前路径为: {current_dir}" + ) + + # 提取code路径 (包含code目录本身) + code_base = current_dir[:code_index + len(code_maker)] + + # 拼接用户传入路径 + full_path = os.path.join(code_base, after_dir) + + return full_path + + +def write_arktsconfig_file(): + """ + 将当前目录下的 .ets文件生成 file_map, 并追加写入 arktsconfig.json + """ + + current_dir = os.path.dirname(os.path.abspath(__file__)) + + # 1. 获取当前目录下的所有.ets文件 + ets_files = [f for f in os.listdir(current_dir) if f.endswith('.ets')] + + # 2. 构建file_map:{文件名:[文件绝对路径]} + file_map = {} + for ets_file in ets_files: + module_name = os.path.splitext(ets_file)[0] + relative_path = os.path.join(current_dir,ets_file) + abs_path = get_path_code_dircetory(relative_path) + file_map[module_name] = [abs_path] + + # 3. 定位要写入的 arktsconfig.json文件 + abs_config_path = get_path_code_dircetory(configPath) + + # 4. 读取并更新配置 + try: + with open(abs_config_path, 'r', encoding='utf-8' ) as f: + config = json.load(f) + except FileNotFoundError: + config = {"compilerOptions": {"baseUrl":"/code/arkcompiler/runtime_core/static_core","paths":{}}} + + # 5. 更新配置中的paths(保留之前的配置项) + config.setdefault("compilerOptions",{}) + config["compilerOptions"].setdefault("paths",{}) + config["compilerOptions"]["paths"].update(file_map) + + with open(abs_config_path, 'w', encoding='utf-8' ) as f: + json.dump(config, f, indent=4, ensure_ascii=False) + + print(f"已成功更新 {abs_config_path}") + + +def build_ets_files(): + """ + 编译hypium、tools、测试用例文件 + """ + absHypiumPath = get_path_code_dircetory(hypiumPath) + + files_to_compile = [] + for root, dirs, files in os.walk(absHypiumPath): + if "testAbility" in dirs: + dirs.remove("testAbility") + if "testrunner" in dirs: + dirs.remove("testrunner") + + for f in files: + if f.endswith(".ets"): + file_path = os.path.join(root, f) + files_to_compile.append(file_path) + + if not files_to_compile: + print("未找到可编译的 .ets 文件,跳过编译。") + return + build_tools(files_to_compile) + + current_dir = os.path.dirname(os.path.abspath(__file__)) + ets_files = [os.path.join(current_dir, f) for f in os.listdir(current_dir) if f.endswith('.ets')] + build_tools(ets_files) + + absTestPath = os.getcwd() + test_files = [] + + for root, dirs, files in os.walk(absTestPath): + for file in files: + if file.endswith(".ets"): + file_abs_path = os.path.join(root, file) + test_files.append(file_abs_path) + build_tools(test_files) + + +def link_abc_files(res_file_name): + """ + 链接所有abc文件生成最终的test.abc + """ + + absArkLinkPath = get_path_code_dircetory(arkLinkPath) + absOutPath = os.path.join(os.getcwd(), "out") + tests_dir_name = res_file_name + + abc_files = [] + + out_files = [os.path.join("./out",f) for f in os.listdir(absOutPath) if f.endswith('.abc')] + abc_files.extend(out_files) + + src_json_path = os.path.join(os.getcwd(), "src.json") + + try: + with open(src_json_path, 'r') as f: + src_data = json.load(f) + src_paths = src_data.get("src_path", []) + + for path in src_paths: + full_path = path + + if os.path.isfile(full_path) and full_path.endswith('.abc'): + abc_files.append(full_path) + else: + print(f"路径{full_path} 不存在或不是.abc文件,跳过处理。") + + except FileNotFoundError: + print(f"文件 {src_json_path} 未找到,跳过处理") + except json.JSONDecodeError: + print(f"文件 {src_json_path} 格式错误无法解析") + except Exception as e: + print(f"读取 src.json 时发生错误: {e}") + + if abc_files: + command = [ + absArkLinkPath, + f"--output={tests_dir_name}.abc", + "--", + *abc_files + ] + + print(f"执行命令 {command}") + + try: + result = subprocess.run( + command, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + + print("命令执行成功") + print(result.stdout.strip()) + + except subprocess.CalledProcessError as e: + print("命令执行失败") + print(f"错误信息 {e.stderr.strip()}") + + else: + print("没有找到可连接的.abc文件") + + +def run_test(res_file_name): + """ + 执行生成的abc文件并生成报告日志 + """ + absArkPath = get_path_code_dircetory(arkPath) + absEtsStdLibPath = get_path_code_dircetory(etsStdLibPath) + tests_dir_name = res_file_name + log_file = os.path.join(os.getcwd(), f"{tests_dir_name}.log") + command = [ + absArkPath, + f"--boot-panda-files={absEtsStdLibPath}", + f"--load-runtimes=ets", + f"{tests_dir_name}.abc", + f"OpenHarmonyTestRunner/ETSGLOBAL::main" + ] + print(f"执行命令 {command}") + with open(log_file, "w") as f: + try: + result = subprocess.run( + command, + check=True, + stdout=f, + stderr=subprocess.PIPE, + text=True + ) + + print("命令执行成功") + except subprocess.CalledProcessError as e: + print("命令执行失败") + print(f"错误信息 {e.stderr.strip()}") + + +def main(): + if len(sys.argv) < 2: + print("使用方式: python3 build_test.py ") + print("实例:") + print("python3 build_test.py functionsTest") + sys.exit(1) + + res_file_name = sys.argv[1] + write_arktsconfig_file() + build_ets_files() + link_abc_files(res_file_name) + run_test(res_file_name) + + +if __name__ == '__main__': + main() \ No newline at end of file -- Gitee From ce753231703627975d16d0527573e41000eb1444 Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Mon, 30 Jun 2025 10:25:48 +0800 Subject: [PATCH 2/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- ...s.app.ability.abilityDelegatorRegistry.ets | 17 +++++- libs/arkts1.2/@ohos.hilog.ets | 16 ++++- libs/arkts1.2/@ohos.systemDateTime.ets | 14 +++++ libs/arkts1.2/AbilityDelegator.ets | 14 +++++ libs/arkts1.2/AbilityDelegatorArgs.ets | 16 ++++- libs/arkts1.2/ShellCmdResult.ets | 16 ++++- libs/arkts1.2/build_test.py | 58 ++++++++++++------- 7 files changed, 127 insertions(+), 24 deletions(-) diff --git a/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets b/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets index 00ed08a..a798cd6 100644 --- a/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets +++ b/libs/arkts1.2/@ohos.app.ability.abilityDelegatorRegistry.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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 { AbilityDelegator as _AbilityDelegator, AbilityDelegatorInner } from 'AbilityDelegator' import { AbilityDelegatorArgs as _AbilityDelegatorArgs} from 'AbilityDelegatorArgs' import { ShellCmdResult as _ShellCmdResult } from 'ShellCmdResult' @@ -17,7 +32,7 @@ export default namespace abilityDelegatorRegistry { "parameters": { "-b": "com.example.myapplication", "-m": "entry_test", - "-s": "600000", + "-s timeout": "600000", "moduleName": "", }, "testCaseNames": "example", diff --git a/libs/arkts1.2/@ohos.hilog.ets b/libs/arkts1.2/@ohos.hilog.ets index 861ef07..b9c1c65 100644 --- a/libs/arkts1.2/@ohos.hilog.ets +++ b/libs/arkts1.2/@ohos.hilog.ets @@ -1,4 +1,18 @@ -export enum LogLevel { +/* + * Copyright (c) 2025 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. + */ + export enum LogLevel { DEBUG = 3, INFO = 4, WARN = 5, diff --git a/libs/arkts1.2/@ohos.systemDateTime.ets b/libs/arkts1.2/@ohos.systemDateTime.ets index fd99e08..eaad063 100644 --- a/libs/arkts1.2/@ohos.systemDateTime.ets +++ b/libs/arkts1.2/@ohos.systemDateTime.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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 { BusinessError } from '@ohos.base'; type AsyncCallback = (error: BusinessError, data: T) => void; diff --git a/libs/arkts1.2/AbilityDelegator.ets b/libs/arkts1.2/AbilityDelegator.ets index 273921b..e65d27c 100644 --- a/libs/arkts1.2/AbilityDelegator.ets +++ b/libs/arkts1.2/AbilityDelegator.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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 { BusinessError } from '@ohos.base'; import { ShellCmdResult } from 'ShellCmdResult' diff --git a/libs/arkts1.2/AbilityDelegatorArgs.ets b/libs/arkts1.2/AbilityDelegatorArgs.ets index e72d3a1..0b6315e 100644 --- a/libs/arkts1.2/AbilityDelegatorArgs.ets +++ b/libs/arkts1.2/AbilityDelegatorArgs.ets @@ -1,4 +1,18 @@ -export interface AbilityDelegatorArgs { +/* + * Copyright (c) 2025 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. + */ + export interface AbilityDelegatorArgs { bundleName: string; parameters: Record; testCaseNames: string; diff --git a/libs/arkts1.2/ShellCmdResult.ets b/libs/arkts1.2/ShellCmdResult.ets index d4df080..364997c 100644 --- a/libs/arkts1.2/ShellCmdResult.ets +++ b/libs/arkts1.2/ShellCmdResult.ets @@ -1,4 +1,18 @@ -export interface ShellCmdResult { +/* + * Copyright (c) 2025 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. + */ + export interface ShellCmdResult { stdResult: string; exitCode: number; } diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py index 6e0622a..1ba22d5 100644 --- a/libs/arkts1.2/build_test.py +++ b/libs/arkts1.2/build_test.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2025 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 os import sys import json @@ -7,20 +24,21 @@ es2PandaPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" arkLinkPath = "arkcompiler/runtime_core/static_core/out/bin/ark_link" arkPath = "arkcompiler/runtime_core/static_core/out/bin/ark" etsStdLibPath = "arkcompiler/runtime_core/static_core/out/plugins/ets/etsstdlib.abc" -configPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" -hypiumPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" +configPath = "arkcompiler/runtime_core/static_core/out/bin/arktsconfig.json" +hypiumPath = "test/testfwk/arkxtest/jsunit/src_static/" + def build_tools(compileFileList): """ 编译工具类 """ - absEs2PandaPath = get_path_code_dir(es2PandaPath) + absEs2PandaPath = get_path_code_dircetory(es2PandaPath) absTestPath = os.getcwd() # 1. 创建输出目录 - output_dir = os.path.join(absTestPath, "out") - os.makedirs(output_dir, exist_ok = True) + outputDir = os.path.join(absTestPath, "out") + os.makedirs(outputDir, exist_ok = True) # 逐个执行编译命令 for ets_file in compileFileList: @@ -28,7 +46,7 @@ def build_tools(compileFileList): # 获取文件名(不带路径) file_name = os.path.basename(ets_file) base_name = os.path.splitext(file_name)[0] - output_file_path = os.path.join(output_dir, f"{base_name}.abc") + output_file_path = os.path.join(outputDir, f"{base_name}.abc") # 构造编译命令 command = [absEs2PandaPath, ets_file, "--output", output_file_path] @@ -58,8 +76,8 @@ def get_path_code_dircetory(after_dir): current_dir = os.path.dirname(current_path) # 查找 /code/ 目录的位置 - code_maker = "/code/" - code_index = current_dir.find(code_maker) + code_marker = "/code/" + code_index = current_dir.find(code_marker) if code_index == -1: raise FileNotFoundError( @@ -67,7 +85,7 @@ def get_path_code_dircetory(after_dir): ) # 提取code路径 (包含code目录本身) - code_base = current_dir[:code_index + len(code_maker)] + code_base = current_dir[:code_index + len(code_marker)] # 拼接用户传入路径 full_path = os.path.join(code_base, after_dir) @@ -98,17 +116,17 @@ def write_arktsconfig_file(): # 4. 读取并更新配置 try: - with open(abs_config_path, 'r', encoding='utf-8' ) as f: + with open(abs_config_path, 'r', encoding='utf-8') as f: config = json.load(f) except FileNotFoundError: - config = {"compilerOptions": {"baseUrl":"/code/arkcompiler/runtime_core/static_core","paths":{}}} + config = {"compilerOptions": { "baseUrl":"/code/arkcompiler/runtime_core/static_core", "paths": {} }} # 5. 更新配置中的paths(保留之前的配置项) - config.setdefault("compilerOptions",{}) - config["compilerOptions"].setdefault("paths",{}) + config.setdefault("compilerOptions", {}) + config["compilerOptions"].setdefault("paths", {}) config["compilerOptions"]["paths"].update(file_map) - with open(abs_config_path, 'w', encoding='utf-8' ) as f: + with open(abs_config_path, 'w', encoding='utf-8') as f: json.dump(config, f, indent=4, ensure_ascii=False) print(f"已成功更新 {abs_config_path}") @@ -162,14 +180,14 @@ def link_abc_files(res_file_name): tests_dir_name = res_file_name abc_files = [] - - out_files = [os.path.join("./out",f) for f in os.listdir(absOutPath) if f.endswith('.abc')] + + out_files = [os.path.join("./out", f) for f in os.listdir(absOutPath) if fabc')] abc_files.extend(out_files) - - src_json_path = os.path.join(os.getcwd(), "src.json") - + + src_json_path = os.path.join(os.getcwd(), "src.json") + try: - with open(src_json_path, 'r') as f: + with open(src_json_path, 'r'): src_data = json.load(f) src_paths = src_data.get("src_path", []) -- Gitee From a67a4263fc935b804fe51499be67608a9cf4a705 Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Mon, 30 Jun 2025 10:54:25 +0800 Subject: [PATCH 3/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- libs/arkts1.2/build_test.py | 99 +++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py index 1ba22d5..250a905 100644 --- a/libs/arkts1.2/build_test.py +++ b/libs/arkts1.2/build_test.py @@ -170,70 +170,75 @@ def build_ets_files(): build_tools(test_files) -def link_abc_files(res_file_name): +def collect_abc_files(res_file_name): """ - 链接所有abc文件生成最终的test.abc + 收集所有需要链接的.abc文件路径(包括out目录和src.json中配置的路径) + 返回: abc文件路径列表 """ - - absArkLinkPath = get_path_code_dircetory(arkLinkPath) absOutPath = os.path.join(os.getcwd(), "out") - tests_dir_name = res_file_name - abc_files = [] - out_files = [os.path.join("./out", f) for f in os.listdir(absOutPath) if fabc')] + # 1. 收集out目录下的.abc文件 + out_files = [os.path.join("./out", f) + for f in os.listdir(absOutPath) + if f.endswith('.abc')] abc_files.extend(out_files) + # 2. 收集src.json中配置的.abc文件 src_json_path = os.path.join(os.getcwd(), "src.json") - try: - with open(src_json_path, 'r'): + with open(src_json_path, 'r') as f: src_data = json.load(f) - src_paths = src_data.get("src_path", []) - - for path in src_paths: - full_path = path - - if os.path.isfile(full_path) and full_path.endswith('.abc'): - abc_files.append(full_path) + for path in src_data.get("src_path", []): + if os.path.isfile(path) and path.endswith('.abc'): + abc_files.append(path) else: - print(f"路径{full_path} 不存在或不是.abc文件,跳过处理。") + print(f"警告: 路径 {path} 不存在或不是.abc文件,已跳过") except FileNotFoundError: - print(f"文件 {src_json_path} 未找到,跳过处理") + print(f"提示: 配置文件 {src_json_path} 未找到,跳过src.json收集") except json.JSONDecodeError: - print(f"文件 {src_json_path} 格式错误无法解析") + print(f"错误: 配置文件 {src_json_path} JSON格式错误") except Exception as e: - print(f"读取 src.json 时发生错误: {e}") + print(f"读取src.json时发生意外错误: {str(e)}") - if abc_files: - command = [ - absArkLinkPath, - f"--output={tests_dir_name}.abc", - "--", - *abc_files - ] - - print(f"执行命令 {command}") + return abc_files + + +def link_abc_files(res_file_name): + """ + 链接所有abc文件生成最终的test.abc + """ + absArkLinkPath = get_path_code_dircetory(arkLinkPath) + abc_files = collect_abc_files(res_file_name) + + if not abc_files: + print("终止: 没有找到可连接的.abc文件") + return + + command = [ + absArkLinkPath, + f"--output={res_file_name}.abc", + "--", + *abc_files + ] + + print(f"执行命令: {' '.join(command)}") + + try: + result = subprocess.run( + command, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + print("状态: 链接成功\n输出:", result.stdout.strip()) - try: - result = subprocess.run( - command, - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True - ) - - print("命令执行成功") - print(result.stdout.strip()) - - except subprocess.CalledProcessError as e: - print("命令执行失败") - print(f"错误信息 {e.stderr.strip()}") - - else: - print("没有找到可连接的.abc文件") + except subprocess.CalledProcessError as e: + print("错误: 链接失败") + print("错误详情:", e.stderr.strip()) + raise # 可以选择抛出异常或处理错误 def run_test(res_file_name): -- Gitee From 8267995418ff55505e086a11e1aafa1b89eabfb5 Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Mon, 30 Jun 2025 14:57:40 +0800 Subject: [PATCH 4/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- libs/arkts1.2/build_test.py | 105 ++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py index 250a905..c79d163 100644 --- a/libs/arkts1.2/build_test.py +++ b/libs/arkts1.2/build_test.py @@ -20,36 +20,36 @@ import sys import json import subprocess -es2PandaPath = "arkcompiler/runtime_core/static_core/out/bin/es2panda" -arkLinkPath = "arkcompiler/runtime_core/static_core/out/bin/ark_link" -arkPath = "arkcompiler/runtime_core/static_core/out/bin/ark" -etsStdLibPath = "arkcompiler/runtime_core/static_core/out/plugins/ets/etsstdlib.abc" -configPath = "arkcompiler/runtime_core/static_core/out/bin/arktsconfig.json" -hypiumPath = "test/testfwk/arkxtest/jsunit/src_static/" +ES2PANDAPATH = "arkcompiler/runtime_core/static_core/out/bin/es2panda" +ARKLINKPATH = "arkcompiler/runtime_core/static_core/out/bin/ark_link" +ARKPATH = "arkcompiler/runtime_core/static_core/out/bin/ark" +ETSSTDLIBPATH = "arkcompiler/runtime_core/static_core/out/plugins/ets/etsstdlib.abc" +CONFIGPATH = "arkcompiler/runtime_core/static_core/out/bin/arktsconfig.json" +HYPIUMPATH = "test/testfwk/arkxtest/jsunit/src_static/" -def build_tools(compileFileList): +def build_tools(compile_fileList): """ 编译工具类 """ - absEs2PandaPath = get_path_code_dircetory(es2PandaPath) - absTestPath = os.getcwd() + abs_es2panda_Path = get_path_code_dircetory(ES2PANDAPATH) + abs_test_path = os.getcwd() # 1. 创建输出目录 - outputDir = os.path.join(absTestPath, "out") - os.makedirs(outputDir, exist_ok = True) + output_dir = os.path.join(abs_test_path, "out") + os.makedirs(output_dir, exist_ok = True) # 逐个执行编译命令 - for ets_file in compileFileList: + for ets_file in compile_fileList: try: # 获取文件名(不带路径) - file_name = os.path.basename(ets_file) + file_name = os.path.base_name(ets_file) base_name = os.path.splitext(file_name)[0] - output_file_path = os.path.join(outputDir, f"{base_name}.abc") + output_filepath = os.path.join(output_dir, f"{base_name}.abc") # 构造编译命令 - command = [absEs2PandaPath, ets_file, "--output", output_file_path] + command = [abs_es2panda_Path, ets_file, "--output", output_filepath] # 执行命令并获取输出 result = subprocess.run( @@ -61,7 +61,7 @@ def build_tools(compileFileList): ) # 成功编译 - print(f"成功编译'{ets_file}', 输出路径: {output_file_path}") + print(f"成功编译'{ets_file}', 输出路径: {output_filepath}") except Exception as e: print(f"'{ets_file}'编译失败") @@ -107,19 +107,19 @@ def write_arktsconfig_file(): file_map = {} for ets_file in ets_files: module_name = os.path.splitext(ets_file)[0] - relative_path = os.path.join(current_dir,ets_file) + relative_path = os.path.join(current_dir, ets_file) abs_path = get_path_code_dircetory(relative_path) file_map[module_name] = [abs_path] # 3. 定位要写入的 arktsconfig.json文件 - abs_config_path = get_path_code_dircetory(configPath) + abs_config_path = get_path_code_dircetory(CONFIGPATH) # 4. 读取并更新配置 try: with open(abs_config_path, 'r', encoding='utf-8') as f: config = json.load(f) except FileNotFoundError: - config = {"compilerOptions": { "baseUrl":"/code/arkcompiler/runtime_core/static_core", "paths": {} }} + config = { "compilerOptions": { "baseUrl": "/code/arkcompiler/runtime_core/static_core", "paths": {} }} # 5. 更新配置中的paths(保留之前的配置项) config.setdefault("compilerOptions", {}) @@ -136,10 +136,10 @@ def build_ets_files(): """ 编译hypium、tools、测试用例文件 """ - absHypiumPath = get_path_code_dircetory(hypiumPath) + abs_hypium_path = get_path_code_dircetory(HYPIUMPATH) files_to_compile = [] - for root, dirs, files in os.walk(absHypiumPath): + for root, dirs, files in os.walk(abs_hypium_path): if "testAbility" in dirs: dirs.remove("testAbility") if "testrunner" in dirs: @@ -159,10 +159,10 @@ def build_ets_files(): ets_files = [os.path.join(current_dir, f) for f in os.listdir(current_dir) if f.endswith('.ets')] build_tools(ets_files) - absTestPath = os.getcwd() + abs_test_path = os.getcwd() test_files = [] - for root, dirs, files in os.walk(absTestPath): + for root, dirs, files in os.walk(abs_test_path): for file in files: if file.endswith(".ets"): file_abs_path = os.path.join(root, file) @@ -171,37 +171,48 @@ def build_ets_files(): def collect_abc_files(res_file_name): - """ - 收集所有需要链接的.abc文件路径(包括out目录和src.json中配置的路径) - 返回: abc文件路径列表 - """ - absOutPath = os.path.join(os.getcwd(), "out") + abs_out_path = os.path.join(os.getcwd(), "out") abc_files = [] # 1. 收集out目录下的.abc文件 - out_files = [os.path.join("./out", f) - for f in os.listdir(absOutPath) - if f.endswith('.abc')] - abc_files.extend(out_files) + if os.path.exists(abs_out_path): + out_files = [ + os.path.join("./out", f) + for f in os.listdir(abs_out_path) + if f.endswith('.abc') + ] + abc_files.extend(out_files) # 2. 收集src.json中配置的.abc文件 + abc_files.extend(load_abc_from_src_json()) + + return abc_files + + +def load_abc_from_src_json(): + abc_files = [] src_json_path = os.path.join(os.getcwd(), "src.json") + + if not os.path.exists(src_json_path): + print(f"提示: 配置文件 {src_json_path} 未找到,跳过src.json收集") + return abc_files + try: with open(src_json_path, 'r') as f: src_data = json.load(f) - for path in src_data.get("src_path", []): - if os.path.isfile(path) and path.endswith('.abc'): - abc_files.append(path) - else: - print(f"警告: 路径 {path} 不存在或不是.abc文件,已跳过") - - except FileNotFoundError: - print(f"提示: 配置文件 {src_json_path} 未找到,跳过src.json收集") except json.JSONDecodeError: print(f"错误: 配置文件 {src_json_path} JSON格式错误") + return abc_files except Exception as e: print(f"读取src.json时发生意外错误: {str(e)}") - + return abc_files + + for path in src_data.get("src_path", []): + if os.path.isfile(path) and path.endswith('.abc'): + abc_files.append(path) + else: + print(f"警告: 路径 {path} 不存在或不是.abc文件,已跳过") + return abc_files @@ -209,7 +220,7 @@ def link_abc_files(res_file_name): """ 链接所有abc文件生成最终的test.abc """ - absArkLinkPath = get_path_code_dircetory(arkLinkPath) + abs_arklink_path = get_path_code_dircetory(ARKLINKPATH) abc_files = collect_abc_files(res_file_name) if not abc_files: @@ -217,7 +228,7 @@ def link_abc_files(res_file_name): return command = [ - absArkLinkPath, + abs_arklink_path, f"--output={res_file_name}.abc", "--", *abc_files @@ -245,13 +256,13 @@ def run_test(res_file_name): """ 执行生成的abc文件并生成报告日志 """ - absArkPath = get_path_code_dircetory(arkPath) - absEtsStdLibPath = get_path_code_dircetory(etsStdLibPath) + abs_ark_path = get_path_code_dircetory(ARKPATH) + abs_etsstdlib_path = get_path_code_dircetory(ETSSTDLIBPATH) tests_dir_name = res_file_name log_file = os.path.join(os.getcwd(), f"{tests_dir_name}.log") command = [ - absArkPath, - f"--boot-panda-files={absEtsStdLibPath}", + abs_ark_path, + f"--boot-panda-files={abs_etsstdlib_path}", f"--load-runtimes=ets", f"{tests_dir_name}.abc", f"OpenHarmonyTestRunner/ETSGLOBAL::main" -- Gitee From ffac180a9c532e6fcce8e625ce2a187bb99abcdf Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Mon, 30 Jun 2025 15:05:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- libs/arkts1.2/build_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py index c79d163..9f48657 100644 --- a/libs/arkts1.2/build_test.py +++ b/libs/arkts1.2/build_test.py @@ -28,12 +28,12 @@ CONFIGPATH = "arkcompiler/runtime_core/static_core/out/bin/arktsconfig.json" HYPIUMPATH = "test/testfwk/arkxtest/jsunit/src_static/" -def build_tools(compile_fileList): +def build_tools(compile_filelist): """ 编译工具类 """ - abs_es2panda_Path = get_path_code_dircetory(ES2PANDAPATH) + abs_es2panda_path = get_path_code_dircetory(ES2PANDAPATH) abs_test_path = os.getcwd() # 1. 创建输出目录 @@ -41,7 +41,7 @@ def build_tools(compile_fileList): os.makedirs(output_dir, exist_ok = True) # 逐个执行编译命令 - for ets_file in compile_fileList: + for ets_file in compile_filelist: try: # 获取文件名(不带路径) file_name = os.path.base_name(ets_file) @@ -49,7 +49,7 @@ def build_tools(compile_fileList): output_filepath = os.path.join(output_dir, f"{base_name}.abc") # 构造编译命令 - command = [abs_es2panda_Path, ets_file, "--output", output_filepath] + command = [abs_es2panda_path, ets_file, "--output", output_filepath] # 执行命令并获取输出 result = subprocess.run( @@ -119,7 +119,7 @@ def write_arktsconfig_file(): with open(abs_config_path, 'r', encoding='utf-8') as f: config = json.load(f) except FileNotFoundError: - config = { "compilerOptions": { "baseUrl": "/code/arkcompiler/runtime_core/static_core", "paths": {} }} + config = { "compilerOptions": { "baseUrl": "/code/arkcompiler/runtime_core/static_core", "paths": {} } } # 5. 更新配置中的paths(保留之前的配置项) config.setdefault("compilerOptions", {}) -- Gitee From 4277dd95efd9f12b0d37880179922b7b67401a9a Mon Sep 17 00:00:00 2001 From: CrazyRong Date: Mon, 30 Jun 2025 15:11:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?arkts1.2=E6=B5=8B=E8=AF=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E8=84=9A=E6=9C=AC=E4=B8=8E=E5=A4=96=E9=83=A8sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CrazyRong --- libs/arkts1.2/build_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/arkts1.2/build_test.py b/libs/arkts1.2/build_test.py index 9f48657..7d8977f 100644 --- a/libs/arkts1.2/build_test.py +++ b/libs/arkts1.2/build_test.py @@ -119,8 +119,8 @@ def write_arktsconfig_file(): with open(abs_config_path, 'r', encoding='utf-8') as f: config = json.load(f) except FileNotFoundError: - config = { "compilerOptions": { "baseUrl": "/code/arkcompiler/runtime_core/static_core", "paths": {} } } - + config = { "compilerOptions": { "baseUrl": "/code/arkcompiler/runtime_core/static_core", "paths": {} }} + # 5. 更新配置中的paths(保留之前的配置项) config.setdefault("compilerOptions", {}) config["compilerOptions"].setdefault("paths", {}) -- Gitee