From ed027ec3ee59cb160e78f727a1194f288e27023a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 12 Feb 2019 05:17:02 -0500 Subject: [PATCH] Refactor build flags --- build.py | 2 +- native/build.gradle | 3 ++- native/jni/Application.mk | 4 ++-- native/jni/core/daemon.cpp | 4 ++-- native/jni/core/magisk.cpp | 4 ++-- native/jni/include/flags.h | 19 ++++++++++++------- native/jni/magiskboot/main.cpp | 2 +- native/jni/magiskhide/magiskhide.cpp | 2 +- native/jni/magiskpolicy/magiskpolicy.cpp | 2 +- native/jni/resetprop/resetprop.cpp | 2 +- native/jni/su/su.cpp | 4 ++-- native/jni/utils/include/logging.h | 3 --- 12 files changed, 27 insertions(+), 24 deletions(-) diff --git a/build.py b/build.py index 9d919534f..6ff31e3b0 100755 --- a/build.py +++ b/build.py @@ -191,7 +191,7 @@ def build_binary(args): os.utime(os.path.join('native', 'jni', 'include', 'flags.h')) # Basic flags - base_flags = f'MAGISK_VERSION="{config["version"]}" MAGISK_VER_CODE={config["versionCode"]}' + base_flags = f'MAGISK_VERSION={config["version"]} MAGISK_VER_CODE={config["versionCode"]}' if not args.release: base_flags += ' MAGISK_DEBUG=1' diff --git a/native/build.gradle b/native/build.gradle index 146637410..3f407defa 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -12,7 +12,8 @@ android { externalNativeBuild { ndkBuild { // Pass arguments to ndk-build. - arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', 'B_BXZ=1', 'MAGISK_DEBUG=1') + arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', + 'MAGISK_DEBUG=1', 'MAGISK_VERSION=debug', 'MAGISK_VER_CODE=INT_MAX') } } } diff --git a/native/jni/Application.mk b/native/jni/Application.mk index 678fd35ea..31869ea74 100644 --- a/native/jni/Application.mk +++ b/native/jni/Application.mk @@ -1,12 +1,12 @@ APP_ABI := armeabi-v7a x86 APP_CFLAGS := -Oz -std=gnu11 \ --DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE} +-D__MVSTR=${MAGISK_VERSION} -D__MCODE=${MAGISK_VER_CODE} APP_CPPFLAGS := -std=c++17 APP_STL := c++_static APP_PLATFORM := android-16 ifdef MAGISK_DEBUG -APP_CFLAGS += -DMAGISK_DEBUG +APP_CFLAGS += -D__MDBG endif # Busybox require some additional settings diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index dc61f2718..a54125e68 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -70,7 +70,7 @@ static void *request_handler(void *args) { su_daemon_handler(client, &credential); break; case CHECK_VERSION: - write_string(client, xstr(MAGISK_VERSION) ":MAGISK"); + write_string(client, MAGISK_VERSION ":MAGISK"); close(client); break; case CHECK_VERSION_CODE: @@ -109,7 +109,7 @@ static void main_daemon() { xdup2(fd, STDIN_FILENO); close(fd); - LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); + LOGI(SHOW_VER(Magisk) " daemon started\n"); // Get server stat stat("/proc/self/exe", &SERVER_STAT); diff --git a/native/jni/core/magisk.cpp b/native/jni/core/magisk.cpp index 46cc82188..d15b89570 100644 --- a/native/jni/core/magisk.cpp +++ b/native/jni/core/magisk.cpp @@ -13,7 +13,7 @@ [[noreturn]] static void usage() { fprintf(stderr, - "Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) multi-call binary\n" + FULL_VER(Magisk) " multi-call binary\n" "\n" "Usage: magisk [applet [arguments]...]\n" " or: magisk [options]...\n" @@ -48,7 +48,7 @@ int magisk_main(int argc, char *argv[]) { if (argc < 2) usage(); if (strcmp(argv[1], "-c") == 0) { - printf("%s (%d)\n", xstr(MAGISK_VERSION) ":MAGISK", MAGISK_VER_CODE); + printf(MAGISK_VERSION ":MAGISK (" str(MAGISK_VER_CODE) ")\n"); return 0; } else if (strcmp(argv[1], "-v") == 0) { int fd = connect_daemon(); diff --git a/native/jni/include/flags.h b/native/jni/include/flags.h index 4a303d2b0..b2444c6ff 100644 --- a/native/jni/include/flags.h +++ b/native/jni/include/flags.h @@ -1,15 +1,20 @@ #pragma once -/* Include this header anywhere you access MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE. +/* Include this header anywhere accessing MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE. * - * This file is only for more precise incremental builds. We can make sure code that uses + * This file is for precise incremental builds. We can make sure code that uses * external flags are re-compiled by updating the timestamp of this file * */ -#ifndef MAGISK_VERSION -#define MAGISK_VERSION 99.99 -#endif +#define quote(s) #s +#define str(s) quote(s) -#ifndef MAGISK_VER_CODE -#define MAGISK_VER_CODE 99999 +#define MAGISK_VERSION str(__MVSTR) +#define MAGISK_VER_CODE __MCODE + +#define SHOW_VER(name) str(name) " v" MAGISK_VERSION "(" str(MAGISK_VER_CODE) ")" +#define FULL_VER(name) SHOW_VER(name) " (by topjohnwu)" + +#ifdef __MDBG +#define MAGISK_DEBUG #endif diff --git a/native/jni/magiskboot/main.cpp b/native/jni/magiskboot/main.cpp index dbe67ee5e..632594d65 100644 --- a/native/jni/magiskboot/main.cpp +++ b/native/jni/magiskboot/main.cpp @@ -107,7 +107,7 @@ static void usage(char *arg0) { int main(int argc, char *argv[]) { cmdline_logging(); - fprintf(stderr, "MagiskBoot v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) - Boot Image Modification Tool\n"); + fprintf(stderr, FULL_VER(MagiskBoot) " - Boot Image Modification Tool\n"); umask(0); if (argc > 1 && strcmp(argv[1], "--cleanup") == 0) { diff --git a/native/jni/magiskhide/magiskhide.cpp b/native/jni/magiskhide/magiskhide.cpp index 63e8988de..b1585c23e 100644 --- a/native/jni/magiskhide/magiskhide.cpp +++ b/native/jni/magiskhide/magiskhide.cpp @@ -17,7 +17,7 @@ bool hide_enabled = false; [[noreturn]] static void usage(char *arg0) { fprintf(stderr, - "MagiskHide v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n" + FULL_VER(MagiskHide) "\n\n" "Usage: %s [--option [arguments...] ]\n\n" "Options:\n" " --status Return the status of MagiskHide\n" diff --git a/native/jni/magiskpolicy/magiskpolicy.cpp b/native/jni/magiskpolicy/magiskpolicy.cpp index dcb1a5176..bad32ca10 100644 --- a/native/jni/magiskpolicy/magiskpolicy.cpp +++ b/native/jni/magiskpolicy/magiskpolicy.cpp @@ -86,7 +86,7 @@ static const char *type_msg_6 = [[noreturn]] static void usage(char *arg0) { fprintf(stderr, - "MagiskPolicy v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n" + FULL_VER(MagiskPolicy) "\n\n" "Usage: %s [--options...] [policy statements...]\n" "\n" "Options:\n" diff --git a/native/jni/resetprop/resetprop.cpp b/native/jni/resetprop/resetprop.cpp index cf5e44fda..4c968f7d1 100644 --- a/native/jni/resetprop/resetprop.cpp +++ b/native/jni/resetprop/resetprop.cpp @@ -55,7 +55,7 @@ illegal: [[noreturn]] static void usage(char* arg0) { fprintf(stderr, - "resetprop v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu & nkk71) - System Props Modification Tool\n\n" + FULL_VER(resetprop) " - System Props Modification Tool\n\n" "Usage: %s [flags] [options...]\n" "\n" "Options:\n" diff --git a/native/jni/su/su.cpp b/native/jni/su/su.cpp index 2505957db..0bee463f6 100644 --- a/native/jni/su/su.cpp +++ b/native/jni/su/su.cpp @@ -35,7 +35,7 @@ static void usage(int status) { FILE *stream = (status == EXIT_SUCCESS) ? stdout : stderr; fprintf(stream, - "MagiskSU v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ")\n\n" + FULL_VER(MagiskSU) "\n\n" "Usage: su [options] [-] [user [argument...]]\n\n" "Options:\n" " -c, --command COMMAND pass COMMAND to the invoked shell\n" @@ -151,7 +151,7 @@ int su_client_main(int argc, char *argv[]) { printf("%d\n", MAGISK_VER_CODE); exit(EXIT_SUCCESS); case 'v': - printf("%s\n", xstr(MAGISK_VERSION) ":MAGISKSU (topjohnwu)"); + printf("%s\n", MAGISK_VERSION ":MAGISKSU"); exit(EXIT_SUCCESS); case 'z': // Do nothing, placed here for legacy support :) diff --git a/native/jni/utils/include/logging.h b/native/jni/utils/include/logging.h index 5675b5d78..7dc1cd9ef 100644 --- a/native/jni/utils/include/logging.h +++ b/native/jni/utils/include/logging.h @@ -11,9 +11,6 @@ extern "C" { #endif -#define str(a) #a -#define xstr(a) str(a) - typedef enum { L_DEBUG, L_INFO,