diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index a79857d9c7cd816993288ded9ccd8e4270da0f6b..ea7302f5d04cbd8a51d05ed37faea5016972bc50 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -391,6 +391,20 @@ export abstract class BaseMode { arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer); this.logger.printInfo('es2panda proceedToState checked'); + if (this.hasMainModule && (this.byteCodeHar || this.moduleType === OHOS_MODULE_TYPE.SHARED)) { + for (const sourceFilePath of this.buildConfig.compileFiles) { + const filePathFromModuleRoot: string = path.relative(this.moduleRootPath, sourceFilePath); + + const declEtsOutputPath: string = changeFileExtension( + path.join(this.declgenV2OutPath as string, filePathFromModuleRoot), + DECL_ETS_SUFFIX + ); + ensurePathExists(declEtsOutputPath); + + arkts.generateStaticDeclarationsFromContext(declEtsOutputPath); + } + } + ast = arkts.EtsScript.fromContext(); PluginDriver.getInstance().getPluginContext().setArkTSAst(ast); PluginDriver.getInstance().runPluginHook(PluginHook.CHECKED); diff --git a/ets2panda/driver/build_system/src/build/compile_worker.ts b/ets2panda/driver/build_system/src/build/compile_worker.ts index c10889518bafa33a6805e744be71c1f391fdbaaf..a93ea46d22758f39b71e9b32b72c235bf816ae3a 100644 --- a/ets2panda/driver/build_system/src/build/compile_worker.ts +++ b/ets2panda/driver/build_system/src/build/compile_worker.ts @@ -87,19 +87,15 @@ process.on('message', (message: { PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, arktsGlobal.compilerContext.peer); - if (buildConfig.hasMainModule && (buildConfig.byteCodeHar || buildConfig.moduleType === OHOS_MODULE_TYPE.SHARED)) { - let filePathFromModuleRoot: string = path.relative(buildConfig.moduleRootPath, fileInfo.filePath); - let declEtsOutputPath: string = changeFileExtension( - path.join(buildConfig.declgenV2OutPath as string, filePathFromModuleRoot), + const filePathFromModuleRoot = path.relative(buildConfig.moduleRootPath, fileInfo.filePath); + const declEtsOutputPath = changeFileExtension( + path.join(buildConfig.declgenV2OutPath!, filePathFromModuleRoot), DECL_ETS_SUFFIX ); ensurePathExists(declEtsOutputPath); - - // Generate 1.2 declaration files(a temporary solution while binary import not pushed) arkts.generateStaticDeclarationsFromContext(declEtsOutputPath); } - PluginDriver.getInstance().runPluginHook(PluginHook.CHECKED); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED, arktsGlobal.compilerContext.peer); diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index f9295c138b39925fae9abee5f58d562e4e0266a8..25a77acc6093cda33d53cbfab7ec29e9563dad80 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -1285,7 +1285,48 @@ extern "C" __attribute__((unused)) int GenerateTsDeclarationsFromContext(es2pand : 1; } -// Will be removed after binary import support is fully implemented. +// #28937 Will be removed after binary import support is fully implemented. +__attribute__((unused)) static std::string GetFileNameByPath(const std::string &path) +{ + auto lastSlash = path.find_last_of("/\\"); + std::string filename = (lastSlash == std::string::npos) ? path : path.substr(lastSlash + 1); + + auto lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename = filename.substr(0, lastDot); + } + + lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename = filename.substr(0, lastDot); + } + + return filename; +} + +// #28937 Will be removed after binary import support is fully implemented. +__attribute__((unused)) static bool HandleMultiFileMode(Context *ctxImpl, const std::string &outputPath) +{ + std::string outputStem = GetFileNameByPath(outputPath); + auto &externalSources = ctxImpl->parserProgram->DirectExternalSources(); + + for (const auto &entry : externalSources) { + for (auto *prog : entry.second) { + if (prog == nullptr || !prog->IsGenAbcForExternal()) { + continue; + } + + if (prog->FileName().Mutf8() == outputStem) { + compiler::HandleGenerateDecl(*prog, *ctxImpl->diagnosticEngine, outputPath); + return !ctxImpl->diagnosticEngine->IsAnyError(); + } + } + } + + return false; +} + +// #28937 Will be removed after binary import support is fully implemented. extern "C" __attribute__((unused)) int GenerateStaticDeclarationsFromContext(es2panda_Context *ctx, const char *outputPath) { @@ -1293,8 +1334,15 @@ extern "C" __attribute__((unused)) int GenerateStaticDeclarationsFromContext(es2 if (ctxImpl->state != ES2PANDA_STATE_CHECKED) { return 1; } - compiler::HandleGenerateDecl(*ctxImpl->parserProgram, *ctxImpl->diagnosticEngine, outputPath); + // Multiple file mode + if (ctxImpl->config->options->IsSimultaneous()) { + bool success = HandleMultiFileMode(ctxImpl, outputPath); + return success ? 0 : 1; + } + + // Single file mode + compiler::HandleGenerateDecl(*ctxImpl->parserProgram, *ctxImpl->diagnosticEngine, outputPath); return ctxImpl->diagnosticEngine->IsAnyError() ? 1 : 0; }