mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
Refactoring script to use super:: instead of crate:: in win_sys_util
Had to add some exceptions here because of some mismatches between the structrure of files vs modules. BUG=b:22320646 TEST=python tools/contrib/refactor_use_references Change-Id: Ia9da533bd8c89871893adfa461e47e4e2fe600d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530119 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
ce0d8c51e9
commit
99e336b688
1 changed files with 29 additions and 11 deletions
|
@ -116,6 +116,25 @@ def use_super_instead_of_crate(root: Path):
|
||||||
that directory to be the module crate:: refers to."""
|
that directory to be the module crate:: refers to."""
|
||||||
|
|
||||||
def replace(module: list[str], use: str):
|
def replace(module: list[str], use: str):
|
||||||
|
# Patch up weird module structure...
|
||||||
|
if len(module) > 1 and module[0] == "win":
|
||||||
|
# Only the listed modules are actually in win::.
|
||||||
|
# The rest is in the top level.
|
||||||
|
if module[1] not in (
|
||||||
|
"file_traits",
|
||||||
|
"syslog",
|
||||||
|
"platform_timer_utils",
|
||||||
|
"file_util",
|
||||||
|
"shm",
|
||||||
|
"wait",
|
||||||
|
"mmap",
|
||||||
|
"stream_channel",
|
||||||
|
"timer",
|
||||||
|
):
|
||||||
|
del module[0]
|
||||||
|
if len(module) > 0 and module[0] in ("punch_hole", "write_zeros"):
|
||||||
|
module = ["write_zeroes", module[0]]
|
||||||
|
|
||||||
if use.startswith("crate::"):
|
if use.startswith("crate::"):
|
||||||
new_use = use.replace("crate::", "super::" * len(module))
|
new_use = use.replace("crate::", "super::" * len(module))
|
||||||
print("::".join(module), use, "->", new_use)
|
print("::".join(module), use, "->", new_use)
|
||||||
|
@ -128,18 +147,17 @@ def use_super_instead_of_crate(root: Path):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for crate in ("sys_util", "win_sys_util", "sys_util_core", "cros_async"):
|
path = Path("common") / "win_sys_util/src"
|
||||||
path = Path("common") / crate / "src"
|
subprocess.check_call(["git", "checkout", "-f", str(path)])
|
||||||
subprocess.check_call(["git", "checkout", "-f", str(path)])
|
|
||||||
|
|
||||||
# Use rustfmt to re-format use statements to be one per line.
|
# Use rustfmt to re-format use statements to be one per line.
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
["rustfmt", "+nightly", "--config=imports_granularity=item", f"{path}/lib.rs"]
|
["rustfmt", "+nightly", "--config=imports_granularity=item", f"{path}/lib.rs"]
|
||||||
)
|
)
|
||||||
use_super_instead_of_crate(path)
|
use_super_instead_of_crate(path)
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
["rustfmt", "+nightly", "--config=imports_granularity=crate", f"{path}/lib.rs"]
|
["rustfmt", "+nightly", "--config=imports_granularity=crate", f"{path}/lib.rs"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue