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
97588408
Commit
97588408
authored
Aug 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize build script
parent
1def9b30
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
100 deletions
+96
-100
build.py
build.py
+96
-100
No files found.
build.py
View file @
97588408
...
...
@@ -106,6 +106,83 @@ def execv(cmd, redirect=None):
def
system
(
cmd
,
redirect
=
None
):
return
subprocess
.
run
(
cmd
,
shell
=
True
,
stdout
=
redirect
if
redirect
!=
None
else
STDOUT
)
def
sign_zip
(
unsigned
,
output
,
release
):
signer_name
=
'zipsigner-3.0.jar'
zipsigner
=
os
.
path
.
join
(
'utils'
,
'build'
,
'libs'
,
signer_name
)
if
not
os
.
path
.
exists
(
zipsigner
):
header
(
'* Building '
+
signer_name
)
proc
=
execv
([
gradlew
,
'utils:shadowJar'
])
if
proc
.
returncode
!=
0
:
error
(
'Build {} failed!'
.
format
(
signer_name
))
header
(
'* Signing Zip'
)
if
release
:
proc
=
execv
([
'java'
,
'-jar'
,
zipsigner
,
keystore
,
config
[
'keyStorePass'
],
config
[
'keyAlias'
],
config
[
'keyPass'
],
unsigned
,
output
])
else
:
proc
=
execv
([
'java'
,
'-jar'
,
zipsigner
,
unsigned
,
output
])
if
proc
.
returncode
!=
0
:
error
(
'Signing zip failed!'
)
def
sign_apk
(
source
,
target
):
# Find the latest build tools
build_tool
=
os
.
path
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'build-tools'
,
sorted
(
os
.
listdir
(
os
.
path
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'build-tools'
)))[
-
1
])
proc
=
execv
([
os
.
path
.
join
(
build_tool
,
'zipalign'
),
'-vpf'
,
'4'
,
source
,
target
],
subprocess
.
DEVNULL
)
if
proc
.
returncode
!=
0
:
error
(
'Zipalign Magisk Manager failed!'
)
# Find apksigner.jar
apksigner
=
''
for
root
,
dirs
,
files
in
os
.
walk
(
build_tool
):
if
'apksigner.jar'
in
files
:
apksigner
=
os
.
path
.
join
(
root
,
'apksigner.jar'
)
break
if
not
apksigner
:
error
(
'Cannot find apksigner.jar in Android SDK build tools'
)
proc
=
execv
([
'java'
,
'-jar'
,
apksigner
,
'sign'
,
'--ks'
,
keystore
,
'--ks-pass'
,
'pass:'
+
config
[
'keyStorePass'
],
'--ks-key-alias'
,
config
[
'keyAlias'
],
'--key-pass'
,
'pass:'
+
config
[
'keyPass'
],
target
])
if
proc
.
returncode
!=
0
:
error
(
'Release sign Magisk Manager failed!'
)
def
binary_dump
(
src
,
out
,
var_name
):
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
for
i
,
c
in
enumerate
(
src
.
read
()):
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
'0x{:02X},'
.
format
(
c
))
out
.
write
(
'
\n
};
\n
'
)
out
.
flush
()
def
gen_update_binary
():
update_bin
=
[]
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'b64xz'
)
if
not
os
.
path
.
exists
(
binary
):
error
(
'Please build
\'
binary
\'
before zipping!'
)
with
open
(
binary
,
'rb'
)
as
b64xz
:
update_bin
.
append
(
'#! /sbin/sh
\n
EX_ARM=
\'
'
)
update_bin
.
append
(
''
.
join
(
"
\\
x{:02X}"
.
format
(
c
)
for
c
in
b64xz
.
read
()))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'b64xz'
)
with
open
(
binary
,
'rb'
)
as
b64xz
:
update_bin
.
append
(
'
\'\n
EX_X86=
\'
'
)
update_bin
.
append
(
''
.
join
(
"
\\
x{:02X}"
.
format
(
c
)
for
c
in
b64xz
.
read
()))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\'\n
BB_ARM='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\n
BB_X86='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
update_bin
.
append
(
'
\n
'
)
with
open
(
os
.
path
.
join
(
'scripts'
,
'update_binary.sh'
),
'r'
)
as
script
:
update_bin
.
append
(
script
.
read
())
return
''
.
join
(
update_bin
)
def
build_binary
(
args
):
# If nothing specified, build everything
try
:
...
...
@@ -149,7 +226,7 @@ def build_binary(args):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'binaries_arch.h'
)):
error
(
'Build "magisk" before building "magiskinit"'
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries.h'
)):
error
(
'Build
release
stub APK before building "magiskinit"'
)
error
(
'Build stub APK before building "magiskinit"'
)
flags
+=
' B_INIT=1'
old_plat
=
True
...
...
@@ -176,58 +253,6 @@ def build_binary(args):
error
(
'Build binaries failed!'
)
collect_binary
()
def
sign_zip
(
unsigned
,
output
,
release
):
signer_name
=
'zipsigner-3.0.jar'
zipsigner
=
os
.
path
.
join
(
'utils'
,
'build'
,
'libs'
,
signer_name
)
if
not
os
.
path
.
exists
(
zipsigner
):
header
(
'* Building '
+
signer_name
)
proc
=
execv
([
gradlew
,
'utils:shadowJar'
])
if
proc
.
returncode
!=
0
:
error
(
'Build {} failed!'
.
format
(
signer_name
))
header
(
'* Signing Zip'
)
if
release
:
proc
=
execv
([
'java'
,
'-jar'
,
zipsigner
,
keystore
,
config
[
'keyStorePass'
],
config
[
'keyAlias'
],
config
[
'keyPass'
],
unsigned
,
output
])
else
:
proc
=
execv
([
'java'
,
'-jar'
,
zipsigner
,
unsigned
,
output
])
if
proc
.
returncode
!=
0
:
error
(
'Signing zip failed!'
)
def
sign_apk
(
source
,
target
):
# Find the latest build tools
build_tool
=
os
.
path
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'build-tools'
,
sorted
(
os
.
listdir
(
os
.
path
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'build-tools'
)))[
-
1
])
proc
=
execv
([
os
.
path
.
join
(
build_tool
,
'zipalign'
),
'-vpf'
,
'4'
,
source
,
target
],
subprocess
.
DEVNULL
)
if
proc
.
returncode
!=
0
:
error
(
'Zipalign Magisk Manager failed!'
)
# Find apksigner.jar
apksigner
=
''
for
root
,
dirs
,
files
in
os
.
walk
(
build_tool
):
if
'apksigner.jar'
in
files
:
apksigner
=
os
.
path
.
join
(
root
,
'apksigner.jar'
)
break
if
not
apksigner
:
error
(
'Cannot find apksigner.jar in Android SDK build tools'
)
proc
=
execv
([
'java'
,
'-jar'
,
apksigner
,
'sign'
,
'--ks'
,
keystore
,
'--ks-pass'
,
'pass:'
+
config
[
'keyStorePass'
],
'--ks-key-alias'
,
config
[
'keyAlias'
],
'--key-pass'
,
'pass:'
+
config
[
'keyPass'
],
target
])
if
proc
.
returncode
!=
0
:
error
(
'Release sign Magisk Manager failed!'
)
def
binary_dump
(
src
,
out
,
var_name
):
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
for
i
,
c
in
enumerate
(
src
.
read
()):
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
'0x{:02X},'
.
format
(
c
))
out
.
write
(
'
\n
};
\n
'
)
out
.
flush
()
def
build_apk
(
args
):
header
(
'* Building Magisk Manager'
)
...
...
@@ -285,31 +310,6 @@ def build_snet(args):
rm
(
source
)
header
(
'Output: '
+
target
)
def
gen_update_binary
():
update_bin
=
[]
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'b64xz'
)
if
not
os
.
path
.
exists
(
binary
):
error
(
'Please build
\'
binary
\'
before zipping!'
)
with
open
(
binary
,
'rb'
)
as
b64xz
:
update_bin
.
append
(
'#! /sbin/sh
\n
EX_ARM=
\'
'
)
update_bin
.
append
(
''
.
join
(
"
\\
x{:02X}"
.
format
(
c
)
for
c
in
b64xz
.
read
()))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'b64xz'
)
with
open
(
binary
,
'rb'
)
as
b64xz
:
update_bin
.
append
(
'
\'\n
EX_X86=
\'
'
)
update_bin
.
append
(
''
.
join
(
"
\\
x{:02X}"
.
format
(
c
)
for
c
in
b64xz
.
read
()))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\'\n
BB_ARM='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\n
BB_X86='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
update_bin
.
append
(
'
\n
'
)
with
open
(
os
.
path
.
join
(
'scripts'
,
'update_binary.sh'
),
'r'
)
as
script
:
update_bin
.
append
(
script
.
read
())
return
''
.
join
(
update_bin
)
def
zip_main
(
args
):
header
(
'* Packing Flashable Zip'
)
...
...
@@ -426,34 +426,30 @@ def cleanup(args):
header
(
'* Cleaning java'
)
execv
([
gradlew
,
'app:clean'
,
'snet:clean'
,
'utils:clean'
])
def
parse_config
():
global
config
with
open
(
'config.prop'
,
'r'
)
as
f
:
with
open
(
'config.prop'
,
'r'
)
as
f
:
for
line
in
[
l
.
strip
(
'
\t\r\n
'
)
for
l
in
f
]:
if
line
.
startswith
(
'#'
)
or
len
(
line
)
==
0
:
continue
prop
=
line
.
split
(
'='
)
config
[
prop
[
0
]
.
strip
(
'
\t\r\n
'
)]
=
prop
[
1
]
.
strip
(
'
\t\r\n
'
)
if
'version'
not
in
config
or
'versionCode'
not
in
config
:
if
'version'
not
in
config
or
'versionCode'
not
in
config
:
error
(
'"version" and "versionCode" is required in "config.prop"'
)
try
:
try
:
config
[
'versionCode'
]
=
int
(
config
[
'versionCode'
])
except
ValueError
:
except
ValueError
:
error
(
'"versionCode" is required to be an integer'
)
if
'prettyName'
not
in
config
:
if
'prettyName'
not
in
config
:
config
[
'prettyName'
]
=
'false'
config
[
'prettyName'
]
=
config
[
'prettyName'
]
.
lower
()
==
'true'
config
[
'prettyName'
]
=
config
[
'prettyName'
]
.
lower
()
==
'true'
if
'outdir'
not
in
config
:
if
'outdir'
not
in
config
:
config
[
'outdir'
]
=
'out'
mkdir_p
(
config
[
'outdir'
])
parse_config
()
mkdir_p
(
config
[
'outdir'
])
parser
=
argparse
.
ArgumentParser
(
description
=
'Magisk build script'
)
parser
.
add_argument
(
'-r'
,
'--release'
,
action
=
'store_true'
,
help
=
'compile Magisk for release'
)
...
...
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