diff --git a/arkoala-arkts/BUILD.gn b/arkoala-arkts/BUILD.gn index f25340304aa68428967ff7c80c18f1ba7823fa81..0bd89a33bbc7035da5c8674a66458606d1bcdbf9 100644 --- a/arkoala-arkts/BUILD.gn +++ b/arkoala-arkts/BUILD.gn @@ -15,6 +15,7 @@ import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") import("//foundation/arkui/ace_engine/ace_config.gni") import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") +import("./components.gni") koala_root = ".." koala_path = "" @@ -130,6 +131,7 @@ npm_cmd("arkui_build") { "$koala_root/incremental:incremental_abc", "$koala_root/interop:interop", ] + inputs = arkui_files project_path = rebase_path("./arkui") target_out_path = rebase_path("$target_out_dir/arkui.abc") built_file_path = rebase_path("./arkui/build/arkui.abc") diff --git a/arkoala-arkts/arktsconfig-gn.json b/arkoala-arkts/arktsconfig-gn.json new file mode 100644 index 0000000000000000000000000000000000000000..0657f9b1dd13926775fecd7817fb75965ef69306 --- /dev/null +++ b/arkoala-arkts/arktsconfig-gn.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "package": "arkui", + "baseUrl": "./arkui", + "paths": {} + }, + "include": [ + "./arkui/@ohos.*/*.ets", + "./arkui/generated/**/*.ets", + "./arkui/src/**/*.ets" + ], + "exclude": [] +} diff --git a/arkoala-arkts/components.gni b/arkoala-arkts/components.gni new file mode 100644 index 0000000000000000000000000000000000000000..d08b477e7898f7314f75f5d6b4b89a77fcf3197f --- /dev/null +++ b/arkoala-arkts/components.gni @@ -0,0 +1,362 @@ +# 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. + +# DO NOT MODIFY THIS FILE MANUALLY. +# USE FOLLOWING COMMAND: +# ./tools/gen_gni.py --json arktsconfig-gn.json --output components.gni --gn-tool ../../../../../../../../prebuilts/build-tools/linux-x86/bin/gn + +arkui_files = [ + "arkui/@ohos.arkui.UIContext/index.ets", + "arkui/@ohos.arkui.component/index.ets", + "arkui/@ohos.arkui.dragController/index.ets", + "arkui/@ohos.arkui.inspector/index.ets", + "arkui/@ohos.arkui.node/index.ets", + "arkui/@ohos.arkui.stateManagement/index.ets", + "arkui/@ohos.arkui.theme/index.ets", + "arkui/@ohos.arkui/index.ets", + "arkui/@ohos.router/index.ets", + "arkui/generated/AlphabetIndexerModifier.ets", + "arkui/generated/AnimatorModifier.ets", + "arkui/generated/AttributeUpdater.ets", + "arkui/generated/BadgeModifier.ets", + "arkui/generated/BaseSpanModifier.ets", + "arkui/generated/BlankModifier.ets", + "arkui/generated/ButtonModifier.ets", + "arkui/generated/CalendarPickerModifier.ets", + "arkui/generated/CanvasModifier.ets", + "arkui/generated/CheckboxGroupModifier.ets", + "arkui/generated/CheckboxModifier.ets", + "arkui/generated/CircleModifier.ets", + "arkui/generated/ColumnModifier.ets", + "arkui/generated/ColumnSplitModifier.ets", + "arkui/generated/CommonMethodModifier.ets", + "arkui/generated/CommonModifier.ets", + "arkui/generated/CommonShapeMethodModifier.ets", + "arkui/generated/ComponentContent.ets", + "arkui/generated/ComponentRootModifier.ets", + "arkui/generated/ContainerSpanModifier.ets", + "arkui/generated/Content.ets", + "arkui/generated/CounterModifier.ets", + "arkui/generated/CustomLayoutRootModifier.ets", + "arkui/generated/DataPanelModifier.ets", + "arkui/generated/DatePickerModifier.ets", + "arkui/generated/DividerModifier.ets", + "arkui/generated/EffectComponentModifier.ets", + "arkui/generated/EllipseModifier.ets", + "arkui/generated/EmbeddedComponentModifier.ets", + "arkui/generated/FlexModifier.ets", + "arkui/generated/FlowItemModifier.ets", + "arkui/generated/FolderStackModifier.ets", + "arkui/generated/FormComponentModifier.ets", + "arkui/generated/FormLinkModifier.ets", + "arkui/generated/FrameNode.ets", + "arkui/generated/GaugeModifier.ets", + "arkui/generated/Graphics.ets", + "arkui/generated/GridColModifier.ets", + "arkui/generated/GridItemModifier.ets", + "arkui/generated/GridModifier.ets", + "arkui/generated/GridRowModifier.ets", + "arkui/generated/HyperlinkModifier.ets", + "arkui/generated/ImageAnimatorModifier.ets", + "arkui/generated/ImageModifier.ets", + "arkui/generated/ImageSpanModifier.ets", + "arkui/generated/IndicatorComponentModifier.ets", + "arkui/generated/LineModifier.ets", + "arkui/generated/LinearIndicatorModifier.ets", + "arkui/generated/ListItemGroupModifier.ets", + "arkui/generated/ListItemModifier.ets", + "arkui/generated/ListModifier.ets", + "arkui/generated/LoadingProgressModifier.ets", + "arkui/generated/MarqueeModifier.ets", + "arkui/generated/MediaCachedImageModifier.ets", + "arkui/generated/MenuItemGroupModifier.ets", + "arkui/generated/MenuItemModifier.ets", + "arkui/generated/MenuModifier.ets", + "arkui/generated/NavDestinationModifier.ets", + "arkui/generated/NavigationModifier.ets", + "arkui/generated/NodeContainerModifier.ets", + "arkui/generated/NodeContent.ets", + "arkui/generated/NodeController.ets", + "arkui/generated/PathModifier.ets", + "arkui/generated/PatternLockModifier.ets", + "arkui/generated/PluginComponentModifier.ets", + "arkui/generated/PolygonModifier.ets", + "arkui/generated/PolylineModifier.ets", + "arkui/generated/ProgressModifier.ets", + "arkui/generated/QRCodeModifier.ets", + "arkui/generated/RadioModifier.ets", + "arkui/generated/RatingModifier.ets", + "arkui/generated/RectModifier.ets", + "arkui/generated/RefreshModifier.ets", + "arkui/generated/RelativeContainerModifier.ets", + "arkui/generated/RemoteWindowModifier.ets", + "arkui/generated/RenderNode.ets", + "arkui/generated/RichEditorModifier.ets", + "arkui/generated/RichTextModifier.ets", + "arkui/generated/RootModifier.ets", + "arkui/generated/RootSceneModifier.ets", + "arkui/generated/RowModifier.ets", + "arkui/generated/RowSplitModifier.ets", + "arkui/generated/ScreenModifier.ets", + "arkui/generated/ScrollBarModifier.ets", + "arkui/generated/ScrollModifier.ets", + "arkui/generated/ScrollableCommonMethodModifier.ets", + "arkui/generated/SearchModifier.ets", + "arkui/generated/SelectModifier.ets", + "arkui/generated/ShapeModifier.ets", + "arkui/generated/SideBarContainerModifier.ets", + "arkui/generated/SliderModifier.ets", + "arkui/generated/SpanModifier.ets", + "arkui/generated/StackModifier.ets", + "arkui/generated/StepperItemModifier.ets", + "arkui/generated/StepperModifier.ets", + "arkui/generated/SwiperModifier.ets", + "arkui/generated/SymbolGlyphModifier.ets", + "arkui/generated/SymbolSpanModifier.ets", + "arkui/generated/TabContentModifier.ets", + "arkui/generated/TabsModifier.ets", + "arkui/generated/TextAreaModifier.ets", + "arkui/generated/TextClockModifier.ets", + "arkui/generated/TextInputModifier.ets", + "arkui/generated/TextModifier.ets", + "arkui/generated/TextPickerModifier.ets", + "arkui/generated/TextTimerModifier.ets", + "arkui/generated/TimePickerModifier.ets", + "arkui/generated/ToggleModifier.ets", + "arkui/generated/UIExtensionComponentModifier.ets", + "arkui/generated/VideoModifier.ets", + "arkui/generated/WaterFlowModifier.ets", + "arkui/generated/WebModifier.ets", + "arkui/generated/WindowSceneModifier.ets", + "arkui/generated/WithThemeModifier.ets", + "arkui/generated/XComponentModifier.ets", + "arkui/generated/component/actionSheet.ets", + "arkui/generated/component/alertDialog.ets", + "arkui/generated/component/alphabetIndexer.ets", + "arkui/generated/component/animator.ets", + "arkui/generated/component/badge.ets", + "arkui/generated/component/blank.ets", + "arkui/generated/component/builder.ets", + "arkui/generated/component/button.ets", + "arkui/generated/component/calendarPicker.ets", + "arkui/generated/component/canvas.ets", + "arkui/generated/component/checkbox.ets", + "arkui/generated/component/checkboxgroup.ets", + "arkui/generated/component/circle.ets", + "arkui/generated/component/column.ets", + "arkui/generated/component/columnSplit.ets", + "arkui/generated/component/common.ets", + "arkui/generated/component/containerSpan.ets", + "arkui/generated/component/contentSlot.ets", + "arkui/generated/component/counter.ets", + "arkui/generated/component/customComponent.ets", + "arkui/generated/component/customDialogController.ets", + "arkui/generated/component/dataPanel.ets", + "arkui/generated/component/datePicker.ets", + "arkui/generated/component/divider.ets", + "arkui/generated/component/effectComponent.ets", + "arkui/generated/component/ellipse.ets", + "arkui/generated/component/embeddedComponent.ets", + "arkui/generated/component/enums.ets", + "arkui/generated/component/flex.ets", + "arkui/generated/component/flowItem.ets", + "arkui/generated/component/focus.ets", + "arkui/generated/component/folderStack.ets", + "arkui/generated/component/formComponent.ets", + "arkui/generated/component/formLink.ets", + "arkui/generated/component/gauge.ets", + "arkui/generated/component/gesture.ets", + "arkui/generated/component/gesture.extra.ets", + "arkui/generated/component/grid.ets", + "arkui/generated/component/gridCol.ets", + "arkui/generated/component/gridItem.ets", + "arkui/generated/component/gridRow.ets", + "arkui/generated/component/hyperlink.ets", + "arkui/generated/component/idlize.ets", + "arkui/generated/component/image.ets", + "arkui/generated/component/imageAnimator.ets", + "arkui/generated/component/imageCommon.ets", + "arkui/generated/component/imageSpan.ets", + "arkui/generated/component/indicatorcomponent.ets", + "arkui/generated/component/inspector.ets", + "arkui/generated/component/lazyForEach.ets", + "arkui/generated/component/lazyGridLayout.ets", + "arkui/generated/component/line.ets", + "arkui/generated/component/linearindicator.ets", + "arkui/generated/component/list.ets", + "arkui/generated/component/listItem.ets", + "arkui/generated/component/listItemGroup.ets", + "arkui/generated/component/loadingProgress.ets", + "arkui/generated/component/marquee.ets", + "arkui/generated/component/matrix2d.ets", + "arkui/generated/component/mediaCachedImage.ets", + "arkui/generated/component/menu.ets", + "arkui/generated/component/menuItem.ets", + "arkui/generated/component/menuItemGroup.ets", + "arkui/generated/component/navDestination.ets", + "arkui/generated/component/navigation.ets", + "arkui/generated/component/navigator.ets", + "arkui/generated/component/nodeContainer.ets", + "arkui/generated/component/pageTransition.ets", + "arkui/generated/component/particle.ets", + "arkui/generated/component/pasteButton.ets", + "arkui/generated/component/path.ets", + "arkui/generated/component/patternLock.ets", + "arkui/generated/component/pluginComponent.ets", + "arkui/generated/component/polygon.ets", + "arkui/generated/component/polyline.ets", + "arkui/generated/component/progress.ets", + "arkui/generated/component/qrcode.ets", + "arkui/generated/component/radio.ets", + "arkui/generated/component/rating.ets", + "arkui/generated/component/rect.ets", + "arkui/generated/component/refresh.ets", + "arkui/generated/component/relativeContainer.ets", + "arkui/generated/component/remoteWindow.ets", + "arkui/generated/component/repeat.ets", + "arkui/generated/component/richEditor.ets", + "arkui/generated/component/richText.ets", + "arkui/generated/component/rootScene.ets", + "arkui/generated/component/row.ets", + "arkui/generated/component/rowSplit.ets", + "arkui/generated/component/saveButton.ets", + "arkui/generated/component/screen.ets", + "arkui/generated/component/scroll.ets", + "arkui/generated/component/scrollBar.ets", + "arkui/generated/component/search.ets", + "arkui/generated/component/securityComponent.ets", + "arkui/generated/component/select.ets", + "arkui/generated/component/shape.ets", + "arkui/generated/component/sidebar.ets", + "arkui/generated/component/slider.ets", + "arkui/generated/component/span.ets", + "arkui/generated/component/stack.ets", + "arkui/generated/component/stateManagement.ets", + "arkui/generated/component/stepper.ets", + "arkui/generated/component/stepperItem.ets", + "arkui/generated/component/styledString.ets", + "arkui/generated/component/swiper.ets", + "arkui/generated/component/symbolSpan.ets", + "arkui/generated/component/symbolglyph.ets", + "arkui/generated/component/tabContent.ets", + "arkui/generated/component/tabs.ets", + "arkui/generated/component/text.ets", + "arkui/generated/component/textArea.ets", + "arkui/generated/component/textClock.ets", + "arkui/generated/component/textCommon.ets", + "arkui/generated/component/textInput.ets", + "arkui/generated/component/textPicker.ets", + "arkui/generated/component/textTimer.ets", + "arkui/generated/component/timePicker.ets", + "arkui/generated/component/toggle.ets", + "arkui/generated/component/uiExtensionComponent.ets", + "arkui/generated/component/units.ets", + "arkui/generated/component/video.ets", + "arkui/generated/component/waterFlow.ets", + "arkui/generated/component/web.ets", + "arkui/generated/component/windowScene.ets", + "arkui/generated/component/withTheme.ets", + "arkui/generated/component/xcomponent.ets", + "arkui/generated/framework/EnumsImpl.ets", + "arkui/generated/framework/GlobalScope.ets", + "arkui/generated/framework/application.BaseContext.ets", + "arkui/generated/framework/application.Context.ets", + "arkui/generated/framework/arkts/ArkUIGeneratedNativeModule.ets", + "arkui/generated/framework/arkts/ArkUINativeModule.ets", + "arkui/generated/framework/arkts/TestNativeModule.ets", + "arkui/generated/framework/arkts/index.ets", + "arkui/generated/framework/arkts/type_check.ets", + "arkui/generated/framework/base.ets", + "arkui/generated/framework/index.ets", + "arkui/generated/framework/ohos.app.ability.Want.ets", + "arkui/generated/framework/ohos.app.ability.common.ets", + "arkui/generated/framework/ohos.arkui.UIContext.ets", + "arkui/generated/framework/ohos.arkui.drawableDescriptor.ets", + "arkui/generated/framework/ohos.arkui.node.ets", + "arkui/generated/framework/ohos.arkui.observer.ets", + "arkui/generated/framework/ohos.arkui.shape.ets", + "arkui/generated/framework/ohos.arkui.theme.ets", + "arkui/generated/framework/ohos.base.ets", + "arkui/generated/framework/ohos.curves.ets", + "arkui/generated/framework/ohos.data.unifiedDataChannel.ets", + "arkui/generated/framework/ohos.data.uniformTypeDescriptor.ets", + "arkui/generated/framework/ohos.font.ets", + "arkui/generated/framework/ohos.graphics.common2D.ets", + "arkui/generated/framework/ohos.graphics.drawing.ets", + "arkui/generated/framework/ohos.graphics.text.ets", + "arkui/generated/framework/ohos.graphics.uiEffect.ets", + "arkui/generated/framework/ohos.intl.ets", + "arkui/generated/framework/ohos.matrix4.ets", + "arkui/generated/framework/ohos.measure.ets", + "arkui/generated/framework/ohos.multimedia.image.ets", + "arkui/generated/framework/ohos.multimodalInput.intentionCode.ets", + "arkui/generated/framework/ohos.multimodalInput.pointer.ets", + "arkui/generated/framework/ohos.promptAction.ets", + "arkui/generated/framework/ohos.web.webview.ets", + "arkui/generated/framework/ohos.window.ets", + "arkui/generated/framework/peers/CallbackDeserializeCall.ets", + "arkui/generated/framework/peers/CallbackKind.ets", + "arkui/generated/framework/resource.ets", + "arkui/generated/framework/searchOps.ets", + "arkui/generated/framework/textFieldOps.ets", + "arkui/generated/stateManagement.ets", + "arkui/generated/stateManagement/decorators.decoratorConsume.ets", + "arkui/generated/stateManagement/decorators.decoratorProvide.ets", + "arkui/generated/stateManagement/decorators.decoratorWatch.ets", + "arkui/src/ArkAnimation.ets", + "arkui/src/ArkComponentRoot.ets", + "arkui/src/ArkCustomComponent.ets", + "arkui/src/ArkNavPathStack.ets", + "arkui/src/ArkPageTransition.ets", + "arkui/src/ArkPageTransitionData.ets", + "arkui/src/ArkState.ets", + "arkui/src/ArkStateStyle.ets", + "arkui/src/ArkUIEntry.ets", + "arkui/src/AttributeUpdater.ets", + "arkui/src/CallbackTransformer.ets", + "arkui/src/CallbacksChecker.ets", + "arkui/src/ComponentBase.ets", + "arkui/src/ContentModifierHooks.ets", + "arkui/src/DataChangeListener.ets", + "arkui/src/Events.ets", + "arkui/src/ForEach.ets", + "arkui/src/ForeignFunctions.ets", + "arkui/src/LazyForEach.ets", + "arkui/src/NativeLog.ets", + "arkui/src/NativePeerNode.ets", + "arkui/src/PeerNode.ets", + "arkui/src/ReusablePool.ets", + "arkui/src/Router.ets", + "arkui/src/Storage.ets", + "arkui/src/TestApiHooks.ets", + "arkui/src/TestComponent.ets", + "arkui/src/UserView.ets", + "arkui/src/component/builder.ets", + "arkui/src/component/common.ets", + "arkui/src/component/customComponent.ets", + "arkui/src/component/extendableComponent.ets", + "arkui/src/component/interop.ets", + "arkui/src/componentAnnotations/index.ets", + "arkui/src/extractors.ets", + "arkui/src/index.ets", + "arkui/src/ohos.arkui.UIContext.ets", + "arkui/src/ohos.measure.ets", + "arkui/src/ohos/router.ets", + "arkui/src/peers/ArkNavigationPeer.ets", + "arkui/src/resources.ets", + "arkui/src/stateAnnotations/index.ets", +] + +arkui_path_keys = [] + +arkui_path_values = [] diff --git a/arkoala-arkts/tools/gen_gni.py b/arkoala-arkts/tools/gen_gni.py new file mode 100755 index 0000000000000000000000000000000000000000..ea5c5f0dcfc3d36246575a8d474a437bf9bd8549 --- /dev/null +++ b/arkoala-arkts/tools/gen_gni.py @@ -0,0 +1,219 @@ +#!/usr/bin/env python3 +# 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 json +import os +import glob +import argparse +from datetime import datetime +import sys +import subprocess + +def find_files(include_patterns, exclude_patterns=None, base_url=None): + """ + 根据 include 和 exclude 规则生成文件列表,路径为相对当前路径 + """ + file_list = [] + current_dir = os.getcwd() + + # 处理 include 规则 + for pattern in include_patterns: + matched_files = glob.glob(pattern, recursive=True) + for file in matched_files: + absolute_file_path = os.path.abspath(file) + relative_path = os.path.relpath(absolute_file_path, current_dir) + file_list.append(relative_path) + + # 处理 exclude 规则(如果存在) + if exclude_patterns: + filtered_file_list = [] + for file_path in file_list: + # 将 exclude 规则中的路径转换为绝对路径 + exclude_match = False + for pattern in exclude_patterns: + absolute_exclude_pattern = os.path.abspath(pattern) + relative_exclude_pattern = os.path.relpath(absolute_exclude_pattern, current_dir) + # 检查是否匹配 exclude 规则 + if glob.fnmatch.fnmatch(file_path, relative_exclude_pattern): + exclude_match = True + break + if not exclude_match: + filtered_file_list.append(file_path) + file_list = filtered_file_list + + file_list.sort() + return file_list + +def generate_files_var_name(package_name, part_index=None): + """ + 根据 package 字段生成变量名,如果指定了 part_index,则生成带编号的变量名 + """ + var_name = package_name.replace("@", "").replace("/", "_") + if part_index is not None: + return f"{var_name}_files_{part_index}" + return f"{var_name}_files" + +def generate_paths_arrays(package_name, paths, base_url): + """ + 解析 paths 字段,生成 keys 和 values 两个数组 + """ + var_prefix = package_name.replace("@", "").replace("/", "_") + + # 提取 keys 和 values + keys = list(paths.keys()) + values = list(paths.values()) + + # 将 values 中的路径转换为相对于当前路径的路径 + current_dir = os.getcwd() + base_url_path = os.path.abspath(base_url) + relative_values = [] + for value in values: + value_path = value[0] + absolute_value_path = os.path.abspath(os.path.join(base_url_path, value_path)) + try: + relative_path = os.path.relpath(absolute_value_path, current_dir) + relative_values.append(relative_path) + except ValueError: + continue + + keys_var_name = f"{var_prefix}_path_keys" + values_var_name = f"{var_prefix}_path_values" + + return keys_var_name, values_var_name, keys, relative_values + +def generate_gni_file(include, exclude, output_file, package_name, paths, base_url, part_size=None): + """ + 生成 .gni 文件,包含文件列表和 paths 的 keys 和 values 数组 + """ + # 根据 include 和 exclude 规则生成文件列表 + file_list = find_files(include, exclude, base_url) + + # 解析 paths 字段 + keys_var_name, values_var_name, keys, values = generate_paths_arrays(package_name, paths, base_url) + + # 获取当前年份 + current_year = datetime.now().year + + # 获取当前执行的命令 + current_command = " ".join(sys.argv) + + # 写入 .gni 文件 + with open(output_file, "w") as f: + # 写入版权头 + f.write(f"# Copyright (c) {current_year} Huawei Device Co., Ltd.\n") + f.write("# Licensed under the Apache License, Version 2.0 (the \"License\");\n") + f.write("# you may not use this file except in compliance with the License.\n") + f.write("# You may obtain a copy of the License at\n") + f.write("#\n") + f.write("# http://www.apache.org/licenses/LICENSE-2.0\n") + f.write("#\n") + f.write("# Unless required by applicable law or agreed to in writing, software\n") + f.write("# distributed under the License is distributed on an \"AS IS\" BASIS,\n") + f.write("# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n") + f.write("# See the License for the specific language governing permissions and\n") + f.write("# limitations under the License.\n\n") + + # 写入新增的两句话 + f.write("# DO NOT MODIFY THIS FILE MANUALLY.\n") + f.write(f"# USE FOLLOWING COMMAND:\n# {current_command}\n\n") + + # 处理文件列表的分割 + if part_size and len(file_list) > part_size: + part_count = (len(file_list) + part_size - 1) // part_size # 确保不会多生成一个空列表 + # 写入分块数量变量 + parts_var_name = package_name.replace("@", "").replace("/", "_") + "_parts" + files_array_var_name = package_name.replace("@", "").replace("/", "_") + "_files_array" + + # 写入分块的文件列表 + for i in range(part_count): + start_index = i * part_size + end_index = start_index + part_size + part_file_list = file_list[start_index:end_index] + if part_file_list: # 确保列表不为空 + files_var_name = generate_files_var_name(package_name, i + 1) + f.write(f"{files_var_name} = [\n") + for file in part_file_list: + f.write(f' "{file}",\n') + f.write("]\n\n") + + # 生成 xxx_parts 数组 + f.write(f"{parts_var_name} = [\n") + for i in range(1, part_count + 1): + f.write(f' {i},\n') + f.write("]\n\n") + + # 生成 xxx_files_array 数组 + f.write(f"{files_array_var_name} = [\n") + for i in range(1, part_count + 1): + files_var_name = generate_files_var_name(package_name, i) + f.write(f' {files_var_name},\n') + f.write("]\n\n") + else: + files_var_name = generate_files_var_name(package_name) + f.write(f"{files_var_name} = [\n") + for file in file_list: + f.write(f' "{file}",\n') + f.write("]\n\n") + + # 写入 paths 的 keys 数组 + f.write(f"{keys_var_name} = [\n") + for key in keys: + f.write(f' "{key}",\n') + f.write("]\n\n") + + # 写入 paths 的 values 数组 + f.write(f"{values_var_name} = [\n") + for value in values: + f.write(f' "{value}",\n') + f.write("]\n") + +def format_gni_file(gn_tool, file): + """ + 对生成的 .gni 文件,进行格式化 + """ + cmd = [gn_tool, "format", file] + print("format cmd:") + print(" ".join(cmd)) + try: + ret = subprocess.run(cmd, capture_output=True, text=True, check=True) + return 0 + except subprocess.CalledProcessError as e: + print(f"Error executing command: {e}", file=sys.stderr) + print(f"error message: {e.stderr}") + print(f"output message: {e.output}") + return 1 + +if __name__ == "__main__": + # 解析命令行参数 + parser = argparse.ArgumentParser(description="Generate .gni file from JSON configuration.") + parser.add_argument("--json", required=True, help="Path to the input JSON file.") + parser.add_argument("--output", default="output.gni", help="Path to the output .gni file.") + parser.add_argument("--gn-tool", default="gn", help="Path to the gn tool.") + parser.add_argument("--part-size", type=int, help="Maximum size of each file list part.") + args = parser.parse_args() + + # 读取 JSON 文件 + with open(args.json, "r") as f: + json_data = json.load(f) + + # 提取所需字段 + include = json_data["include"] + exclude = json_data.get("exclude") # 使用 get 方法,避免 KeyError 异常 + package_name = json_data["compilerOptions"]["package"] + paths = json_data["compilerOptions"]["paths"] + base_url = json_data["compilerOptions"]["baseUrl"] + + # 生成 .gni 文件 + generate_gni_file(include, exclude, args.output, package_name, paths, base_url, args.part_size) + format_gni_file(args.gn_tool, args.output) \ No newline at end of file diff --git a/gn/npm_util.gni b/gn/npm_util.gni index 5d078451124457bda8a0f27aa5784c62c73612df..bf1f906cd36a03192b2931e51ecc5d6504678f08 100644 --- a/gn/npm_util.gni +++ b/gn/npm_util.gni @@ -23,6 +23,9 @@ template("npm_cmd") { if (defined(invoker.deps)) { deps = invoker.deps } + if (defined(invoker.inputs)) { + inputs = invoker.inputs + } if (defined(invoker.external_deps)) { external_deps = invoker.external_deps }