servo/python/servo/devenv_commands.py
Jerens Lensun b9347bf302
Remove cargo-update, update-cargo, grep, ndk-stack, and ndk-gdb mach commands (#37874)
Remove some seldomly used `mach commands:

- `ndk-stack` and `ndk-gdb`: These commands have bit rotted completely,
so need to be reimplemented. Remove them for now to make them less
confusing.
- `cargo-update` / `update-cargo`: This command just calls `cargo`
directly so isn't really necessary.
- `grep`: There are much better grep tools now such as `rg` that make
these kind of special-cases obsolete. In addition, we can improve the
default behavior of `git grep` by using the git attributes feature.

These commands are being removed in order to implement Python type
checking the Servo repository.

Testing: This just removes some mach command so shouldn't need tests.

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
2025-07-04 11:36:33 +00:00

102 lines
3.9 KiB
Python

# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import json
from mach.decorators import (
Command,
CommandArgument,
CommandProvider,
)
from tidy.linting_report import GitHubAnnotationManager
from servo.command_base import CommandBase, call
@CommandProvider
class MachCommands(CommandBase):
@Command("check", description='Run "cargo check"', category="devenv")
@CommandArgument(
"params", default=None, nargs="...", help="Command-line arguments to be passed through to cargo check"
)
@CommandBase.common_command_arguments(build_configuration=True, build_type=False)
def check(self, params, **kwargs):
if not params:
params = []
self.ensure_bootstrapped()
self.ensure_clobbered()
status = self.run_cargo_build_like_command("check", params, **kwargs)
if status == 0:
print("Finished checking, binary NOT updated. Consider ./mach build before ./mach run")
return status
@Command("rustc", description="Run the Rust compiler", category="devenv")
@CommandArgument("params", default=None, nargs="...", help="Command-line arguments to be passed through to rustc")
def rustc(self, params):
if params is None:
params = []
self.ensure_bootstrapped()
return call(["rustc"] + params, env=self.build_env())
@Command("cargo-fix", description='Run "cargo fix"', category="devenv")
@CommandArgument(
"params", default=None, nargs="...", help="Command-line arguments to be passed through to cargo-fix"
)
@CommandBase.common_command_arguments(build_configuration=True, build_type=False)
def cargo_fix(self, params, **kwargs):
if not params:
params = []
self.ensure_bootstrapped()
self.ensure_clobbered()
return self.run_cargo_build_like_command("fix", params, **kwargs)
@Command("clippy", description='Run "cargo clippy"', category="devenv")
@CommandArgument("params", default=None, nargs="...", help="Command-line arguments to be passed through to clippy")
@CommandArgument(
"--github-annotations",
default=False,
action="store_true",
help="Emit the clippy warnings in the Github Actions annotations format",
)
@CommandBase.common_command_arguments(build_configuration=True, build_type=False)
def cargo_clippy(self, params, github_annotations=False, **kwargs):
if not params:
params = []
self.ensure_bootstrapped()
self.ensure_clobbered()
env = self.build_env()
env["RUSTC"] = "rustc"
if github_annotations:
if "--message-format=json" not in params:
params.insert(0, "--message-format=json")
github_annotation_manager = GitHubAnnotationManager("clippy")
results = self.run_cargo_build_like_command("clippy", params, env=env, capture_output=True, **kwargs)
if results.returncode == 0:
return 0
try:
github_annotation_manager.emit_annotations_for_clippy(
[json.loads(line) for line in results.stdout.splitlines() if line.strip()]
)
except json.JSONDecodeError:
pass
return results.returncode
return self.run_cargo_build_like_command("clippy", params, env=env, **kwargs)
@Command("fetch", description="Fetch Rust, Cargo and Cargo dependencies", category="devenv")
def fetch(self):
self.ensure_bootstrapped()
return call(["cargo", "fetch"], env=self.build_env())