diff --git a/ets2panda/driver/build_system/src/build/compile_thread_worker.ts b/ets2panda/driver/build_system/src/build/compile_thread_worker.ts index ab98fac0c5d670bfd9c6c71e6474745e7e00e192..fdb40b5305448a0656044f69f7756b72ab184e10 100644 --- a/ets2panda/driver/build_system/src/build/compile_thread_worker.ts +++ b/ets2panda/driver/build_system/src/build/compile_thread_worker.ts @@ -14,8 +14,7 @@ */ import { parentPort, workerData } from 'worker_threads'; -import { CompileFileInfo, JobInfo } from '../types'; -import * as fs from 'fs'; +import { JobInfo } from '../types'; import * as path from 'path'; import { changeFileExtension, @@ -38,6 +37,7 @@ import { } from '../logger'; import { ErrorCode } from '../error_code'; import { KitImportTransformer } from '../plugins/KitImportTransformer'; +import { initKoalaModules } from '../init/init_koala_modules'; const { workerId } = workerData; @@ -45,8 +45,7 @@ function compileAbc(jobInfo: JobInfo): void { let config = jobInfo.buildConfig as BuildConfig; Logger.getInstance(config); PluginDriver.getInstance().initPlugins(config); - const koalaWrapperPath = path.resolve(config.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); - let { arkts, arktsGlobal } = require(koalaWrapperPath); + let { arkts, arktsGlobal } = initKoalaModules(config) const isDebug = config.buildMode === BUILD_MODE.DEBUG; let errorStatus = false; @@ -124,8 +123,7 @@ function compileExternalProgram(jobInfo: JobInfo): void { let config = jobInfo.buildConfig as BuildConfig; Logger.getInstance(config); PluginDriver.getInstance().initPlugins(config); - const koalaWrapperPath = path.resolve(config.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); - let { arkts, arktsGlobal } = require(koalaWrapperPath); + let { arkts, arktsGlobal } = initKoalaModules(config) const isDebug = config.buildMode === BUILD_MODE.DEBUG; let errorStatus = false; diff --git a/ets2panda/driver/build_system/src/build/compile_worker.ts b/ets2panda/driver/build_system/src/build/compile_worker.ts index 1ae817d7d03b710f5eedc669d1713972c75c6aa8..734b95a39d1814192ddc5d412fc9b5a7035e796c 100644 --- a/ets2panda/driver/build_system/src/build/compile_worker.ts +++ b/ets2panda/driver/build_system/src/build/compile_worker.ts @@ -31,6 +31,7 @@ import { OHOS_MODULE_TYPE } from '../types'; import { Logger } from '../logger'; +import { initKoalaModules } from '../init/init_koala_modules'; process.on('message', (message: { taskList: CompileFileInfo[]; @@ -45,8 +46,7 @@ process.on('message', (message: { Logger.getInstance(buildConfig); PluginDriver.getInstance().initPlugins(buildConfig); - const koalaWrapperPath = process.env.KOALA_WRAPPER_PATH ?? path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); - let { arkts, arktsGlobal } = require(koalaWrapperPath); + let { arkts, arktsGlobal } = initKoalaModules(buildConfig) const { KitImportTransformer } = require('../plugins/KitImportTransformer'); for (const fileInfo of taskList) { diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index e25cdff91d5cae4ea0c394572c7d12827aaf852c..9e351ba69baa9c1ccf7ad92b0fbc0160998c0c30 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -27,12 +27,12 @@ import { import { DECL_ETS_SUFFIX, DECL_TS_SUFFIX, - KOALA_WRAPPER_PATH_FROM_SDK, STATIC_RECORD_FILE, STATIC_RECORD_FILE_CONTENT, TS_SUFFIX } from '../pre_define'; import { PluginDriver, PluginHook } from '../plugins/plugins_driver'; +import { initKoalaModules } from '../init/init_koala_modules'; process.on('message', (message: { taskList: CompileFileInfo[]; @@ -49,9 +49,7 @@ process.on('message', (message: { const pluginDriver = PluginDriver.getInstance(); pluginDriver.initPlugins(buildConfig); - const koalaWrapperPath = path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); - let { arkts, arktsGlobal } = require(koalaWrapperPath); - arktsGlobal.es2panda._SetUpSoPath(buildConfig.pandaSdkPath); + let { arkts, arktsGlobal } = initKoalaModules(buildConfig) for (const fileInfo of taskList) { let errorStatus = false; diff --git a/ets2panda/driver/build_system/src/init/init_koala_modules.ts b/ets2panda/driver/build_system/src/init/init_koala_modules.ts new file mode 100644 index 0000000000000000000000000000000000000000..f24b5eba641296e6da604559b415bd5fca44ac41 --- /dev/null +++ b/ets2panda/driver/build_system/src/init/init_koala_modules.ts @@ -0,0 +1,48 @@ +/* + * 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 { KOALA_WRAPPER_PATH_FROM_SDK, MEMO_PLUGIN_PATH_FROM_SDK, UI_PLUGIN_PATH_FROM_SDK } from "../pre_define"; +import { BuildConfig } from "../types"; +import path from "path" + + +let koalaModule: any; + +export function initKoalaModules(buildConfig: BuildConfig) { + if (koalaModule) return koalaModule + + const koalaWrapperPath = process.env.KOALA_WRAPPER_PATH ?? path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); + koalaModule = require(koalaWrapperPath); + koalaModule.arktsGlobal.es2panda._SetUpSoPath(buildConfig.pandaSdkPath); + buildConfig.arkts = koalaModule.arkts; + buildConfig.arktsGlobal = koalaModule.arktsGlobal; + return koalaModule +} + +export function initKoalaPlugins(projectConfig: BuildConfig): void { + + const uiPluginPath = path.resolve(projectConfig.buildSdkPath, UI_PLUGIN_PATH_FROM_SDK); + const memoPluginPath = path.resolve(projectConfig.buildSdkPath, MEMO_PLUGIN_PATH_FROM_SDK); + + // TODO: need change in hvigor + if (process.env.USE_KOALA_UI_PLUGIN) { + projectConfig.plugins['ArkUI'] = uiPluginPath + } + + if (process.env.USE_KOALA_MEMO_PLUGIN) { + projectConfig.plugins['ArkUI-Memo'] = memoPluginPath + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/src/init/process_build_config.ts b/ets2panda/driver/build_system/src/init/process_build_config.ts index 769b18939ec00ac69c96c6c20aa454133bbc6bfe..5f8a6066b7f3c8042a450493b0bf9233b96dde7a 100644 --- a/ets2panda/driver/build_system/src/init/process_build_config.ts +++ b/ets2panda/driver/build_system/src/init/process_build_config.ts @@ -27,7 +27,6 @@ import { ARKTS, COMPONENT, KITS, - KOALA_WRAPPER_PATH_FROM_SDK, PANDA_SDK_PATH_FROM_SDK, PROJECT_BUILD_CONFIG_FILE } from '../pre_define'; @@ -42,6 +41,7 @@ import { BUILD_MODE, AliasConfig } from '../types'; +import { initKoalaModules } from './init_koala_modules'; export function processBuildConfig(projectConfig: BuildConfig): BuildConfig { let buildConfig: BuildConfig = { @@ -58,7 +58,7 @@ export function processBuildConfig(projectConfig: BuildConfig): BuildConfig { checkCacheProjectConfig(buildConfig); initPlatformSpecificConfig(buildConfig); initBuildEnv(buildConfig); - initKoalaWrapper(buildConfig); + initKoalaModules(buildConfig); PluginDriver.getInstance().initPlugins(buildConfig); initAliasConfig(buildConfig); initInteropSDKInfo(buildConfig); @@ -142,14 +142,6 @@ export function initBuildEnv(buildConfig: BuildConfig): void { logger.printInfo(`Updated PATH: ${process.env.PATH}`); } -function initKoalaWrapper(buildConfig: BuildConfig): void { - let koalaWrapperPath: string = process.env.KOALA_WRAPPER_PATH ?? path.resolve(buildConfig.buildSdkPath as string, KOALA_WRAPPER_PATH_FROM_SDK); - const { arkts, arktsGlobal } = require(koalaWrapperPath); - buildConfig.arkts = arkts; - buildConfig.arktsGlobal = arktsGlobal; - buildConfig.arktsGlobal.es2panda._SetUpSoPath(buildConfig.pandaSdkPath); -} - function initAliasConfig(buildConfig: BuildConfig): void { buildConfig.aliasConfig = new Map(); buildConfig.sdkAliasMap = buildConfig.sdkAliasMap instanceof Map diff --git a/ets2panda/driver/build_system/src/plugins/plugins_driver.ts b/ets2panda/driver/build_system/src/plugins/plugins_driver.ts index 9213df98d63bc2e8fc9a040064d974c048dd9902..4af2ec6aad84af74ab156975ba850ee4dc42de2a 100644 --- a/ets2panda/driver/build_system/src/plugins/plugins_driver.ts +++ b/ets2panda/driver/build_system/src/plugins/plugins_driver.ts @@ -21,8 +21,7 @@ import { import { BuildConfig } from '../types'; import { ErrorCode } from '../error_code'; import { FileManager } from './FileManager'; -import path from 'path' -import { MEMO_PLUGIN_PATH_FROM_SDK, UI_PLUGIN_PATH_FROM_SDK } from '../pre_define'; +import { initKoalaPlugins } from '../init/init_koala_modules'; export enum PluginHook { NEW = 'afterNew', @@ -151,27 +150,12 @@ export class PluginDriver { PluginDriver.instance = undefined; } - private initKoalaPlugins(projectConfig: BuildConfig): void { - - const uiPluginPath = path.resolve(projectConfig.buildSdkPath, UI_PLUGIN_PATH_FROM_SDK); - const memoPluginPath = path.resolve(projectConfig.buildSdkPath, MEMO_PLUGIN_PATH_FROM_SDK); - - // TODO: need change in hvigor - if (process.env.USE_KOALA_UI_PLUGIN) { - projectConfig.plugins['ArkUI'] = uiPluginPath - } - - if (process.env.USE_KOALA_MEMO_PLUGIN) { - projectConfig.plugins['ArkUI-Memo'] = memoPluginPath - } - } - public initPlugins(projectConfig: BuildConfig): void { if (!projectConfig || !projectConfig.plugins) { return; } - this.initKoalaPlugins(projectConfig) + initKoalaPlugins(projectConfig) const pluginResults: RawPlugins[] = Object.entries(projectConfig.plugins).map(([key, value]) => { try {