@samitouri / QOSamiQemu / commits / 0836a79ada

scripts: remove now dead parts of rustc_args.py

The logic to parse the [lints] section has been integrated into Meson and can be removed. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo Bonzini committed May 25, 2026 at 17:53 UTC 0836a79adafe9c5089839621ac761f84b92e95cf
2 files changed +1 -80
meson.build
-1
@@ -130,7 +130,6 @@ endif
130
131 if have_rust
132 rustc_args = [find_program('scripts/rust/rustc_args.py'),
133 - '--rustc-version', rustc.version(),
133 '--workspace', meson.project_source_root()]
134
135 rustfmt = find_program('rustfmt', required: false)
scripts/rust/rustc_args.py
+1 -79
@@ -25,10 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
25 """
26
27 import argparse
28 -from dataclasses import dataclass
28 import logging
29 from pathlib import Path
31 -from typing import Any, Iterable, List, Mapping, Optional, Set
30 +from typing import Any, Iterable, Mapping, Optional, Set
31
32 try:
33 import tomllib
@@ -74,40 +73,6 @@ class CargoTOML:
73 return table
74
75
77 -@dataclass
78 -class LintFlag:
79 - flags: List[str]
80 - priority: int
81 -
82 -
83 -def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]:
84 - """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags."""
85 -
86 - toml_lints = cargo_toml.lints
87 -
88 - lint_list = []
89 - for k, v in toml_lints.items():
90 - prefix = "" if k == "rust" else k + "::"
91 - for lint, data in v.items():
92 - level = data if isinstance(data, str) else data["level"]
93 - priority = 0 if isinstance(data, str) else data.get("priority", 0)
94 - if level == "deny":
95 - flag = "-D"
96 - elif level == "allow":
97 - flag = "-A"
98 - elif level == "warn":
99 - flag = "-W"
100 - elif level == "forbid":
101 - flag = "-F"
102 - else:
103 - raise Exception(f"invalid level {level} for {prefix}{lint}")
104 - lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority))
105 -
106 - lint_list.sort(key=lambda x: x.priority)
107 - for lint in lint_list:
108 - yield from lint.flags
109 -
110 -
76 def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]:
77 """Converts defines from config[..].h headers to rustc --cfg flags."""
78
@@ -154,60 +119,17 @@ def main() -> None:
119 required=False,
120 default=None,
121 )
157 - parser.add_argument(
158 - "--features",
159 - action="store_true",
160 - dest="features",
161 - help="generate --check-cfg arguments for features",
162 - required=False,
163 - default=None,
164 - )
165 - parser.add_argument(
166 - "--lints",
167 - action="store_true",
168 - dest="lints",
169 - help="generate arguments from [lints] table",
170 - required=False,
171 - default=None,
172 - )
173 - parser.add_argument(
174 - "--rustc-version",
175 - metavar="VERSION",
176 - dest="rustc_version",
177 - action="store",
178 - help="version of rustc",
179 - required=False,
180 - default="1.0.0",
181 - )
122 args = parser.parse_args()
123 if args.verbose:
124 logging.basicConfig(level=logging.DEBUG)
125 logging.debug("args: %s", args)
126
187 - rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2]))
127 if args.workspace:
128 workspace_cargo_toml = Path(args.workspace, "Cargo.toml").resolve()
129 cargo_toml = CargoTOML(args.cargo_toml, str(workspace_cargo_toml))
130 else:
131 cargo_toml = CargoTOML(args.cargo_toml, None)
132
194 - if args.lints:
195 - for tok in generate_lint_flags(cargo_toml):
196 - print(tok)
197 -
198 - if rustc_version >= (1, 80):
199 - if args.lints:
200 - print("--check-cfg")
201 - print("cfg(test)")
202 - for cfg in sorted(cargo_toml.check_cfg):
203 - print("--check-cfg")
204 - print(cfg)
205 - if args.features:
206 - for feature in cargo_toml.get_table("features"):
207 - if feature != "default":
208 - print("--check-cfg")
209 - print(f'cfg(feature,values("{feature}"))')
210 -
133 for header in args.config_headers:
134 for tok in generate_cfg_flags(header, cargo_toml):
135 print(tok)