diff --git a/BUILD.gn b/BUILD.gn index 1245c4acb615e003186aca4d3a62ff0ec271cec8..c06527ca05a889c743e7ad423d258b752d856de8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -428,6 +428,7 @@ group("build_ohos_ets") { # 将ets1.1文件处理成ets1.1interop action("build_sdk_interop1") { deps = [ + ":build_sdk_interop1_arkui", ":ohos_base_split", ":ohos_ets_dynamic" ] @@ -628,8 +629,30 @@ action("ohos_ets_process_interop") { "--source-root-dir", rebase_path("//", root_build_dir), "--node-js", - rebase_path(nodejs, root_build_dir) + rebase_path(nodejs, root_build_dir), + "--is-pre", + "false" ] outputs = ["${interface_sdk_path}/arkui_dummy_interop"] -} \ No newline at end of file +} + +action("build_sdk_interop1_arkui") { + deps = [ + ":ohos_base_split", + ":ohos_ets_dynamic" ] + + script = "process_label_noninterop.py" + args = [ + "--intermediates-output", + rebase_path("${interface_sdk_path}", root_build_dir), + "--source-root-dir", + rebase_path("//", root_build_dir), + "--node-js", + rebase_path(nodejs, root_build_dir), + "--is-pre", + "true" + ] + + outputs = ["${interface_sdk_path}/arkui_dummy_interop_pre"] +} diff --git a/build-tools/process_global_import.js b/build-tools/process_global_import.js index b1c488a95d9511615e0d2aad8bbfc97a5d28c492..37a7544b6c93ebb1326f0354d1aca2fbda0dfbc7 100644 --- a/build-tools/process_global_import.js +++ b/build-tools/process_global_import.js @@ -217,7 +217,6 @@ class HandleUIImports { addUIImports(node) { const newStatements = [...node.statements]; - this.addForSpecialFiles(node, newStatements); const compImportSpecifiers = []; const stateImportSpecifiers = []; @@ -241,33 +240,6 @@ class HandleUIImports { this.processSourceFileForUIImport(node, newStatements); } - addForSpecialFiles(node, newStatements) { - const fileName = this.getCoreFilename(path.basename(node.fileName)); - if (fileName === FRAMENODE) { - newStatements.push(this.createFrameNodeTypeNode()); - } - } - - createFrameNodeTypeNode() { - return ts.factory.createModuleDeclaration( - [ - ts.factory.createToken(ts.SyntaxKind.ExportKeyword), - ts.factory.createToken(ts.SyntaxKind.DeclareKeyword) - ], - ts.factory.createIdentifier(TYPENODE), - ts.factory.createModuleBlock([ts.factory.createTypeAliasDeclaration( - undefined, - ts.factory.createIdentifier(XCOMPONENT), - undefined, - ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier(ANY), - undefined - ) - )]), - ts.NodeFlags.Namespace | ts.NodeFlags.ExportContext | ts.NodeFlags.Ambient | ts.NodeFlags.ContextFlags - ); - } - processTypeWithoutDefaultOnly(typeName, modulePath) { this.setImportType(modulePath, ImportType.NAMED); return ts.factory.createExportDeclaration( @@ -430,6 +402,9 @@ class HandleUIImports { if (fileName.endsWith(EXTNAME_D_ETS)) { return fileName.slice(0, -EXTNAME_D_ETS.length); } + if (fileName.endsWith(EXTNAME_D_TS)) { + return fileName.slice(0, -EXTNAME_D_TS.length); + } return fileName; } @@ -646,7 +621,7 @@ function getDeclgenFiles(dir, filePaths = []) { if (stat.isDirectory()) { getDeclgenFiles(filePath, filePaths); - } else if (stat.isFile() && file.endsWith(EXTNAME_D_ETS)) { + } else if (stat.isFile() && (file.endsWith(EXTNAME_D_ETS) || file.endsWith(EXTNAME_D_TS))) { filePaths.push(filePath); } }); @@ -1070,6 +1045,7 @@ const whiteFileList = [ ]; const EXTNAME_D_ETS = '.d.ets'; +const EXTNAME_D_TS = '.d.ts'; const OHOS_ARKUI = '@ohos.arkui.'; const OHOS_KIT_ARKUI = '@kit ArkUI'; const OHOS_ARKUI_STATEMANAGEMENT = './@ohos.arkui.GlobalESValue'; @@ -1081,10 +1057,6 @@ const ARKUI_BUILDER = 'Builder'; const DEFAULT = 'default'; const GENERIC_T = 'T'; const COMPONENT = 'component'; -const FRAMENODE = 'FrameNode'; -const TYPENODE = 'typeNode'; -const XCOMPONENT = 'XComponent'; -const ANY = 'Any'; function start() { const program = new commander.Command(); diff --git a/build-tools/process_label_noninterop.js b/build-tools/process_label_noninterop.js index a10a82b2e5aee840c1682a8eeb2596f71125f266..f01f3eea4795248915924f13a98098c4916966c2 100644 --- a/build-tools/process_label_noninterop.js +++ b/build-tools/process_label_noninterop.js @@ -23,6 +23,11 @@ let componentEtsDeleteFiles = []; const kitFileNeedDeleteMap = new Map(); const stmtReplacementMap = new Map(); +const EXTNAME_TS = '.ts'; +const FRAMENODE = 'FrameNode'; +const TYPENODE = 'typeNode'; +const XCOMPONENT = 'XComponent'; +const ANY = 'Any'; function start() { const program = new commander.Command(); @@ -43,7 +48,7 @@ function start() { } function initGlobalESValueFile() { - fs.writeFileSync(`${path.resolve(outputPath, '../api')}/@ohos.arkui.GlobalESValue.d.ets`, "'use static';", undefined, (err) => { + fs.writeFileSync(`${path.resolve(outputPath, '../api')}/@ohos.arkui.GlobalESValue.d.ts`, '', undefined, (err) => { if (err) { console.error(`ERROR FOR CREATE FILE ${err}`); } @@ -53,7 +58,7 @@ function initGlobalESValueFile() { function writeGlobalESValueFile(content) { content = content.replace("'use static';", '') .replace(/\.\.\/api/g, '.'); - fs.appendFileSync(`${path.resolve(outputPath, '../api')}/@ohos.arkui.GlobalESValue.d.ets`, content, undefined, (err) => { + fs.appendFileSync(`${path.resolve(outputPath, '../api')}/@ohos.arkui.GlobalESValue.d.ts`, content, undefined, (err) => { if (err) { console.error(`ERROR FOR CREATE FILE ${err}`); } @@ -242,9 +247,6 @@ function postProcessContent(content) { } function outputFile(url, node, sourceFile, referencesMessage, copyrightMessage, isCopyrightDeleted) { - if (isEmptyFile(node)) { - return; - } const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); let result = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); if (isCopyrightDeleted) { @@ -312,6 +314,40 @@ function formatImportDeclaration(url, copyrightMessage = '', isCopyrightDeleted }; } +function getCoreFilename(fileName) { + if (fileName.endsWith(EXTNAME_TS)) { + return fileName.slice(0, -EXTNAME_TS.length); + } + return fileName; +} + +function createFrameNodeTypeNode() { + return ts.factory.createModuleDeclaration( + [ + ts.factory.createToken(ts.SyntaxKind.ExportKeyword), + ts.factory.createToken(ts.SyntaxKind.DeclareKeyword) + ], + ts.factory.createIdentifier(TYPENODE), + ts.factory.createModuleBlock([ts.factory.createTypeAliasDeclaration( + undefined, + ts.factory.createIdentifier(XCOMPONENT), + undefined, + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(ANY), + undefined + ) + )]), + ts.NodeFlags.Namespace | ts.NodeFlags.ExportContext | ts.NodeFlags.Ambient | ts.NodeFlags.ContextFlags + ); +} + +function addForSpecialFiles(node, newStatements) { + const fileName = getCoreFilename(path.basename(node.fileName)); + if (fileName === FRAMENODE) { + newStatements.push(createFrameNodeTypeNode()); + } +} + function formatAllNodes(url, node, allIdentifierSet, copyrightMessage = '', isCopyrightDeleted = false) { let referencesMessage = ''; let currReferencesModule = []; @@ -348,6 +384,9 @@ function formatAllNodes(url, node, allIdentifierSet, copyrightMessage = '', isCo newStatements.push(statement); } }); + + addForSpecialFiles(node, newStatements); + currReferencesModule.forEach((item) => { if (item.isUsed) { referencesMessage += item.reference + '\n'; @@ -542,7 +581,7 @@ function deleteNonInteropApi(url) { sourceFile = node; const deleteNode = processSourceFile(node, kitName, url); // 处理最外层节点 node = processVisitEachChild(context, deleteNode.node); - if (!isEmptyFile(node) && needProcessLabelNonInterop(fileName, kitName)) { + if (needProcessLabelNonInterop(fileName, kitName)) { const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const result = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); ts.transpileModule(result, { @@ -918,25 +957,6 @@ function isNonInterop(node) { return false; } -function isEmptyFile(node) { - let isEmpty = true; - if (ts.isSourceFile(node) && node.statements) { - for (let i = 0; i < node.statements.length; i++) { - const statement = node.statements[i]; - if (ts.isImportDeclaration(statement)) { - continue; - } - isEmpty = false; - break; - } - } - const fileName = getPureName(node.fileName.replace('.ts', '').replace('.ets', '')); - if (isEmpty && componentEtsFiles.includes(fileName)) { - componentEtsDeleteFiles.push(fileName); - } - return isEmpty; -} - let outputPath = ''; let inputDir = ''; let exportFlag = false; diff --git a/process_label_noninterop.py b/process_label_noninterop.py index ac8cd8ee622a5741f73520675528243bc8b841ab..832694a5379888cfde0397597229797ecb2b9efa 100755 --- a/process_label_noninterop.py +++ b/process_label_noninterop.py @@ -21,7 +21,6 @@ import subprocess INTERFACE_PATH = "interface/sdk-js" PROCESS_INTEROP = "interface/sdk-js/build-tools/process_label_noninterop.js" - PROCESS_GLOBAL_IMPORT = "interface/sdk-js/build-tools/process_global_import.js" @@ -30,7 +29,10 @@ def process_interop(options, sub_input, sub_output, export_flag): tool = os.path.abspath(os.path.join(options.source_root_dir, PROCESS_INTEROP)) cwd_dir = os.path.abspath(os.path.join( options.source_root_dir, INTERFACE_PATH)) + intermediates_output = os.path.abspath(options.intermediates_output) + if options.is_pre == "true": + intermediates_output = os.path.dirname(os.path.abspath(options.intermediates_output)) input_dir = intermediates_output + sub_input output_dir = intermediates_output + sub_output @@ -59,10 +61,10 @@ def process_global_import(options, sub_input, sub_output, export_flag): tool = os.path.abspath(os.path.join(options.source_root_dir, PROCESS_GLOBAL_IMPORT)) cwd_dir = os.path.abspath(os.path.join( options.source_root_dir, INTERFACE_PATH)) - intermediates_output = os.path.abspath(options.intermediates_output) - delete_path = os.path.join(intermediates_output, "ets1.1interop", "component") - delete_directory(delete_path) + intermediates_output = os.path.abspath(options.intermediates_output) + if options.is_pre == "true": + intermediates_output = os.path.dirname(os.path.abspath(options.intermediates_output)) input_dir = intermediates_output + sub_input output_dir = intermediates_output + sub_output @@ -80,13 +82,18 @@ def main(): parser.add_argument('--intermediates-output', required=True) parser.add_argument('--source-root-dir', required=True) parser.add_argument('--node-js', required=True) + parser.add_argument('--is-pre', required=True) options = parser.parse_args() - process_interop(options, "/ets1.1interop/api", "/ets1.1interop/api", "false") - process_interop(options, "/ets1.1interop/component", "/ets1.1interop/component", "true") - process_interop(options, "/ets1.2interop/declaration/api", "/ets1.2interop/declaration/api", "false") - process_global_import(options, "/ets1.1interop/api", "/ets1.1interop/api", "false") + if options.is_pre == "true": + process_interop(options, "/ohos_dynamic/api", "/ohos_dynamic/api", "false") + process_interop(options, "/ohos_dynamic/component", "/ohos_dynamic/component", "true") + process_global_import(options, "/ohos_dynamic/api", "/ohos_dynamic/api", "false") + else: + process_interop(options, "/ets1.2interop/declaration/api", "/ets1.2interop/declaration/api", "false") + delete_path = os.path.join(os.path.abspath(options.intermediates_output), "ets1.1interop", "component") + delete_directory(delete_path) if __name__ == '__main__':