From 79f6d3544c4254eff0cd796b76e3ddf7559f47c9 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Fri, 23 May 2025 11:58:46 +0300 Subject: [PATCH] [+] partially added cross-file parser --- .../fxreader/pr34/commands_typed/cli.py | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/python/online/fxreader/pr34/commands_typed/cli.py b/python/online/fxreader/pr34/commands_typed/cli.py index f772b36..135f439 100644 --- a/python/online/fxreader/pr34/commands_typed/cli.py +++ b/python/online/fxreader/pr34/commands_typed/cli.py @@ -1,5 +1,7 @@ import dataclasses import io +import importlib +import configparser import glob import os import pathlib @@ -542,6 +544,63 @@ class CLI(abc.ABC): def third_party_roots(self) -> list[pathlib.Path]: return [] + class meson_toolchains_t: + class res_t: + @dataclasses.dataclass + class toolchain_t: + name: str + path: Optional[pathlib.Path] = None + + def meson_toolchains(self) -> list[meson_toolchains_t.res_t.toolchain_t]: + t1 = pathlib.Path(importlib.import_module('online.fxreader.pr34').__path__[0]) + toolchains = glob.glob(str(t1 / 'meson' / 'toolchains' / '*')) + + res : list[CLI.meson_toolchains_t.res_t.toolchain_t] = [] + + for o in toolchains: + entry = self.meson_toolchains_t.res_t.toolchain_t( + name=pathlib.Path(o).name, + path=pathlib.Path(o), + ) + + config = configparser.ConfigParser() + config.read(str(entry.path)) + + return res + + + def _cross_file( + self, + extra_args: list[str], + pyproject_tool: PyProject.Tool, + ) -> list[str]: + if pyproject_tool.meson and pyproject_tool.meson.args and pyproject_tool.meson.args.setup: + extra_args = pyproject_tool.meson.args.setup + extra_args + + parser = argparse.ArgumentParser() + parser.add_argument( + '--cross-file', + dest='cross_file', + default=None, + # type=pathlib.Path, + type=pathlib.Path, + ) + + options, args = pr34_argparse.parse_args(extra_args) + + if not options.cross_file is None: + if not options.cross_file.exists() and ( + not options.cross_file.is_absolute() and \ + options.cross_file.stem in self.meson_toolchains + ): + options.cross_file = self.meson_toolchains[ + options.cross_file.stem + ].path + + extra_args = ['--cross-file', str(options.cross_file)] + args + + return extra_args + def meson_setup( self, project_name: str, @@ -576,8 +635,10 @@ class CLI(abc.ABC): if len(self.third_party_roots) > 0: extra_args.extend(['-Dthird_party_roots=%s' % str(o.absolute()) for o in self.third_party_roots]) - if pyproject_tool.meson and pyproject_tool.meson.args and pyproject_tool.meson.args.setup: - extra_args = pyproject_tool.meson.args.setup + extra_args + self._cross_file( + extra_args=extra_args, + pyproject_tool=pyproject_tool, + ) cmd = [ # shutil_which(