mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Support rustup wrapper
This commit is contained in:
parent
c1cadf4bdc
commit
3f2264f2c7
23
build.py
23
build.py
@ -626,6 +626,25 @@ def build_all(args):
|
|||||||
build_app(args)
|
build_app(args)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_rustup(args):
|
||||||
|
wrapper_dir = Path(args.wrapper_dir)
|
||||||
|
rm_rf(wrapper_dir)
|
||||||
|
wrapper_dir.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||||
|
if "CARGO_HOME" in os.environ:
|
||||||
|
cargo_home = Path(os.environ["CARGO_HOME"])
|
||||||
|
else:
|
||||||
|
cargo_home = Path.home() / ".cargo"
|
||||||
|
cargo_bin = cargo_home / "bin"
|
||||||
|
for src in cargo_bin.iterdir():
|
||||||
|
tgt = wrapper_dir / src.name
|
||||||
|
tgt.symlink_to(src)
|
||||||
|
# Replace rustup with python script
|
||||||
|
wrapper = wrapper_dir / "rustup"
|
||||||
|
wrapper.unlink()
|
||||||
|
cp(Path("scripts", "rustup_wrapper.py"), wrapper)
|
||||||
|
wrapper.chmod(0o755)
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Magisk build script")
|
parser = argparse.ArgumentParser(description="Magisk build script")
|
||||||
parser.set_defaults(func=lambda x: None)
|
parser.set_defaults(func=lambda x: None)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -656,6 +675,10 @@ cargo_parser = subparsers.add_parser("cargo", help="run cargo with proper enviro
|
|||||||
cargo_parser.add_argument("commands", nargs=argparse.REMAINDER)
|
cargo_parser.add_argument("commands", nargs=argparse.REMAINDER)
|
||||||
cargo_parser.set_defaults(func=run_cargo_cmd)
|
cargo_parser.set_defaults(func=run_cargo_cmd)
|
||||||
|
|
||||||
|
rustup_parser = subparsers.add_parser("rustup", help="setup rustup wrapper")
|
||||||
|
rustup_parser.add_argument("wrapper_dir", help="path to setup rustup wrapper binaries")
|
||||||
|
rustup_parser.set_defaults(func=setup_rustup)
|
||||||
|
|
||||||
app_parser = subparsers.add_parser("app", help="build the Magisk app")
|
app_parser = subparsers.add_parser("app", help="build the Magisk app")
|
||||||
app_parser.set_defaults(func=build_app)
|
app_parser.set_defaults(func=build_app)
|
||||||
|
|
||||||
|
40
scripts/rustup_wrapper.py
Executable file
40
scripts/rustup_wrapper.py
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Why do we need this wrapper?
|
||||||
|
################################
|
||||||
|
#
|
||||||
|
# The command `rustup component list` does not work with custom toolchains:
|
||||||
|
# > error: toolchain 'magisk' does not support components
|
||||||
|
#
|
||||||
|
# However, this command is used by several IDEs to determine available
|
||||||
|
# components that can be used, such as clippy, rustfmt etc.
|
||||||
|
# In this script, we simply redirect the output when using the nightly
|
||||||
|
# channel if any `component` command failed.
|
||||||
|
|
||||||
|
if "CARGO_HOME" in os.environ:
|
||||||
|
cargo_home = Path(os.environ["CARGO_HOME"])
|
||||||
|
else:
|
||||||
|
cargo_home = Path.home() / ".cargo"
|
||||||
|
|
||||||
|
rustup = cargo_home / "bin" / "rustup"
|
||||||
|
|
||||||
|
if "component" in sys.argv:
|
||||||
|
proc = subprocess.run(
|
||||||
|
[rustup, *sys.argv[1:]],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
# Remove any channel overrides
|
||||||
|
if sys.argv[1].startswith("+"):
|
||||||
|
sys.argv.pop(1)
|
||||||
|
# Return the nightly channel results
|
||||||
|
sys.exit(subprocess.run([rustup, "+nightly", *sys.argv[1:]]).returncode)
|
||||||
|
|
||||||
|
# Passthrough
|
||||||
|
sys.exit(subprocess.run([rustup, *sys.argv[1:]]).returncode)
|
Loading…
Reference in New Issue
Block a user