mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-30 13:30:15 +02:00
Support generating files for C++ IDE
This commit is contained in:
parent
03e034795d
commit
00c1b36837
49
build.py
49
build.py
@ -160,6 +160,15 @@ def clean_elf():
|
|||||||
run_cargo(cmds)
|
run_cargo(cmds)
|
||||||
|
|
||||||
|
|
||||||
|
def collect_ndk_build():
|
||||||
|
for arch in build_abis.keys():
|
||||||
|
arch_dir = Path("native", "libs", arch)
|
||||||
|
out_dir = Path("native", "out", arch)
|
||||||
|
for source in arch_dir.iterdir():
|
||||||
|
target = out_dir / source.name
|
||||||
|
mv(source, target)
|
||||||
|
|
||||||
|
|
||||||
def run_ndk_build(cmds: list):
|
def run_ndk_build(cmds: list):
|
||||||
os.chdir("native")
|
os.chdir("native")
|
||||||
cmds.append("NDK_PROJECT_PATH=.")
|
cmds.append("NDK_PROJECT_PATH=.")
|
||||||
@ -175,13 +184,6 @@ def run_ndk_build(cmds: list):
|
|||||||
error("Build binary failed!")
|
error("Build binary failed!")
|
||||||
os.chdir("..")
|
os.chdir("..")
|
||||||
|
|
||||||
for arch in build_abis.keys():
|
|
||||||
arch_dir = Path("native", "libs", arch)
|
|
||||||
out_dir = Path("native", "out", arch)
|
|
||||||
for source in arch_dir.iterdir():
|
|
||||||
target = out_dir / source.name
|
|
||||||
mv(source, target)
|
|
||||||
|
|
||||||
|
|
||||||
def build_cpp_src(targets: set):
|
def build_cpp_src(targets: set):
|
||||||
cmds = []
|
cmds = []
|
||||||
@ -203,6 +205,7 @@ def build_cpp_src(targets: set):
|
|||||||
|
|
||||||
if cmds:
|
if cmds:
|
||||||
run_ndk_build(cmds)
|
run_ndk_build(cmds)
|
||||||
|
collect_ndk_build()
|
||||||
|
|
||||||
cmds.clear()
|
cmds.clear()
|
||||||
|
|
||||||
@ -215,6 +218,7 @@ def build_cpp_src(targets: set):
|
|||||||
if cmds:
|
if cmds:
|
||||||
cmds.append("B_CRT0=1")
|
cmds.append("B_CRT0=1")
|
||||||
run_ndk_build(cmds)
|
run_ndk_build(cmds)
|
||||||
|
collect_ndk_build()
|
||||||
|
|
||||||
if clean:
|
if clean:
|
||||||
clean_elf()
|
clean_elf()
|
||||||
@ -472,6 +476,7 @@ def cleanup():
|
|||||||
rm(rs_gen)
|
rm(rs_gen)
|
||||||
|
|
||||||
if "native" in targets:
|
if "native" in targets:
|
||||||
|
header("* Cleaning native")
|
||||||
rm_rf(Path("native", "out"))
|
rm_rf(Path("native", "out"))
|
||||||
rm_rf(Path("tools", "elf-cleaner", "target"))
|
rm_rf(Path("tools", "elf-cleaner", "target"))
|
||||||
|
|
||||||
@ -491,6 +496,33 @@ def build_all():
|
|||||||
############
|
############
|
||||||
|
|
||||||
|
|
||||||
|
def gen_ide():
|
||||||
|
ensure_paths()
|
||||||
|
args.force_out = True
|
||||||
|
|
||||||
|
# Dump flags for both C++ and Rust code
|
||||||
|
dump_flag_header()
|
||||||
|
|
||||||
|
# Run build.rs to generate Rust/C++ FFI bindings
|
||||||
|
os.chdir(Path("native", "src"))
|
||||||
|
run_cargo(["check"])
|
||||||
|
os.chdir(Path("..", ".."))
|
||||||
|
|
||||||
|
# Generate compilation database
|
||||||
|
run_ndk_build(
|
||||||
|
[
|
||||||
|
"B_MAGISK=1",
|
||||||
|
"B_INIT=1",
|
||||||
|
"B_BOOT=1",
|
||||||
|
"B_POLICY=1",
|
||||||
|
"B_PRELOAD=1",
|
||||||
|
"B_PROP=1",
|
||||||
|
"B_CRT0=1",
|
||||||
|
"compile_commands.json",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def clippy_cli():
|
def clippy_cli():
|
||||||
args.force_out = True
|
args.force_out = True
|
||||||
os.chdir(Path("native", "src"))
|
os.chdir(Path("native", "src"))
|
||||||
@ -801,12 +833,15 @@ def parse_args():
|
|||||||
"wrapper_dir", help="path to setup rustup wrapper binaries"
|
"wrapper_dir", help="path to setup rustup wrapper binaries"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gen_parser = subparsers.add_parser("gen", help="generate files for IDE")
|
||||||
|
|
||||||
# Set callbacks
|
# Set callbacks
|
||||||
all_parser.set_defaults(func=build_all)
|
all_parser.set_defaults(func=build_all)
|
||||||
native_parser.set_defaults(func=build_native)
|
native_parser.set_defaults(func=build_native)
|
||||||
cargo_parser.set_defaults(func=cargo_cli)
|
cargo_parser.set_defaults(func=cargo_cli)
|
||||||
clippy_parser.set_defaults(func=clippy_cli)
|
clippy_parser.set_defaults(func=clippy_cli)
|
||||||
rustup_parser.set_defaults(func=setup_rustup)
|
rustup_parser.set_defaults(func=setup_rustup)
|
||||||
|
gen_parser.set_defaults(func=gen_ide)
|
||||||
app_parser.set_defaults(func=build_app)
|
app_parser.set_defaults(func=build_app)
|
||||||
stub_parser.set_defaults(func=build_stub)
|
stub_parser.set_defaults(func=build_stub)
|
||||||
test_parser.set_defaults(func=build_test)
|
test_parser.set_defaults(func=build_test)
|
||||||
|
1
native/.gitignore
vendored
1
native/.gitignore
vendored
@ -5,3 +5,4 @@ libs
|
|||||||
/.cxx
|
/.cxx
|
||||||
*-rs.cpp
|
*-rs.cpp
|
||||||
*-rs.hpp
|
*-rs.hpp
|
||||||
|
/compile_commands.json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user