Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
de2306bd
Commit
de2306bd
authored
Sep 08, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper incremental builds
Auto generate flag.h for precise rebuilding
parent
714feeb9
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
56 additions
and
74 deletions
+56
-74
build.py
build.py
+43
-32
Android.mk
native/jni/Android.mk
+0
-6
Application.mk
native/jni/Application.mk
+0
-6
daemon.cpp
native/jni/core/daemon.cpp
+1
-1
magisk.cpp
native/jni/core/magisk.cpp
+1
-1
flags.hpp
native/jni/include/flags.hpp
+0
-20
init.cpp
native/jni/init/init.cpp
+2
-1
su.cpp
native/jni/su/su.cpp
+1
-1
Android.mk
native/jni/utils/Android.mk
+4
-2
logging.cpp
native/jni/utils/logging.cpp
+2
-2
hook.cpp
native/jni/zygisk/hook.cpp
+2
-2
No files found.
build.py
View file @
de2306bd
...
...
@@ -10,6 +10,7 @@ import shutil
import
stat
import
subprocess
import
sys
import
textwrap
import
urllib.request
import
zipfile
from
distutils.dir_util
import
copy_tree
...
...
@@ -67,6 +68,7 @@ ndk_path = op.join(ndk_root, 'magisk')
ndk_build
=
op
.
join
(
ndk_path
,
'ndk-build'
)
gradlew
=
op
.
join
(
'.'
,
'gradlew'
+
(
'.bat'
if
is_windows
else
''
))
adb_path
=
op
.
join
(
sdk_path
,
'platform-tools'
,
'adb'
+
(
'.exe'
if
is_windows
else
''
))
native_gen_path
=
op
.
join
(
'native'
,
'out'
,
'generated'
)
# Global vars
config
=
{}
...
...
@@ -244,33 +246,60 @@ def sign_zip(unsigned):
error
(
'Signing failed!'
)
def
binary_dump
(
src
,
out
,
var_name
):
out
.
write
(
f
'constexpr unsigned char {var_name}[] = {{'
)
def
binary_dump
(
src
,
var_name
):
out
_str
=
f
'constexpr unsigned char {var_name}[] = {{'
for
i
,
c
in
enumerate
(
xz
(
src
.
read
())):
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
f
'0x{c:02X},'
)
out
.
write
(
'
\n
};
\n
'
)
out
.
flush
()
out
_str
+=
'
\n
'
out
_str
+=
f
'0x{c:02X},'
out
_str
+=
'
\n
};
\n
'
return
out_str
def
run_ndk_build
(
flags
):
os
.
chdir
(
'native'
)
proc
=
system
(
f
'{ndk_build} {
base_flags} {
flags} -j{cpu_count}'
)
proc
=
system
(
f
'{ndk_build} {flags} -j{cpu_count}'
)
if
proc
.
returncode
!=
0
:
error
(
'Build binary failed!'
)
os
.
chdir
(
'..'
)
collect_binary
()
def
dump_bin_headers
():
def
write_if_diff
(
file_name
,
text
):
do_write
=
True
if
op
.
exists
(
file_name
):
with
open
(
file_name
,
'r'
)
as
f
:
orig
=
f
.
read
()
do_write
=
orig
!=
text
if
do_write
:
with
open
(
file_name
,
'w'
)
as
f
:
f
.
write
(
text
)
def
dump_bin_header
():
stub
=
op
.
join
(
config
[
'outdir'
],
'stub-release.apk'
)
if
not
op
.
exists
(
stub
):
error
(
'Build stub APK before building "magiskinit"'
)
mkdir_p
(
op
.
join
(
'native'
,
'out'
))
with
open
(
op
.
join
(
'native'
,
'out'
,
'binaries.h'
),
'w'
)
as
out
:
with
open
(
stub
,
'rb'
)
as
src
:
binary_dump
(
src
,
out
,
'manager_xz'
)
mkdir_p
(
native_gen_path
)
with
open
(
stub
,
'rb'
)
as
src
:
text
=
binary_dump
(
src
,
'manager_xz'
)
write_if_diff
(
op
.
join
(
native_gen_path
,
'binaries.h'
),
text
)
def
dump_flag_header
():
flag_txt
=
textwrap
.
dedent
(
'''
\
#pragma once
#define quote(s) #s
#define str(s) quote(s)
#define MAGISK_FULL_VER MAGISK_VERSION "(" str(MAGISK_VER_CODE) ")"
#define NAME_WITH_VER(name) str(name) " " MAGISK_FULL_VER
'''
)
flag_txt
+=
f
'#define MAGISK_VERSION "{config["version"]}"
\n
'
flag_txt
+=
f
'#define MAGISK_VER_CODE {config["versionCode"]}
\n
'
flag_txt
+=
f
'#define MAGISK_DEBUG {0 if args.release else 1}
\n
'
mkdir_p
(
native_gen_path
)
write_if_diff
(
op
.
join
(
native_gen_path
,
'flags.h'
),
flag_txt
)
def
build_binary
(
args
):
...
...
@@ -291,25 +320,7 @@ def build_binary(args):
header
(
'* Building binaries: '
+
' '
.
join
(
args
.
target
))
update_flags
=
False
flags
=
op
.
join
(
'native'
,
'jni'
,
'include'
,
'flags.hpp'
)
flags_stat
=
os
.
stat
(
flags
)
if
op
.
exists
(
args
.
config
):
if
os
.
stat
(
args
.
config
)
.
st_mtime_ns
>
flags_stat
.
st_mtime_ns
:
update_flags
=
True
if
os
.
stat
(
'gradle.properties'
)
.
st_mtime_ns
>
flags_stat
.
st_mtime_ns
:
update_flags
=
True
if
update_flags
:
os
.
utime
(
flags
)
# Basic flags
global
base_flags
base_flags
=
f
'MAGISK_VERSION={config["version"]} MAGISK_VER_CODE={config["versionCode"]}'
if
not
args
.
release
:
base_flags
+=
' MAGISK_DEBUG=1'
dump_flag_header
()
flag
=
''
...
...
@@ -320,7 +331,7 @@ def build_binary(args):
flag
+=
' B_TEST=1'
if
'magiskinit'
in
args
.
target
:
dump_bin_header
s
()
dump_bin_header
()
flag
+=
' B_INIT=1'
if
'magiskpolicy'
in
args
.
target
:
...
...
native/jni/Android.mk
View file @
de2306bd
...
...
@@ -9,7 +9,6 @@ ifdef B_MAGISK
include $(CLEAR_VARS)
LOCAL_MODULE := magisk
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap libxhook
LOCAL_C_INCLUDES := jni/include
LOCAL_SRC_FILES := \
core/applets.cpp \
...
...
@@ -49,7 +48,6 @@ ifdef B_INIT
LOCAL_MODULE := magiskinit
LOCAL_STATIC_LIBRARIES := libsepol libxz libutils
LOCAL_C_INCLUDES := jni/include out
LOCAL_SRC_FILES := \
init/init.cpp \
...
...
@@ -76,7 +74,6 @@ ifdef B_BOOT
include $(CLEAR_VARS)
LOCAL_MODULE := magiskboot
LOCAL_STATIC_LIBRARIES := libmincrypt liblzma liblz4 libbz2 libfdt libutils libz libzopfli
LOCAL_C_INCLUDES := jni/include
LOCAL_SRC_FILES := \
magiskboot/main.cpp \
...
...
@@ -99,7 +96,6 @@ ifdef B_POLICY
include $(CLEAR_VARS)
LOCAL_MODULE := magiskpolicy
LOCAL_STATIC_LIBRARIES := libsepol libutils
LOCAL_C_INCLUDES := jni/include
LOCAL_SRC_FILES := \
core/applet_stub.cpp \
...
...
@@ -120,7 +116,6 @@ ifdef B_PROP
include $(CLEAR_VARS)
LOCAL_MODULE := resetprop
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils
LOCAL_C_INCLUDES := jni/include
LOCAL_SRC_FILES := \
core/applet_stub.cpp \
...
...
@@ -139,7 +134,6 @@ ifneq (,$(wildcard jni/test.cpp))
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_STATIC_LIBRARIES := libutils libphmap
LOCAL_C_INCLUDES := jni/include
LOCAL_SRC_FILES := test.cpp
include $(BUILD_EXECUTABLE)
...
...
native/jni/Application.mk
View file @
de2306bd
...
...
@@ -10,10 +10,4 @@ APP_STRIP_MODE := --strip-all
# Busybox should use stock libc.a
ifdef B_BB
APP_PLATFORM := android-22
else
# Make Busybox cflag stable
APP_CFLAGS += -D__MVSTR=${MAGISK_VERSION} -D__MCODE=${MAGISK_VER_CODE}
ifdef MAGISK_DEBUG
APP_CFLAGS += -D__MDBG
endif
endif
native/jni/core/daemon.cpp
View file @
de2306bd
...
...
@@ -9,7 +9,7 @@
#include <selinux.hpp>
#include <db.hpp>
#include <resetprop.hpp>
#include <flags.h
pp
>
#include <flags.h>
#include "core.hpp"
...
...
native/jni/core/magisk.cpp
View file @
de2306bd
...
...
@@ -5,7 +5,7 @@
#include <magisk.hpp>
#include <daemon.hpp>
#include <selinux.hpp>
#include <flags.h
pp
>
#include <flags.h>
#include "core.hpp"
...
...
native/jni/include/flags.hpp
deleted
100644 → 0
View file @
714feeb9
#pragma once
/* Include this header anywhere accessing MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE.
*
* 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
* */
#define quote(s) #s
#define str(s) quote(s)
#define MAGISK_VERSION str(__MVSTR)
#define MAGISK_VER_CODE __MCODE
#define MAGISK_FULL_VER MAGISK_VERSION "(" str(MAGISK_VER_CODE) ")"
#define NAME_WITH_VER(name) str(name) " " MAGISK_FULL_VER
#ifdef __MDBG
#define MAGISK_DEBUG
#endif
native/jni/init/init.cpp
View file @
de2306bd
...
...
@@ -6,10 +6,11 @@
#include <vector>
#include <xz.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <binaries.h>
#include "binaries.h"
#include "init.hpp"
using
namespace
std
;
...
...
native/jni/su/su.cpp
View file @
de2306bd
...
...
@@ -16,7 +16,7 @@
#include <magisk.hpp>
#include <daemon.hpp>
#include <utils.hpp>
#include <flags.h
pp
>
#include <flags.h>
#include "su.hpp"
#include "pts.hpp"
...
...
native/jni/utils/Android.mk
View file @
de2306bd
LOCAL_PATH := $(call my-dir)
# All Magisk common code lives here
include $(CLEAR_VARS)
LOCAL_MODULE:= libutils
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_
PATH)/include
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include
out/generated
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_
C_INCLUDES)
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
LOCAL_STATIC_LIBRARIES := libcxx
LOCAL_SRC_FILES := \
...
...
native/jni/utils/logging.cpp
View file @
de2306bd
#include <cstdio>
#include <cstdlib>
#include <flags.h
pp
>
#include <flags.h>
#include "logging.hpp"
...
...
@@ -47,7 +47,7 @@ void cmdline_logging() {
}
// LTO will optimize out the NOP function
#if
def
MAGISK_DEBUG
#if MAGISK_DEBUG
void
LOGD
(
const
char
*
fmt
,
...)
{
LOG_BODY
(
d
)
}
#else
void
LOGD
(
const
char
*
fmt
,
...)
{}
...
...
native/jni/zygisk/hook.cpp
View file @
de2306bd
...
...
@@ -3,7 +3,7 @@
#include <bitset>
#include <utils.hpp>
#include <flags.h
pp
>
#include <flags.h>
#include <daemon.hpp>
#include "inject.hpp"
...
...
@@ -356,7 +356,7 @@ static int hook_register(const char *path, const char *symbol, void *new_func, v
#define APP_PROCESS "^/system/bin/app_process.*"
void
hook_functions
()
{
#if
def
MAGISK_DEBUG
#if MAGISK_DEBUG
xhook_enable_debug
(
1
);
xhook_enable_sigsegv_protection
(
0
);
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment