Support building individual applets

This commit is contained in:
topjohnwu 2019-05-30 21:17:58 -07:00
parent bf58205b0a
commit 7918fc3528
3 changed files with 46 additions and 7 deletions

View File

@ -56,11 +56,14 @@ archs = ['armeabi-v7a', 'x86']
arch64 = ['arm64-v8a', 'x86_64'] arch64 = ['arm64-v8a', 'x86_64']
keystore = 'release-key.jks' keystore = 'release-key.jks'
config = {} config = {}
support_targets = ['magisk', 'magiskinit', 'magiskboot', 'magiskpolicy', 'busybox', 'test']
default_targets = ['magisk', 'magiskinit', 'magiskboot', 'busybox']
def mv(source, target): def mv(source, target):
try: try:
shutil.move(source, target) shutil.move(source, target)
vprint(f'mv: {source} -> {target}')
except: except:
pass pass
@ -76,6 +79,7 @@ def cp(source, target):
def rm(file): def rm(file):
try: try:
os.remove(file) os.remove(file)
vprint(f'rm: {file}')
except OSError as e: except OSError as e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
@ -102,7 +106,7 @@ def zip_with_msg(zip_file, source, target):
def collect_binary(): def collect_binary():
for arch in archs + arch64: for arch in archs + arch64:
mkdir_p(os.path.join('native', 'out', arch)) mkdir_p(os.path.join('native', 'out', arch))
for bin in ['magisk', 'magiskinit', 'magiskinit64', 'magiskboot', 'busybox', 'test']: for bin in support_targets + ['magiskinit64']:
source = os.path.join('native', 'libs', arch, bin) source = os.path.join('native', 'libs', arch, bin)
target = os.path.join('native', 'out', arch, bin) target = os.path.join('native', 'out', arch, bin)
mv(source, target) mv(source, target)
@ -183,14 +187,12 @@ def run_ndk_build(flags):
def build_binary(args): def build_binary(args):
support_targets = {'magisk', 'magiskinit', 'magiskboot', 'busybox', 'test'}
if args.target: if args.target:
args.target = set(args.target) & support_targets args.target = set(args.target) & set(support_targets)
if not args.target: if not args.target:
return return
else: else:
# If nothing specified, build everything args.target = default_targets
args.target = ['magisk', 'magiskinit', 'magiskboot', 'busybox']
header('* Building binaries: ' + ' '.join(args.target)) header('* Building binaries: ' + ' '.join(args.target))
@ -227,6 +229,9 @@ def build_binary(args):
run_ndk_build('B_INIT=1') run_ndk_build('B_INIT=1')
run_ndk_build('B_INIT64=1') run_ndk_build('B_INIT64=1')
if 'magiskpolicy' in args.target:
run_ndk_build('B_POLICY=1')
if 'magiskboot' in args.target: if 'magiskboot' in args.target:
run_ndk_build('B_BOOT=1') run_ndk_build('B_BOOT=1')
@ -439,7 +444,8 @@ all_parser.set_defaults(func=build_all)
binary_parser = subparsers.add_parser('binary', help='build binaries') binary_parser = subparsers.add_parser('binary', help='build binaries')
binary_parser.add_argument( binary_parser.add_argument(
'target', nargs='*', help='Support: magisk, magiskinit, magiskboot, busybox. Leave empty to build all.') 'target', nargs='*', help=f"Either {', '.join(support_targets)}, \
or empty for defaults ({', '.join(default_targets)})")
binary_parser.set_defaults(func=build_binary) binary_parser.set_defaults(func=build_binary)
apk_parser = subparsers.add_parser('apk', help='build Magisk Manager APK') apk_parser = subparsers.add_parser('apk', help='build Magisk Manager APK')
@ -463,7 +469,7 @@ un_parser.set_defaults(func=zip_uninstaller)
clean_parser = subparsers.add_parser('clean', help='cleanup.') clean_parser = subparsers.add_parser('clean', help='cleanup.')
clean_parser.add_argument( clean_parser.add_argument(
'target', nargs='*', help='Support: native, java. Leave empty to clean all.') 'target', nargs='*', help='Either native, java, or empty to clean both.')
clean_parser.set_defaults(func=cleanup) clean_parser.set_defaults(func=cleanup)
if len(sys.argv) == 1: if len(sys.argv) == 1:

View File

@ -56,6 +56,30 @@ include $(BUILD_EXECUTABLE)
endif endif
ifdef B_POLICY
include $(CLEAR_VARS)
LOCAL_MODULE := magiskpolicy
LOCAL_STATIC_LIBRARIES := libsepol libutils
LOCAL_C_INCLUDES := \
jni/include \
$(LIBSEPOL) \
$(LIBUTILS)
LOCAL_SRC_FILES := \
core/applet_stub.cpp \
magiskpolicy/api.cpp \
magiskpolicy/magiskpolicy.cpp \
magiskpolicy/rules.cpp \
magiskpolicy/policydb.cpp \
magiskpolicy/sepolicy.c
LOCAL_CFLAGS := -DAPPLET_STUB_MAIN=magiskpolicy_main
LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)
endif
include $(CLEAR_VARS) include $(CLEAR_VARS)
ifdef B_INIT ifdef B_INIT

View File

@ -0,0 +1,9 @@
#include <sys/stat.h>
#include <magisk.h>
int main(int argc, char *argv[]) {
umask(0);
cmdline_logging();
return APPLET_STUB_MAIN(argc, argv);
}