From 1e96916ac6e6b162c47a65fa0f559080174f1f5f Mon Sep 17 00:00:00 2001 From: lihao550 Date: Wed, 13 Aug 2025 17:15:36 +0800 Subject: [PATCH] convert arkts1.1 by code content Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICS7IC Signed-off-by: lihao Change-Id: I8a7213d2dc9ffa1feb87b72b052d436531e34b7e --- .../interop/run_declgen_standalone.ts | 28 +++++++++++++++++-- .../fast_build/ark_compiler/interop/type.ts | 15 ++++++++++ .../interop/run_declgen_standalone.ts | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb..3dce63cb8 100644 --- a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -23,6 +23,8 @@ import { import { ArkTSEvolutionModule, BuildType, + CodeInput, + CodeInputParams, DeclFilesConfig, DECLGEN_CACHE_FILE, Params, @@ -34,7 +36,7 @@ import path from 'path'; import * as ts from 'typescript'; import { EXTNAME_D_ETS, EXTNAME_JS } from '../common/ark_define'; import { getRealModulePath } from '../../system_api/api_check_utils'; -import { generateInteropDecls } from 'declgen/build/src/generateInteropDecls'; +import { generateInteropDecls, generateInteropDeclsFromCode } from 'declgen/build/src/generateInteropDecls'; import { calculateFileHash } from '../utils'; import { processInteropUI } from '../../../process_interop_ui'; @@ -47,7 +49,11 @@ export function run(param: Params): boolean { return; } if (task.buildTask === BuildType.DECLGEN) { - DeclfileProductor.getInstance().runDeclgen(moduleInfo); + if (task.codeInputs && task.codeInputs.length > 0) { + DeclfileProductor.getInstance().runDeclgenFromCode(moduleInfo, task.codeInputs); + } else { + DeclfileProductor.getInstance().runDeclgen(moduleInfo); + } } else if (task.buildTask === BuildType.INTEROP_CONTEXT) { DeclfileProductor.getInstance().writeDeclFileInfo(moduleInfo, task.mainModuleName); } else if (task.buildTask === BuildType.BYTE_CODE_HAR) { @@ -172,6 +178,24 @@ class DeclfileProductor { fs.writeFileSync(cachePath, JSON.stringify(newCache, null, 2)); } + runDeclgenFromCode(moduleInfo: ArkTSEvolutionModule, codeInputs: CodeInput[]): void { + const config: CodeInputParams = { + codeInputs: codeInputs, + outDir: moduleInfo.declgenV2OutPath, + rootDir: moduleInfo.modulePath, + customResolveModuleNames: resolveModuleNames, + customCompilerOptions: DeclfileProductor.compilerOptions, + includePaths: [moduleInfo.modulePath] + }; + + if (!fs.existsSync(config.outDir)) { + fs.mkdirSync(config.outDir, { recursive: true }); + } + + generateInteropDeclsFromCode(config); + processInteropUI(FileManager.arkTSModuleMap.get(moduleInfo.packageName)?.declgenV2OutPath); + } + writeDeclFileInfo(moduleInfo: ArkTSEvolutionModule, mainModuleName: string): void { moduleInfo.isNative = moduleInfo.isNative ?? moduleInfo.packageName.endsWith('.so'); moduleInfo.dynamicFiles.forEach(file => { diff --git a/compiler/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/fast_build/ark_compiler/interop/type.ts index 3a3dc2a11..491d709bd 100644 --- a/compiler/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/fast_build/ark_compiler/interop/type.ts @@ -37,6 +37,11 @@ export interface Params { tasks: taskInfo[]; } +export interface CodeInput { + fileName: string; + content: string; +} + export interface ProjectConfig { cachePath: string; bundleName: string; @@ -54,6 +59,7 @@ interface taskInfo { packageName: string; buildTask: BuildType; mainModuleName?: string; + codeInputs?: CodeInput[]; } export interface AliasConfig { @@ -78,6 +84,15 @@ export interface RunnerParms { includePaths?: string[]; } +export interface CodeInputParams { + codeInputs: CodeInput[]; + outDir: string; + rootDir?: string; + customResolveModuleNames?: (moduleName: string[], containingFile: string) => ts.ResolvedModuleFull[]; + customCompilerOptions?: ts.CompilerOptions; + includePaths?: string[]; +} + export interface DeclFilesConfig { packageName: string; files: { diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb..962b21b04 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -24,11 +24,11 @@ import { ArkTSEvolutionModule, BuildType, DeclFilesConfig, - DECLGEN_CACHE_FILE, Params, ProjectConfig, RunnerParms } from './type'; +import { DECLGEN_CACHE_FILE } from './pre_define'; import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -- Gitee