Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,17 @@ def generate_clippy(self) -> None:
elem.add_dep(list(self.all_structured_sources))
self.add_build(elem)

def generate_clippy_json(self) -> None:
if 'clippy-json' in self.all_outputs or not self.have_language('rust'):
return

cmd = self.environment.get_build_command() + \
['--internal', 'clippy', self.environment.build_dir, '--error-format=json']
elem = self.create_phony_target('clippy-json', 'CUSTOM_COMMAND', 'PHONY')
elem.add_item('COMMAND', cmd)
elem.add_item('pool', 'console')
self.add_build(elem)

def generate_rustdoc(self) -> None:
if 'rustdoc' in self.all_outputs or not self.have_language('rust'):
return
Expand Down Expand Up @@ -3966,6 +3977,7 @@ def generate_utils(self) -> None:
self.generate_clangformat()
self.generate_clangtidy()
self.generate_clippy()
self.generate_clippy_json()
self.generate_rustdoc()
self.generate_tags('etags', 'TAGS')
self.generate_tags('ctags', 'ctags')
Expand Down
8 changes: 5 additions & 3 deletions mesonbuild/scripts/clippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..compilers.rust import RustCompiler

class ClippyDriver:
def __init__(self, build: build.Build, tempdir: str):
def __init__(self, build: build.Build, tempdir: str, args: list[str]):
self.tools: PerMachine[T.List[str]] = PerMachine([], [])
self.warned: T.DefaultDict[str, bool] = defaultdict(lambda: False)
self.tempdir = tempdir
Expand All @@ -24,6 +24,7 @@ def __init__(self, build: build.Build, tempdir: str):
if 'rust' in compilers:
compiler = T.cast('RustCompiler', compilers['rust'])
self.tools[machine] = compiler.get_rust_tool('clippy-driver')
self.args = args

def warn_missing_clippy(self, machine: str) -> None:
if self.warned[machine]:
Expand Down Expand Up @@ -64,13 +65,14 @@ def __call__(self, target: T.Dict[str, T.Any]) -> T.Iterable[T.Coroutine[None, N
# and --emit dep-info= is not enough for clippy to do
# enough analysis, so use --emit metadata.
cmdlist.append('--emit')
cmdlist.append('metadata')
cmdlist.append('link')
cmdlist.append('--out-dir')
cmdlist.append(self.tempdir)
cmdlist += self.args
yield run_with_buffered_output(cmdlist)

def run(args: T.List[str]) -> int:
os.chdir(args[0])
build_data = build.load(os.getcwd())
with tempfile.TemporaryDirectory() as d:
return run_tool_on_targets(ClippyDriver(build_data, d))
return run_tool_on_targets(ClippyDriver(build_data, d, args[1:]))
Loading