From 6311bcaf24e1d77ef63f01622f15b8b12ea5bbb1 Mon Sep 17 00:00:00 2001 From: LaterComer <12015333+Later-Comer@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:48:32 +0800 Subject: 将scons --menuconfig/--pyconfig/--pyconfig-silent统一调用kconfiglib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/bsp_buildings.yml | 2 +- .github/workflows/compile_bsp_with_drivers.yml | 2 +- .github/workflows/manual_dist.yml | 2 +- .../workflows/manual_trigger_scons_STM32_all.yml | 2 +- .../manual_trigger_scons_except_STM32_all.yml | 2 +- .../manual_trigger_scons_fail_bsp_all.yml | 2 +- tools/building.py | 30 +- tools/defconfig.py | 43 - tools/genconf.py | 32 - tools/kconfiglib.py | 7024 ------------------- tools/kconfiglib/.gitignore | 4 + tools/kconfiglib/LICENSE.txt | 5 + tools/kconfiglib/MANIFEST.in | 2 + tools/kconfiglib/README.rst | 841 +++ tools/kconfiglib/alldefconfig.py | 27 + tools/kconfiglib/allmodconfig.py | 46 + tools/kconfiglib/allnoconfig.py | 45 + tools/kconfiglib/allyesconfig.py | 56 + tools/kconfiglib/defconfig.py | 43 + tools/kconfiglib/genconfig.py | 154 + tools/kconfiglib/guiconfig.py | 2324 +++++++ tools/kconfiglib/kconfiglib.py | 7160 ++++++++++++++++++++ tools/kconfiglib/listnewconfig.py | 76 + tools/kconfiglib/makefile.patch | 48 + tools/kconfiglib/menuconfig.py | 3278 +++++++++ tools/kconfiglib/oldconfig.py | 246 + tools/kconfiglib/olddefconfig.py | 28 + tools/kconfiglib/savedefconfig.py | 49 + tools/kconfiglib/setconfig.py | 92 + tools/kconfiglib/setup.cfg | 7 + tools/kconfiglib/setup.py | 96 + tools/kconfiglib/testsuite.py | 3203 +++++++++ tools/menuconfig.py | 333 - tools/menukconfig.py | 365 + tools/options.py | 15 +- tools/pyguiconfig.py | 2314 ------- 36 files changed, 18228 insertions(+), 9770 deletions(-) delete mode 100644 tools/defconfig.py delete mode 100644 tools/genconf.py delete mode 100644 tools/kconfiglib.py create mode 100644 tools/kconfiglib/.gitignore create mode 100644 tools/kconfiglib/LICENSE.txt create mode 100644 tools/kconfiglib/MANIFEST.in create mode 100644 tools/kconfiglib/README.rst create mode 100644 tools/kconfiglib/alldefconfig.py create mode 100644 tools/kconfiglib/allmodconfig.py create mode 100644 tools/kconfiglib/allnoconfig.py create mode 100644 tools/kconfiglib/allyesconfig.py create mode 100644 tools/kconfiglib/defconfig.py create mode 100644 tools/kconfiglib/genconfig.py create mode 100644 tools/kconfiglib/guiconfig.py create mode 100644 tools/kconfiglib/kconfiglib.py create mode 100644 tools/kconfiglib/listnewconfig.py create mode 100644 tools/kconfiglib/makefile.patch create mode 100644 tools/kconfiglib/menuconfig.py create mode 100644 tools/kconfiglib/oldconfig.py create mode 100644 tools/kconfiglib/olddefconfig.py create mode 100644 tools/kconfiglib/savedefconfig.py create mode 100644 tools/kconfiglib/setconfig.py create mode 100644 tools/kconfiglib/setup.cfg create mode 100644 tools/kconfiglib/setup.py create mode 100644 tools/kconfiglib/testsuite.py delete mode 100644 tools/menuconfig.py create mode 100644 tools/menukconfig.py delete mode 100644 tools/pyguiconfig.py diff --git a/.github/workflows/bsp_buildings.yml b/.github/workflows/bsp_buildings.yml index 291cdc2638..4de198074a 100644 --- a/.github/workflows/bsp_buildings.yml +++ b/.github/workflows/bsp_buildings.yml @@ -354,7 +354,7 @@ jobs: chmod 777 install_ubuntu.sh ./install_ubuntu.sh git config --global http.postBuffer 524288000 - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV echo "RTT_CC=gcc" >> $GITHUB_ENV diff --git a/.github/workflows/compile_bsp_with_drivers.yml b/.github/workflows/compile_bsp_with_drivers.yml index 634eab49bb..53d6e4269f 100644 --- a/.github/workflows/compile_bsp_with_drivers.yml +++ b/.github/workflows/compile_bsp_with_drivers.yml @@ -52,7 +52,7 @@ jobs: git config --global http.postBuffer 524288000 git remote -v git fetch origin - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" - name: Install Arm ToolChains if: ${{ success() }} diff --git a/.github/workflows/manual_dist.yml b/.github/workflows/manual_dist.yml index b3ec3e80bb..93efd90ecf 100644 --- a/.github/workflows/manual_dist.yml +++ b/.github/workflows/manual_dist.yml @@ -66,7 +66,7 @@ jobs: chmod 777 install_ubuntu.sh ./install_ubuntu.sh git config --global http.postBuffer 524288000 - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV echo "RTT_CC=gcc" >> $GITHUB_ENV diff --git a/.github/workflows/manual_trigger_scons_STM32_all.yml b/.github/workflows/manual_trigger_scons_STM32_all.yml index ee99da365d..57795f74b9 100644 --- a/.github/workflows/manual_trigger_scons_STM32_all.yml +++ b/.github/workflows/manual_trigger_scons_STM32_all.yml @@ -141,7 +141,7 @@ jobs: chmod 777 install_ubuntu.sh ./install_ubuntu.sh git config --global http.postBuffer 524288000 - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV echo "RTT_CC=gcc" >> $GITHUB_ENV diff --git a/.github/workflows/manual_trigger_scons_except_STM32_all.yml b/.github/workflows/manual_trigger_scons_except_STM32_all.yml index f3b4186b64..a2fbe2f2d3 100644 --- a/.github/workflows/manual_trigger_scons_except_STM32_all.yml +++ b/.github/workflows/manual_trigger_scons_except_STM32_all.yml @@ -286,7 +286,7 @@ jobs: chmod 777 install_ubuntu.sh ./install_ubuntu.sh git config --global http.postBuffer 524288000 - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV echo "RTT_CC=gcc" >> $GITHUB_ENV diff --git a/.github/workflows/manual_trigger_scons_fail_bsp_all.yml b/.github/workflows/manual_trigger_scons_fail_bsp_all.yml index 8ad5188b23..c7b01eba5a 100644 --- a/.github/workflows/manual_trigger_scons_fail_bsp_all.yml +++ b/.github/workflows/manual_trigger_scons_fail_bsp_all.yml @@ -116,7 +116,7 @@ jobs: chmod 777 install_ubuntu.sh ./install_ubuntu.sh git config --global http.postBuffer 524288000 - python -c "import tools.menuconfig; tools.menuconfig.touch_env()" + python -c "import tools.menukconfig; tools.menukconfig.touch_env()" echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV echo "RTT_CC=gcc" >> $GITHUB_ENV diff --git a/tools/building.py b/tools/building.py index d6c56ad3ba..797ffc0076 100644 --- a/tools/building.py +++ b/tools/building.py @@ -139,10 +139,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ # set RTT_ROOT in ENV Env['RTT_ROOT'] = Rtt_Root + os.environ["RTT_DIR"] = Rtt_Root # set BSP_ROOT in ENV Env['BSP_ROOT'] = Dir('#').abspath + os.environ["BSP_DIR"] = Dir('#').abspath + # set PKGS_ROOT in ENV + if not "PKGS_DIR" in os.environ: + if "ENV_ROOT" in os.environ: + os.environ["PKGS_DIR"] = os.path.join(os.environ["ENV_ROOT"], "packages") + elif sys.platform == "win32": + os.environ["PKGS_DIR"] = os.path.join(os.environ["USERPROFILE"], ".env/packages") + else: + os.environ["PKGS_DIR"] = os.path.join(os.environ["HOME"], ".env/packages") - sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')] + sys.path = sys.path + [os.path.join(Rtt_Root, 'tools'), os.path.join(Rtt_Root, 'tools/kconfiglib')] # {target_name:(CROSS_TOOL, PLATFORM)} tgt_dict = {'mdk':('keil', 'armcc'), @@ -303,7 +313,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ print('--global-macros arguments are illegal!') if GetOption('genconfig'): - from genconf import genconfig + from menukconfig import genconfig genconfig() exit(0) @@ -311,25 +321,25 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ from WCS import ThreadStackStaticAnalysis ThreadStackStaticAnalysis(Env) exit(0) - if platform.system() != 'Windows': - if GetOption('menuconfig'): - from menuconfig import menuconfig - menuconfig(Rtt_Root) - exit(0) + + if GetOption('menuconfig'): + from menukconfig import menuconfig + menuconfig(Rtt_Root) + exit(0) if GetOption('pyconfig-silent'): - from menuconfig import guiconfig_silent + from menukconfig import guiconfig_silent guiconfig_silent(Rtt_Root) exit(0) elif GetOption('pyconfig'): - from menuconfig import guiconfig + from menukconfig import guiconfig guiconfig(Rtt_Root) exit(0) configfn = GetOption('useconfig') if configfn: - from menuconfig import mk_rtconfig + from menukconfig import mk_rtconfig mk_rtconfig(configfn) exit(0) diff --git a/tools/defconfig.py b/tools/defconfig.py deleted file mode 100644 index d1b1e4ea73..0000000000 --- a/tools/defconfig.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Reads a specified configuration file, then writes a new configuration file. -This can be used to initialize the configuration from e.g. an arch-specific -configuration file. This input configuration file would usually be a minimal -configuration file, as generated by e.g. savedefconfig. - -The default output filename is '.config'. A different filename can be passed in -the KCONFIG_CONFIG environment variable. -""" -import argparse - -import kconfiglib - - -def main(): - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description=__doc__) - - parser.add_argument( - "--kconfig", - default="Kconfig", - help="Base Kconfig file (default: Kconfig)") - - parser.add_argument( - "config", - metavar="CONFIGURATION", - help="Input configuration file") - - args = parser.parse_args() - - kconf = kconfiglib.Kconfig(args.kconfig) - print(kconf.load_config(args.config)) - print(kconf.write_config()) - - -if __name__ == "__main__": - main() diff --git a/tools/genconf.py b/tools/genconf.py deleted file mode 100644 index d033c4007d..0000000000 --- a/tools/genconf.py +++ /dev/null @@ -1,32 +0,0 @@ -import os - -def genconfig() : - from SCons.Script import SCons - - PreProcessor = SCons.cpp.PreProcessor() - - try: - f = open('rtconfig.h', 'r') - contents = f.read() - f.close() - except : - print("Open rtconfig.h file failed.") - - PreProcessor.process_contents(contents) - options = PreProcessor.cpp_namespace - - try: - f = open('.config', 'w') - for (opt, value) in options.items(): - if type(value) == type(1): - f.write("CONFIG_%s=%d\n" % (opt, value)) - - if type(value) == type('') and value == '': - f.write("CONFIG_%s=y\n" % opt) - elif type(value) == type('str'): - f.write("CONFIG_%s=%s\n" % (opt, value)) - - print("Generate .config done!") - f.close() - except: - print("Generate .config file failed.") diff --git a/tools/kconfiglib.py b/tools/kconfiglib.py deleted file mode 100644 index 9a9b2f03f7..0000000000 --- a/tools/kconfiglib.py +++ /dev/null @@ -1,7024 +0,0 @@ -# Copyright (c) 2011-2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Overview -======== - -Kconfiglib is a Python 2/3 library for scripting and extracting information -from Kconfig (https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt) -configuration systems. - -See the homepage at https://github.com/ulfalizer/Kconfiglib for a longer -overview. - -Since Kconfiglib 12.0.0, the library version is available in -kconfiglib.VERSION, which is a (, , ) tuple, e.g. -(12, 0, 0). - - -Using Kconfiglib on the Linux kernel with the Makefile targets -============================================================== - -For the Linux kernel, a handy interface is provided by the -scripts/kconfig/Makefile patch, which can be applied with either 'git am' or -the 'patch' utility: - - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | git am - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | patch -p1 - -Warning: Not passing -p1 to patch will cause the wrong file to be patched. - -Please tell me if the patch does not apply. It should be trivial to apply -manually, as it's just a block of text that needs to be inserted near the other -*conf: targets in scripts/kconfig/Makefile. - -Look further down for a motivation for the Makefile patch and for instructions -on how you can use Kconfiglib without it. - -If you do not wish to install Kconfiglib via pip, the Makefile patch is set up -so that you can also just clone Kconfiglib into the kernel root: - - $ git clone git://github.com/ulfalizer/Kconfiglib.git - $ git am Kconfiglib/makefile.patch (or 'patch -p1 < Kconfiglib/makefile.patch') - -Warning: The directory name Kconfiglib/ is significant in this case, because -it's added to PYTHONPATH by the new targets in makefile.patch. - -The targets added by the Makefile patch are described in the following -sections. - - -make kmenuconfig ----------------- - -This target runs the curses menuconfig interface with Python 3. As of -Kconfiglib 12.2.0, both Python 2 and Python 3 are supported (previously, only -Python 3 was supported, so this was a backport). - - -make guiconfig --------------- - -This target runs the Tkinter menuconfig interface. Both Python 2 and Python 3 -are supported. To change the Python interpreter used, pass -PYTHONCMD= to 'make'. The default is 'python'. - - -make [ARCH=] iscriptconfig --------------------------------- - -This target gives an interactive Python prompt where a Kconfig instance has -been preloaded and is available in 'kconf'. To change the Python interpreter -used, pass PYTHONCMD= to 'make'. The default is 'python'. - -To get a feel for the API, try evaluating and printing the symbols in -kconf.defined_syms, and explore the MenuNode menu tree starting at -kconf.top_node by following 'next' and 'list' pointers. - -The item contained in a menu node is found in MenuNode.item (note that this can -be one of the constants kconfiglib.MENU and kconfiglib.COMMENT), and all -symbols and choices have a 'nodes' attribute containing their menu nodes -(usually only one). Printing a menu node will print its item, in Kconfig -format. - -If you want to look up a symbol by name, use the kconf.syms dictionary. - - -make scriptconfig SCRIPT=