From 26a09597d5f1df72bf71745365c7ba86f5b373f2 Mon Sep 17 00:00:00 2001 From: dongchao Date: Mon, 1 Sep 2025 10:51:52 +0800 Subject: [PATCH] Disable annotation decl generation in interop sdk Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVOPE Signed-off-by: dongchao Change-Id: Ibec5159a7f8b2f0deba63cead6899d1cf5cce783 --- ets2panda/bindings/native/src/bridges.cpp | 10 ++++++---- .../bindings/src/common/Es2pandaNativeModule.ts | 3 ++- ets2panda/bindings/src/common/driver_helper.ts | 7 +++++-- ets2panda/bindings/src/lsp/lsp_helper.ts | 2 +- ets2panda/declgen_ets2ts/declgenEts2Ts.cpp | 3 ++- ets2panda/declgen_ets2ts/declgenEts2Ts.h | 1 + .../driver/build_system/src/build/base_mode.ts | 5 ++++- .../build_system/src/build/declgen_worker.ts | 4 +++- ets2panda/driver/build_system/src/types.ts | 1 + ets2panda/public/es2panda_lib.cpp | 4 +++- ets2panda/public/es2panda_lib.h | 2 +- ets2panda/public/es2panda_lib.idl.erb | 3 +++ ets2panda/scripts/arkui.properties | 2 +- ets2panda/test/unit/declgen/CMakeLists.txt | 1 + ...test_ets2ts_isolated_annotation-expected.txt | 1 + .../test_ets2ts_isolated_annotation.ets | 17 +++++++++++++++++ .../declgen/test_ets2ts_isolated_declgen.cpp | 2 +- 17 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt create mode 100644 ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets diff --git a/ets2panda/bindings/native/src/bridges.cpp b/ets2panda/bindings/native/src/bridges.cpp index e34e2dbb39..5e4c941d47 100644 --- a/ets2panda/bindings/native/src/bridges.cpp +++ b/ets2panda/bindings/native/src/bridges.cpp @@ -45,14 +45,16 @@ KNativePointer impl_CreateContextFromStringWithHistory(KNativePointer configPtr, TS_INTEROP_3(CreateContextFromStringWithHistory, KNativePointer, KNativePointer, KStringPtr, KStringPtr) KInt impl_GenerateTsDeclarationsFromContext(KNativePointer contextPtr, KStringPtr &outputDeclEts, KStringPtr &outputEts, - KBoolean exportAll, KBoolean isolated, KStringPtr &recordFile) + KBoolean exportAll, KBoolean isolated, KStringPtr &recordFile, + KBoolean genAnnotations) { auto context = reinterpret_cast(contextPtr); return static_cast(GetPublicImpl()->GenerateTsDeclarationsFromContext( - context, outputDeclEts.Data(), outputEts.Data(), exportAll != 0, isolated != 0, recordFile.Data())); + context, outputDeclEts.Data(), outputEts.Data(), exportAll != 0, isolated != 0, recordFile.Data(), + genAnnotations != 0)); } -TS_INTEROP_6(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean, - KStringPtr) +TS_INTEROP_7(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean, + KStringPtr, KBoolean) KNativePointer impl_CreateContextFromFile(KNativePointer configPtr, KStringPtr &filenamePtr) { diff --git a/ets2panda/bindings/src/common/Es2pandaNativeModule.ts b/ets2panda/bindings/src/common/Es2pandaNativeModule.ts index b1f2d4da0d..269b7917d9 100644 --- a/ets2panda/bindings/src/common/Es2pandaNativeModule.ts +++ b/ets2panda/bindings/src/common/Es2pandaNativeModule.ts @@ -83,7 +83,8 @@ export class Es2pandaNativeModule { outputEts: String, exportAll: KBoolean, isolated: KBoolean, - recordFile: String + recordFile: String, + genAnnotations: KBoolean ): KPtr { throw new Error('Not implemented'); } diff --git a/ets2panda/bindings/src/common/driver_helper.ts b/ets2panda/bindings/src/common/driver_helper.ts index 0f3b97b943..73d9d97fb3 100644 --- a/ets2panda/bindings/src/common/driver_helper.ts +++ b/ets2panda/bindings/src/common/driver_helper.ts @@ -82,17 +82,20 @@ export class DriverHelper { etsOutPath: string, exportAll: boolean, isolated: boolean, - recordFile: string + recordFile: string, + genAnnotations: boolean ): void { let exportAll_: KBoolean = exportAll ? 1 : 0; let isolated_: KBoolean = isolated ? 1 : 0; + let genAnnotations_: KBoolean = genAnnotations ? 1 : 0; global.es2panda._GenerateTsDeclarationsFromContext( this._cfg.peer, declOutPath, etsOutPath, exportAll_, isolated_, - recordFile + recordFile, + genAnnotations_ ); } } diff --git a/ets2panda/bindings/src/lsp/lsp_helper.ts b/ets2panda/bindings/src/lsp/lsp_helper.ts index 44d91ac0e1..99a4f26f2e 100644 --- a/ets2panda/bindings/src/lsp/lsp_helper.ts +++ b/ets2panda/bindings/src/lsp/lsp_helper.ts @@ -229,7 +229,7 @@ export class Lsp { this.declFileMap[declEtsOutputPath] = filePath; ensurePathExists(declEtsOutputPath); ensurePathExists(etsOutputPath); - global.es2pandaPublic._GenerateTsDeclarationsFromContext(ctx, declEtsOutputPath, etsOutputPath, 1, 0, ''); + global.es2pandaPublic._GenerateTsDeclarationsFromContext(ctx, declEtsOutputPath, etsOutputPath, 1, 0, '', 1); } finally { this.destroyContext(cfg, ctx); } diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 30b22ef0be..6318d06191 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -1123,7 +1123,8 @@ std::string TSDeclGen::RemoveModuleExtensionName(const std::string &filepath) template void TSDeclGen::GenAnnotations(const ir::AnnotationAllowed *node) { - if (node == nullptr || (!node->HasAnnotations() && node->Annotations().size() == 0U)) { + if (!declgenOptions_.genAnnotations || node == nullptr || + (!node->HasAnnotations() && node->Annotations().size() == 0U)) { return; } GenSeparated( diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.h b/ets2panda/declgen_ets2ts/declgenEts2Ts.h index 7e79a37f53..3ec916d23b 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.h +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.h @@ -35,6 +35,7 @@ struct DeclgenOptions { std::string outputDeclEts; std::string outputEts; std::string recordFile; + bool genAnnotations = true; }; // Consume program after checker stage and generate out_path typescript file with declarations diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index eeb15985ea..231eaa7349 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -125,6 +125,7 @@ export abstract class BaseMode { public byteCodeHar: boolean; public es2pandaMode: number; public skipDeclCheck: boolean; + public genDeclAnnotations: boolean; constructor(buildConfig: BuildConfig) { this.buildConfig = buildConfig; @@ -166,6 +167,7 @@ export abstract class BaseMode { : ES2PANDA_MODE.RUN ); this.skipDeclCheck = buildConfig?.skipDeclCheck as boolean ?? true; + this.genDeclAnnotations = buildConfig?.genDeclAnnotations as boolean ?? true; } public declgen(fileInfo: CompileFileInfo): void { @@ -227,7 +229,8 @@ export abstract class BaseMode { etsOutputPath, false, false, - staticRecordRelativePath + staticRecordRelativePath, + this.genDeclAnnotations ); // Generate 1.0 declaration files & 1.0 glue code this.logger.printInfo('declaration files generated'); } catch (error) { diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index fcb5ae0adc..acdaae4687 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -98,6 +98,7 @@ process.on('message', async (message: { arktsGlobal.compilerContext = arkts.Context.createFromStringWithHistory(source); pluginDriver.getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); const skipDeclCheck = buildConfig?.skipDeclCheck ?? true; + const genDeclAnnotations = buildConfig?.genDeclAnnotations ?? true; arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer, skipDeclCheck); let ast = arkts.EtsScript.fromContext(); @@ -114,7 +115,8 @@ process.on('message', async (message: { etsOutputPath, false, false, - staticRecordRelativePath + staticRecordRelativePath, + genDeclAnnotations ); logger.printInfo(`[declgen] ${fileInfo.filePath} processed successfully`); diff --git a/ets2panda/driver/build_system/src/types.ts b/ets2panda/driver/build_system/src/types.ts index fe66126e83..73d44ab46b 100644 --- a/ets2panda/driver/build_system/src/types.ts +++ b/ets2panda/driver/build_system/src/types.ts @@ -173,6 +173,7 @@ export interface DeclgenConfig { declgenBridgeCodePath?: string; skipDeclCheck?: boolean; continueOnError?: boolean; + genDeclAnnotations?: boolean; } export interface LoggerConfig { diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 671ec8b85d..ea052d5e3d 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -1270,7 +1270,8 @@ extern "C" es2panda_AstNode **AllDeclarationsByNameFromProgram([[maybe_unused]] extern "C" __attribute__((unused)) int GenerateTsDeclarationsFromContext(es2panda_Context *ctx, const char *outputDeclEts, const char *outputEts, bool exportAll, - bool isolated, const char *recordFile) + bool isolated, const char *recordFile, + bool genAnnotations) { auto *ctxImpl = reinterpret_cast(ctx); auto *checker = reinterpret_cast(ctxImpl->GetChecker()); @@ -1281,6 +1282,7 @@ extern "C" __attribute__((unused)) int GenerateTsDeclarationsFromContext(es2pand declgenOptions.outputEts = outputEts ? outputEts : ""; declgenOptions.isolated = isolated; declgenOptions.recordFile = recordFile ? recordFile : ""; + declgenOptions.genAnnotations = genAnnotations; return ark::es2panda::declgen_ets2ts::GenerateTsDeclarations(checker, ctxImpl->parserProgram, declgenOptions) ? 0 : 1; diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index a1562a4fd6..992e068bbe 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -274,7 +274,7 @@ struct CAPI_EXPORT es2panda_Impl { int (*GenerateTsDeclarationsFromContext)(es2panda_Context *context, const char *outputDeclEts, const char *outputEts, bool exportAll, bool isolated, - const char *recordFile); + const char *recordFile, bool genAnnotations); void (*InsertETSImportDeclarationAndParse)(es2panda_Context *context, es2panda_Program *program, es2panda_AstNode *importDeclaration); int (*GenerateStaticDeclarationsFromContext)(es2panda_Context *context, const char *outputPath); diff --git a/ets2panda/public/es2panda_lib.idl.erb b/ets2panda/public/es2panda_lib.idl.erb index 56f8266106..b91f57b1c6 100644 --- a/ets2panda/public/es2panda_lib.idl.erb +++ b/ets2panda/public/es2panda_lib.idl.erb @@ -235,6 +235,9 @@ interface es2panda_Impl { ir.AstNode FirstDeclarationByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name); sequence AllDeclarationsByNameFromNode(es2panda_Context ctx, ir.AstNode node, String name); sequence AllDeclarationsByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name); + i32 GenerateTsDeclarationsFromContext(es2panda_Context ctx, String outputDeclEts, String outputEts, + boolean exportAll, boolean isolated, String recordFile, + boolean genAnnotations); void InsertETSImportDeclarationAndParse(es2panda_Context context, es2panda_Program program, ETSImportDeclaration node); i32 GenerateStaticDeclarationsFromContext(es2panda_Context context, String outputPath); diff --git a/ets2panda/scripts/arkui.properties b/ets2panda/scripts/arkui.properties index 7f0cf795d6..d5acadafe7 100644 --- a/ets2panda/scripts/arkui.properties +++ b/ets2panda/scripts/arkui.properties @@ -1,3 +1,3 @@ ARKUI_DEV_REPO=https://gitee.com/rri_opensource/koala_projects.git -ARKUI_DEV_BRANCH=panda_rev_11 +ARKUI_DEV_BRANCH=panda_rev_11-interop_0702 ARKUI_DEST=koala-sig diff --git a/ets2panda/test/unit/declgen/CMakeLists.txt b/ets2panda/test/unit/declgen/CMakeLists.txt index 601c09c31e..0bf413a536 100644 --- a/ets2panda/test/unit/declgen/CMakeLists.txt +++ b/ets2panda/test/unit/declgen/CMakeLists.txt @@ -31,6 +31,7 @@ set(ETS2TS_ISOLATED_TESTS "./ets2ts_isolated/test_ets2ts_isolated_interface.ets" "./ets2ts_isolated/test_ets2ts_isolated_function_with_optional_parameter.ets" "./ets2ts_isolated/test_ets2ts_infer_function_return_type_with_import_symbol.ets" + "./ets2ts_isolated/test_ets2ts_isolated_annotation.ets" ) foreach(TEST_DATA IN ITEMS ${DECLGEN_PLUGIN_TESTS}) diff --git a/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt new file mode 100644 index 0000000000..b1725174a5 --- /dev/null +++ b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt @@ -0,0 +1 @@ +export declare function foo(): void; diff --git a/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets new file mode 100644 index 0000000000..071cbf9efb --- /dev/null +++ b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets @@ -0,0 +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. + */ + +@Builer +export function foo(): void {} \ No newline at end of file diff --git a/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp b/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp index a2049a3800..319a02bd46 100644 --- a/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp +++ b/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp @@ -49,7 +49,7 @@ int main(int argc, char **argv) impl->ProceedToState(context, ES2PANDA_STATE_CHECKED); CheckForErrors("CHECKED", context); std::string declName = GetDeclPrefix(argv[argc - 1]) + ".d.ets"; - int result = impl->GenerateTsDeclarationsFromContext(context, declName.c_str(), "dump.ets", false, true, ""); + int result = impl->GenerateTsDeclarationsFromContext(context, declName.c_str(), "dump.ets", false, true, "", false); if (result != 0) { std::cerr << "FAILED TO GENERATE DECLARATIONS" << std::endl; return result; -- Gitee