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
12aa6d86
Commit
12aa6d86
authored
Dec 24, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make config.prop optional
parent
7d08969d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
34 deletions
+81
-34
build.gradle.kts
app/build.gradle.kts
+4
-4
build.py
build.py
+26
-15
build.gradle.kts
buildSrc/build.gradle.kts
+4
-0
BuildSource.kt
buildSrc/src/main/java/BuildSource.kt
+22
-7
config.prop.sample
config.prop.sample
+25
-8
No files found.
app/build.gradle.kts
View file @
12aa6d86
...
@@ -20,12 +20,12 @@ android {
...
@@ -20,12 +20,12 @@ android {
applicationId
=
"com.topjohnwu.magisk"
applicationId
=
"com.topjohnwu.magisk"
vectorDrawables
.
useSupportLibrary
=
true
vectorDrawables
.
useSupportLibrary
=
true
multiDexEnabled
=
true
multiDexEnabled
=
true
versionName
=
Config
[
"appVersion"
]
versionName
=
Config
.
appVersion
versionCode
=
Config
[
"appVersionCode"
]
?.
toInt
()
versionCode
=
Config
.
appVersionCode
buildConfigField
(
"int"
,
"LATEST_MAGISK"
,
Config
[
"versionCode"
]
?:
"Integer.MAX_VALUE"
)
buildConfigField
(
"int"
,
"LATEST_MAGISK"
,
Config
.
magiskVersionCode
.
toString
()
)
javaCompileOptions
.
annotationProcessorOptions
.
arguments
(
javaCompileOptions
.
annotationProcessorOptions
.
arguments
(
mapOf
(
"room.incremental"
to
"true"
)
mapOf
(
"room.incremental"
to
"true"
)
)
)
}
}
...
...
build.py
View file @
12aa6d86
...
@@ -116,6 +116,10 @@ def system(cmd):
...
@@ -116,6 +116,10 @@ def system(cmd):
return
subprocess
.
run
(
cmd
,
shell
=
True
,
stdout
=
STDOUT
)
return
subprocess
.
run
(
cmd
,
shell
=
True
,
stdout
=
STDOUT
)
def
cmd_out
(
cmd
):
return
subprocess
.
check_output
(
cmd
)
.
strip
()
.
decode
(
'utf-8'
)
def
xz
(
data
):
def
xz
(
data
):
return
lzma
.
compress
(
data
,
preset
=
9
,
check
=
lzma
.
CHECK_NONE
)
return
lzma
.
compress
(
data
,
preset
=
9
,
check
=
lzma
.
CHECK_NONE
)
...
@@ -129,37 +133,39 @@ def parse_props(file):
...
@@ -129,37 +133,39 @@ def parse_props(file):
prop
=
line
.
split
(
'='
)
prop
=
line
.
split
(
'='
)
if
len
(
prop
)
!=
2
:
if
len
(
prop
)
!=
2
:
continue
continue
props
[
prop
[
0
]
.
strip
(
'
\t\r\n
'
)]
=
prop
[
1
]
.
strip
(
'
\t\r\n
'
)
value
=
prop
[
1
]
.
strip
(
'
\t\r\n
'
)
if
len
(
value
)
==
0
:
continue
props
[
prop
[
0
]
.
strip
(
'
\t\r\n
'
)]
=
value
return
props
return
props
def
load_config
(
args
):
def
load_config
(
args
):
# Load prop file
commit_hash
=
cmd_out
([
'git'
,
'rev-parse'
,
'--short=8'
,
'refs/heads/master'
])
if
not
op
.
exists
(
args
.
config
):
commit_count
=
cmd_out
([
'git'
,
'rev-list'
,
'--count'
,
'refs/heads/master'
])
error
(
f
'Please make sure {args.config} exists'
)
# Some default values
# Some default values
config
[
'version'
]
=
commit_hash
config
[
'versionCode'
]
=
2147483647
config
[
'appVersion'
]
=
commit_hash
config
[
'appVersionCode'
]
=
commit_count
config
[
'outdir'
]
=
'out'
config
[
'outdir'
]
=
'out'
config
[
'prettyName'
]
=
'false'
config
[
'prettyName'
]
=
'false'
config
[
'keyStore'
]
=
'release-key.jks'
config
[
'keyStore'
]
=
'release-key.jks'
config
.
update
(
parse_props
(
args
.
config
))
# Load prop file
if
op
.
exists
(
args
.
config
):
config
.
update
(
parse_props
(
args
.
config
))
# Sanitize configs
# Sanitize configs
config
[
'prettyName'
]
=
config
[
'prettyName'
]
.
lower
()
==
'true'
config
[
'prettyName'
]
=
config
[
'prettyName'
]
.
lower
()
==
'true'
if
'version'
not
in
config
or
'versionCode'
not
in
config
:
error
(
'Config error: "version" and "versionCode" is required'
)
try
:
try
:
config
[
'versionCode'
]
=
int
(
config
[
'versionCode'
])
config
[
'versionCode'
]
=
int
(
config
[
'versionCode'
])
except
ValueError
:
except
ValueError
:
error
(
'Config error: "versionCode" is required to be an integer'
)
error
(
'Config error: "versionCode" is required to be an integer'
)
if
args
.
release
and
not
op
.
exists
(
config
[
'keyStore'
]):
error
(
f
'Config error: assign "keyStore" to a java keystore'
)
mkdir_p
(
config
[
'outdir'
])
mkdir_p
(
config
[
'outdir'
])
global
STDOUT
global
STDOUT
STDOUT
=
None
if
args
.
verbose
else
subprocess
.
DEVNULL
STDOUT
=
None
if
args
.
verbose
else
subprocess
.
DEVNULL
...
@@ -295,10 +301,15 @@ def build_binary(args):
...
@@ -295,10 +301,15 @@ def build_binary(args):
header
(
'* Building binaries: '
+
' '
.
join
(
args
.
target
))
header
(
'* Building binaries: '
+
' '
.
join
(
args
.
target
))
config_stat
=
os
.
stat
(
args
.
config
)
update_flags
=
True
flags
=
op
.
join
(
'native'
,
'jni'
,
'include'
,
'flags.hpp'
)
flags
=
op
.
join
(
'native'
,
'jni'
,
'include'
,
'flags.hpp'
)
if
config_stat
.
st_mtime_ns
>
os
.
stat
(
flags
)
.
st_mtime_ns
:
os
.
utime
(
flags
,
ns
=
(
config_stat
.
st_atime_ns
,
config_stat
.
st_mtime_ns
))
if
op
.
exists
(
args
.
config
):
config_stat
=
os
.
stat
(
args
.
config
)
update_flags
=
config_stat
.
st_mtime_ns
>
os
.
stat
(
flags
)
.
st_mtime_ns
if
update_flags
:
os
.
utime
(
flags
)
# Basic flags
# Basic flags
global
base_flags
global
base_flags
...
@@ -567,7 +578,7 @@ parser.add_argument('-r', '--release', action='store_true',
...
@@ -567,7 +578,7 @@ parser.add_argument('-r', '--release', action='store_true',
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
help
=
'verbose output'
)
help
=
'verbose output'
)
parser
.
add_argument
(
'-c'
,
'--config'
,
default
=
'config.prop'
,
parser
.
add_argument
(
'-c'
,
'--config'
,
default
=
'config.prop'
,
help
=
'
override
config file (default: config.prop)'
)
help
=
'
set
config file (default: config.prop)'
)
subparsers
=
parser
.
add_subparsers
(
title
=
'actions'
)
subparsers
=
parser
.
add_subparsers
(
title
=
'actions'
)
all_parser
=
subparsers
.
add_parser
(
all_parser
=
subparsers
.
add_parser
(
...
...
buildSrc/build.gradle.kts
View file @
12aa6d86
...
@@ -13,3 +13,7 @@ gradlePlugin {
...
@@ -13,3 +13,7 @@ gradlePlugin {
}
}
}
}
}
}
dependencies
{
implementation
(
"org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r"
)
}
buildSrc/src/main/java/BuildSource.kt
View file @
12aa6d86
import
org.gradle.api.GradleException
import
org.eclipse.jgit.api.Git
import
org.eclipse.jgit.internal.storage.file.FileRepository
import
org.gradle.api.Plugin
import
org.gradle.api.Plugin
import
org.gradle.api.Project
import
org.gradle.api.Project
import
org.gradle.kotlin.dsl.provideDelegate
import
org.gradle.kotlin.dsl.provideDelegate
...
@@ -7,19 +8,33 @@ import java.io.File
...
@@ -7,19 +8,33 @@ import java.io.File
import
java.util.*
import
java.util.*
private
val
props
=
Properties
()
private
val
props
=
Properties
()
private
lateinit
var
commitHash
:
String
private
var
commitCount
=
0
object
Config
{
object
Config
{
operator
fun
get
(
key
:
String
)
=
props
[
key
]
as
?
String
operator
fun
get
(
key
:
String
)
:
String
?
{
fun
contains
(
key
:
String
)
=
props
.
containsKey
(
key
)
val
v
=
props
[
key
]
as
?
String
?:
return
null
return
if
(
v
.
isBlank
())
null
else
v
}
fun
contains
(
key
:
String
)
=
get
(
key
)
!=
null
val
appVersion
:
String
get
()
=
get
(
"appVersion"
)
?:
commitHash
val
appVersionCode
:
Int
get
()
=
get
(
"appVersionCode"
)
?.
toInt
()
?:
commitCount
val
magiskVersionCode
:
Int
get
()
=
get
(
"versionCode"
)
?.
toInt
()
?:
Int
.
MAX_VALUE
}
}
class
MagiskPlugin
:
Plugin
<
Project
>
{
class
MagiskPlugin
:
Plugin
<
Project
>
{
override
fun
apply
(
project
:
Project
)
{
override
fun
apply
(
project
:
Project
)
{
val
configPath
:
String
?
by
project
val
configPath
:
String
?
by
project
val
file
=
configPath
?.
let
{
File
(
it
)
}
?:
project
.
file
(
"config.prop"
)
val
config
=
configPath
?.
let
{
File
(
it
)
}
?:
project
.
file
(
"config.prop"
)
if
(
!
file
.
exists
())
if
(
config
.
exists
())
throw
GradleException
(
"Please setup config.prop"
)
config
.
inputStream
().
use
{
props
.
load
(
it
)
}
file
.
inputStream
().
use
{
props
.
load
(
it
)
}
if
(!
Config
.
contains
(
"appVersion"
)
||
!
Config
.
contains
(
"appVersionCode"
))
{
val
repo
=
FileRepository
(
project
.
rootProject
.
file
(
".git"
))
val
refId
=
repo
.
refDatabase
.
exactRef
(
"refs/heads/master"
).
objectId
commitHash
=
repo
.
newObjectReader
().
abbreviate
(
refId
,
8
).
name
()
commitCount
=
Git
(
repo
).
log
().
add
(
refId
).
call
().
count
()
}
}
}
}
}
config.prop.sample
View file @
12aa6d86
##########################################################
# All variables in config.prop are optional
# Removing or leaving them blank will keep default values
##########################################################
# The version name and version code of Magisk
# The version name and version code of Magisk
version=
version=
versionCode=
versionCode=
...
@@ -6,16 +11,28 @@ versionCode=
...
@@ -6,16 +11,28 @@ versionCode=
appVersion=
appVersion=
appVersionCode=
appVersionCode=
outdir=out
# Output path
outdir=
################################################################
# Whether to use pretty names for zips
# e.g. Magisk-v${version}.zip, Magisk-uninstaller-${date}.zip
# Default names are magisk-${release/debug/uninstaller}.zip
################################################################
# The value is either true or false
prettyName=
# Whether use pretty names for zips, e.g. Magisk-v${version}.zip, Magisk-uninstaller-${date}.zip
#####################################################
# The default output names are magisk-${release/debug/uninstaller}.zip
# Signing configs for signing zips and APKs
prettyName=false
# These 4 variables has to be either all set or not
#####################################################
# Only used when building with release flag
# Path to keystore file
# These passwords are used along with keyStore to sign APKs and zips
keyStore=
# keyPass is the pwd for the specified keyAlias
# Keystore password
keyStore=release-key.jks
keyStorePass=
keyStorePass=
# The desired key alias in the keystore
keyAlias=
keyAlias=
# Password of specified key alias
keyPass=
keyPass=
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