From 60b3b8ddce86ef04f288dcb09426c95abe59fb03 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 27 Sep 2018 03:56:56 -0400 Subject: [PATCH] Better incremental builds --- build.py | 3 +-- native/build.gradle | 4 ++-- native/jni/core/bootstages.c | 1 + native/jni/core/daemon.c | 3 ++- native/jni/core/log_daemon.c | 1 + native/jni/core/magisk.c | 3 ++- native/jni/core/magiskinit.c | 1 + native/jni/include/flags.h | 15 +++++++++++++++ native/jni/include/magisk.h | 1 - native/jni/magiskhide/proc_monitor.c | 1 + native/jni/su/su.c | 3 ++- native/jni/su/su.h | 1 - native/jni/utils/img.c | 1 + native/jni/utils/misc.c | 1 + 14 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 native/jni/include/flags.h diff --git a/build.py b/build.py index e837dd5c8..698a6dfee 100755 --- a/build.py +++ b/build.py @@ -170,8 +170,7 @@ def build_binary(args): header('* Building binaries: ' + ' '.join(args.target)) - # Force update logging.h timestamp to trigger recompilation for the flags to make a difference - os.utime(os.path.join('native', 'jni', 'utils', 'include', 'logging.h')) + os.utime(os.path.join('native', 'jni', 'include', 'flags.h')) # Basic flags base_flags = 'MAGISK_VERSION=\"{}\" MAGISK_VER_CODE={} MAGISK_DEBUG={}'.format(config['version'], config['versionCode'], diff --git a/native/build.gradle b/native/build.gradle index d5f0ec359..63c5d4e72 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -14,8 +14,8 @@ android { externalNativeBuild { ndkBuild { // Pass arguments to ndk-build. - arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', 'B_BXZ=1', 'MAGISK_VERSION=debug', - 'MAGISK_VER_CODE=99999', 'MAGISK_DEBUG=-DMAGISK_DEBUG') + arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', 'B_BXZ=1', + 'MAGISK_DEBUG=-DMAGISK_DEBUG') } } } diff --git a/native/jni/core/bootstages.c b/native/jni/core/bootstages.c index e718dddbc..eb3b2bc4a 100644 --- a/native/jni/core/bootstages.c +++ b/native/jni/core/bootstages.c @@ -21,6 +21,7 @@ #include "daemon.h" #include "resetprop.h" #include "selinux.h" +#include "flags.h" static char buf[PATH_MAX], buf2[PATH_MAX]; static struct vector module_list; diff --git a/native/jni/core/daemon.c b/native/jni/core/daemon.c index 99b16d55b..797c3d39d 100644 --- a/native/jni/core/daemon.c +++ b/native/jni/core/daemon.c @@ -19,6 +19,7 @@ #include "daemon.h" #include "resetprop.h" #include "selinux.h" +#include "flags.h" int setup_done = 0; int seperate_vendor = 0; @@ -69,7 +70,7 @@ static void *request_handler(void *args) { su_daemon_receiver(client, &credential); break; case CHECK_VERSION: - write_string(client, MAGISK_VER_STR); + write_string(client, xstr(MAGISK_VERSION) ":MAGISK"); close(client); break; case CHECK_VERSION_CODE: diff --git a/native/jni/core/log_daemon.c b/native/jni/core/log_daemon.c index 74cc1ff17..6334be2cd 100644 --- a/native/jni/core/log_daemon.c +++ b/native/jni/core/log_daemon.c @@ -16,6 +16,7 @@ #include "magisk.h" #include "utils.h" #include "daemon.h" +#include "flags.h" static int loggable = 0; static struct vector log_cmd, clear_cmd; diff --git a/native/jni/core/magisk.c b/native/jni/core/magisk.c index aefdf98d8..b6b9d89c2 100644 --- a/native/jni/core/magisk.c +++ b/native/jni/core/magisk.c @@ -11,6 +11,7 @@ #include "magisk.h" #include "daemon.h" #include "selinux.h" +#include "flags.h" char *argv0; @@ -66,7 +67,7 @@ int magisk_main(int argc, char *argv[]) { if (argc < 2) usage(); if (strcmp(argv[1], "-c") == 0) { - printf("%s (%d)\n", MAGISK_VER_STR, MAGISK_VER_CODE); + printf("%s (%d)\n", xstr(MAGISK_VERSION) ":MAGISK", MAGISK_VER_CODE); return 0; } else if (strcmp(argv[1], "-v") == 0) { int fd = connect_daemon(); diff --git a/native/jni/core/magiskinit.c b/native/jni/core/magiskinit.c index 9317d3d60..f572a6729 100644 --- a/native/jni/core/magiskinit.c +++ b/native/jni/core/magiskinit.c @@ -45,6 +45,7 @@ #include "utils.h" #include "daemon.h" #include "magisk.h" +#include "flags.h" #define DEFAULT_DT_DIR "/proc/device-tree/firmware/android" diff --git a/native/jni/include/flags.h b/native/jni/include/flags.h new file mode 100644 index 000000000..4a303d2b0 --- /dev/null +++ b/native/jni/include/flags.h @@ -0,0 +1,15 @@ +#pragma once + +/* Include this header anywhere you access MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE. + * + * This file is only for more 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 + +#ifndef MAGISK_VER_CODE +#define MAGISK_VER_CODE 99999 +#endif diff --git a/native/jni/include/magisk.h b/native/jni/include/magisk.h index c39b151ca..a8cb8721c 100644 --- a/native/jni/include/magisk.h +++ b/native/jni/include/magisk.h @@ -6,7 +6,6 @@ #include "logging.h" -#define MAGISK_VER_STR xstr(MAGISK_VERSION) ":MAGISK" #define MAIN_SOCKET "d30138f2310a9fb9c54a3e0c21f58591" #define LOG_SOCKET "5864cd77f2f8c59b3882e2d35dbf51e4" #define JAVA_PACKAGE_NAME "com.topjohnwu.magisk" diff --git a/native/jni/magiskhide/proc_monitor.c b/native/jni/magiskhide/proc_monitor.c index bcbf79e0a..33af0a93b 100644 --- a/native/jni/magiskhide/proc_monitor.c +++ b/native/jni/magiskhide/proc_monitor.c @@ -20,6 +20,7 @@ #include "daemon.h" #include "utils.h" #include "magiskhide.h" +#include "flags.h" static int sockfd = -1; diff --git a/native/jni/su/su.c b/native/jni/su/su.c index d35dd30cc..8ab0518e7 100644 --- a/native/jni/su/su.c +++ b/native/jni/su/su.c @@ -28,6 +28,7 @@ #include "utils.h" #include "su.h" #include "selinux.h" +#include "flags.h" struct su_context *su_ctx; @@ -182,7 +183,7 @@ int su_daemon_main(int argc, char **argv) { printf("%d\n", MAGISK_VER_CODE); exit2(EXIT_SUCCESS); case 'v': - printf("%s\n", MAGISKSU_VER_STR); + printf("%s\n", xstr(MAGISK_VERSION) ":MAGISKSU (topjohnwu)"); exit2(EXIT_SUCCESS); case 'z': // Do nothing, placed here for legacy support :) diff --git a/native/jni/su/su.h b/native/jni/su/su.h index 28abb67b5..e286cc606 100644 --- a/native/jni/su/su.h +++ b/native/jni/su/su.h @@ -11,7 +11,6 @@ #include "db.h" #include "list.h" -#define MAGISKSU_VER_STR xstr(MAGISK_VERSION) ":MAGISKSU (topjohnwu)" #define DEFAULT_SHELL "/system/bin/sh" struct su_info { diff --git a/native/jni/utils/img.c b/native/jni/utils/img.c index 4e993f780..ff044e58d 100644 --- a/native/jni/utils/img.c +++ b/native/jni/utils/img.c @@ -17,6 +17,7 @@ #include "magisk.h" #include "utils.h" #include "img.h" +#include "flags.h" #define round_size(a) ((((a) / 32) + 2) * 32) #define SOURCE_TMP "/dev/.img_src" diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 1dce719c2..4a7c6db41 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -23,6 +23,7 @@ #include "logging.h" #include "utils.h" #include "resetprop.h" +#include "flags.h" unsigned get_shell_uid() { struct passwd* ppwd = getpwnam("shell");