From f25f58ef1dff2c8b344bb1dc1142c48fa4b96267 Mon Sep 17 00:00:00 2001 From: dongchao Date: Tue, 3 Jun 2025 12:05:08 +0800 Subject: [PATCH] Fix build_system codecheck and proceedToState Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICCBZ0 Signed-off-by: dongchao Change-Id: I10c4a97076ffb931dbe12a8510f1f4ff5e130204 --- .../build_system/src/build/base_mode.ts | 30 ++------ .../src/build/compile_thread_worker.ts | 76 +++++++++---------- .../build_system/src/build/compile_worker.ts | 6 +- .../build_system/src/build/declgen_worker.ts | 4 +- .../src/plugins/plugins_driver.ts | 2 +- 5 files changed, 48 insertions(+), 70 deletions(-) diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 5d374555e6..e8ac0aecfb 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -174,13 +174,13 @@ export abstract class BaseMode { arktsGlobal.compilerContext = arkts.Context.createFromString(source); PluginDriver.getInstance().getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, true); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer, true); let ast = arkts.EtsScript.fromContext(); PluginDriver.getInstance().getPluginContext().setArkTSAst(ast); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, true); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer, true); ast = arkts.EtsScript.fromContext(); PluginDriver.getInstance().getPluginContext().setArkTSAst(ast); @@ -240,21 +240,21 @@ export abstract class BaseMode { arktsGlobal.compilerContext = arkts.Context.createFromString(source); PluginDriver.getInstance().getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer); this.logger.printInfo('es2panda proceedToState parsed'); let ast = arkts.EtsScript.fromContext(); PluginDriver.getInstance().getPluginContext().setArkTSAst(ast); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); this.logger.printInfo('plugin parsed finished'); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer); this.logger.printInfo('es2panda proceedToState checked'); ast = arkts.EtsScript.fromContext(); PluginDriver.getInstance().getPluginContext().setArkTSAst(ast); PluginDriver.getInstance().runPluginHook(PluginHook.CHECKED); this.logger.printInfo('plugin checked finished'); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED, arktsGlobal.compilerContext.peer); this.logger.printInfo('es2panda bin generated'); } catch (error) { errorStatus = true; @@ -1225,26 +1225,6 @@ export abstract class BaseMode { }); } - private updateDependantJobs(jobId: string, processingJobs: Set, jobs: Record, queues: Queues): void { - finishedJob.push(jobId); - processingJobs.delete(jobId); - const completedJob = jobs[jobId]; - completedJob.dependants.forEach(depJobId => { - const depJob = jobs[depJobId]; - // During incremental compilation, the dependants task does not necessarily exist - if (!depJob) { - return; - } - const depIndex = depJob.dependencies.indexOf(jobId); - if (depIndex !== -1) { - depJob.dependencies.splice(depIndex, 1); - if (depJob.dependencies.length === 0) { - this.addJobToQueues(depJob, queues); - } - } - }); - } - private assignTaskToIdleWorker( workerInfo: WorkerInfo, queues: Queues, 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 c8aaed5662..db45e16117 100644 --- a/ets2panda/driver/build_system/src/build/compile_thread_worker.ts +++ b/ets2panda/driver/build_system/src/build/compile_thread_worker.ts @@ -36,34 +36,33 @@ import { ErrorCode } from '../error_code'; const { workerId } = workerData; 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 buildConfig = jobInfo.buildConfig as BuildConfig; + Logger.getInstance(buildConfig); + PluginDriver.getInstance().initPlugins(buildConfig); + const koalaWrapperPath = path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); let { arkts, arktsGlobal } = require(koalaWrapperPath); - const isDebug = config.buildMode === BUILD_MODE.DEBUG; + const isDebug = buildConfig.buildMode === BUILD_MODE.DEBUG; let errorStatus = false; - try { - let fileInfo = jobInfo.compileFileInfo; - ensurePathExists(fileInfo.abcFilePath); - - const ets2pandaCmd = [ - '_', '--extension', 'ets', - '--arktsconfig', fileInfo.arktsConfigFile, - '--output', fileInfo.abcFilePath, - ]; + let fileInfo = jobInfo.compileFileInfo; + ensurePathExists(fileInfo.abcFilePath); - if (isDebug) { - ets2pandaCmd.push('--debug-info'); - } - ets2pandaCmd.push(fileInfo.filePath); + const ets2pandaCmd = [ + '_', '--extension', 'ets', + '--arktsconfig', fileInfo.arktsConfigFile, + '--output', fileInfo.abcFilePath, + ]; - let config = arkts.Config.create(ets2pandaCmd).peer; - arktsGlobal.config = config; + if (isDebug) { + ets2pandaCmd.push('--debug-info'); + } + ets2pandaCmd.push(fileInfo.filePath); - let context = arkts.Context.createCacheContextFromFile(config, fileInfo.filePath, jobInfo.globalContextPtr, false).peer; + let config = arkts.Config.create(ets2pandaCmd).peer; + arktsGlobal.config = config; + let context = arkts.Context.createCacheContextFromFile(config, fileInfo.filePath, jobInfo.globalContextPtr, false).peer; + try { PluginDriver.getInstance().getPluginContext().setContextPtr(context); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context); @@ -88,7 +87,7 @@ function compileAbc(jobInfo: JobInfo): void { } finally { if (!errorStatus) { // when error occur,wrapper will destroy context. - arktsGlobal.es2panda._DestroyContext(arktsGlobal.compilerContext.peer); + arktsGlobal.es2panda._DestroyContext(context); } PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN); arkts.destroyConfig(arktsGlobal.config); @@ -96,28 +95,27 @@ function compileAbc(jobInfo: JobInfo): void { } 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 buildConfig = jobInfo.buildConfig as BuildConfig; + Logger.getInstance(buildConfig); + PluginDriver.getInstance().initPlugins(buildConfig); + const koalaWrapperPath = path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); let { arkts, arktsGlobal } = require(koalaWrapperPath); - const isDebug = config.buildMode === BUILD_MODE.DEBUG; + const isDebug = buildConfig.buildMode === BUILD_MODE.DEBUG; let errorStatus = false; - try { - let fileInfo = jobInfo.compileFileInfo; - const ets2pandaCmd = ['-', '--extension', 'ets', '--arktsconfig', fileInfo.arktsConfigFile]; - - if (isDebug) { - ets2pandaCmd.push('--debug-info'); - } - ets2pandaCmd.push(fileInfo.filePath); + let fileInfo = jobInfo.compileFileInfo; + const ets2pandaCmd = ['-', '--extension', 'ets', '--arktsconfig', fileInfo.arktsConfigFile]; - let config = arkts.Config.create(ets2pandaCmd).peer; - arktsGlobal.config = config; + if (isDebug) { + ets2pandaCmd.push('--debug-info'); + } + ets2pandaCmd.push(fileInfo.filePath); - let context = arkts.Context.createCacheContextFromFile(config, fileInfo.filePath, jobInfo.globalContextPtr, true).peer; + let config = arkts.Config.create(ets2pandaCmd).peer; + arktsGlobal.config = config; + let context = arkts.Context.createCacheContextFromFile(config, fileInfo.filePath, jobInfo.globalContextPtr, true).peer; + try { PluginDriver.getInstance().getPluginContext().setContextPtr(context); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context); @@ -142,7 +140,7 @@ function compileExternalProgram(jobInfo: JobInfo): void { } finally { if (!errorStatus) { // when error occur,wrapper will destroy context. - arktsGlobal.es2panda._DestroyContext(arktsGlobal.compilerContext.peer); + arktsGlobal.es2panda._DestroyContext(context); } PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN); arkts.destroyConfig(arktsGlobal.config); diff --git a/ets2panda/driver/build_system/src/build/compile_worker.ts b/ets2panda/driver/build_system/src/build/compile_worker.ts index 38a1fcdb59..fd5065c39f 100644 --- a/ets2panda/driver/build_system/src/build/compile_worker.ts +++ b/ets2panda/driver/build_system/src/build/compile_worker.ts @@ -70,13 +70,13 @@ process.on('message', (message: { PluginDriver.getInstance().getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer); PluginDriver.getInstance().runPluginHook(PluginHook.CHECKED); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED, arktsGlobal.compilerContext.peer); } catch (error) { errorStatus = true; if (error instanceof Error) { diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index 2d25e9704d..63968d0d15 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -79,13 +79,13 @@ process.on('message', (message: { arktsGlobal.compilerContext = arkts.Context.createFromString(source); pluginDriver.getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, true); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer, true); let ast = arkts.EtsScript.fromContext(); pluginDriver.getPluginContext().setArkTSAst(ast); pluginDriver.runPluginHook(PluginHook.PARSED); - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, true); + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer, true); ast = arkts.EtsScript.fromContext(); pluginDriver.getPluginContext().setArkTSAst(ast); diff --git a/ets2panda/driver/build_system/src/plugins/plugins_driver.ts b/ets2panda/driver/build_system/src/plugins/plugins_driver.ts index 67203f601d..2bd46fcb26 100644 --- a/ets2panda/driver/build_system/src/plugins/plugins_driver.ts +++ b/ets2panda/driver/build_system/src/plugins/plugins_driver.ts @@ -112,7 +112,7 @@ class PluginContext { } } - public getFileManager(): FileManager | undefined{ + public getFileManager(): FileManager | undefined { return this.fileManager; } -- Gitee