Make versionCode unconfigurable

This commit is contained in:
topjohnwu 2020-12-25 05:34:15 -08:00
parent 12aa6d86e4
commit 8a2a6d9232
5 changed files with 46 additions and 45 deletions

View File

@ -22,7 +22,6 @@ android {
multiDexEnabled = true
versionName = Config.appVersion
versionCode = Config.appVersionCode
buildConfigField("int", "LATEST_MAGISK", Config.magiskVersionCode.toString())
javaCompileOptions.annotationProcessorOptions.arguments(
mapOf("room.incremental" to "true")

View File

@ -55,9 +55,6 @@ arch64 = ['arm64-v8a', 'x86_64']
support_targets = ['magisk', 'magiskinit', 'magiskboot', 'magiskpolicy', 'resetprop', 'busybox', 'test']
default_targets = ['magisk', 'magiskinit', 'magiskboot', 'busybox']
ndk_ver = '21d'
ndk_ver_full = '21.3.6528147'
ndk_root = op.join(os.environ['ANDROID_SDK_ROOT'], 'ndk')
ndk_path = op.join(ndk_root, 'magisk')
ndk_build = op.join(ndk_path, 'ndk-build')
@ -141,23 +138,20 @@ def parse_props(file):
def load_config(args):
commit_hash = cmd_out(['git', 'rev-parse', '--short=8', 'refs/heads/master'])
commit_count = cmd_out(['git', 'rev-list', '--count', 'refs/heads/master'])
commit_hash = cmd_out(['git', 'rev-parse', '--short=8', 'HEAD'])
# Some default values
# Default values
config['version'] = commit_hash
config['versionCode'] = 2147483647
config['appVersion'] = commit_hash
config['appVersionCode'] = commit_count
config['outdir'] = 'out'
config['prettyName'] = 'false'
config['keyStore'] = 'release-key.jks'
# Load prop file
# Load prop files
if op.exists(args.config):
config.update(parse_props(args.config))
# Sanitize configs
for key, value in parse_props('gradle.properties').items():
if key.startswith('magisk.'):
config[key[7:]] = value
config['prettyName'] = config['prettyName'].lower() == 'true'
@ -201,7 +195,7 @@ def clean_elf():
def sign_zip(unsigned, output, release):
if not release:
if not release or 'keyStore' not in config:
mv(unsigned, output)
return
@ -289,7 +283,7 @@ def dump_bin_headers():
def build_binary(args):
# Verify NDK install
props = parse_props(op.join(ndk_path, 'source.properties'))
if props['Pkg.Revision'] != ndk_ver_full:
if props['Pkg.Revision'] != config['fullNdkVersion']:
error('Incorrect NDK. Please install/upgrade NDK with "build.py ndk"')
if args.target:
@ -301,12 +295,17 @@ def build_binary(args):
header('* Building binaries: ' + ' '.join(args.target))
update_flags = True
update_flags = False
flags = op.join('native', 'jni', 'include', 'flags.hpp')
flags_stat = os.stat(flags)
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 os.stat(args.config).st_mtime_ns > flags_stat.st_mtime_ns:
update_flags = True
last_commit = int(cmd_out(['git', 'log', '-1', r'--format=%at', 'HEAD']))
if last_commit > flags_stat.st_mtime:
update_flags = True
if update_flags:
os.utime(flags)
@ -522,6 +521,7 @@ def cleanup(args):
def setup_ndk(args):
os_name = platform.system().lower()
ndk_ver = config['ndkVersion']
url = f'https://dl.google.com/android/repository/android-ndk-r{ndk_ver}-{os_name}-x86_64.zip'
ndk_zip = url.split('/')[-1]
@ -578,7 +578,7 @@ parser.add_argument('-r', '--release', action='store_true',
parser.add_argument('-v', '--verbose', action='store_true',
help='verbose output')
parser.add_argument('-c', '--config', default='config.prop',
help='set config file (default: config.prop)')
help='custom config file (default: config.prop)')
subparsers = parser.add_subparsers(title='actions')
all_parser = subparsers.add_parser(

View File

@ -19,22 +19,21 @@ object Config {
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
val appVersionCode: Int get() = commitCount
}
class MagiskPlugin : Plugin<Project> {
override fun apply(project: Project) {
val configPath: String? by project
val config = configPath?.let { File(it) } ?: project.file("config.prop")
if (config.exists())
config.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()
configPath?.let {
val config = File(it)
if (config.exists())
config.inputStream().use { s -> props.load(s) }
}
val repo = FileRepository(project.rootProject.file(".git"))
val refId = repo.refDatabase.exactRef("HEAD").objectId
commitHash = repo.newObjectReader().abbreviate(refId, 8).name()
commitCount = Git(repo).log().add(refId).call().count()
}
}

View File

@ -3,16 +3,14 @@
# Removing or leaving them blank will keep default values
##########################################################
# The version name and version code of Magisk
version=
versionCode=
# The version name of Magisk. Default: git HEAD short SHA1
version=string
# The version name and version code of Magisk Manager
appVersion=
appVersionCode=
# The version name of Magisk Manager. Default: git HEAD short SHA1
appVersion=string
# Output path
outdir=
# Output path. Default: out
outdir=string
################################################################
# Whether to use pretty names for zips
@ -20,8 +18,8 @@ outdir=
# Default names are magisk-${release/debug/uninstaller}.zip
################################################################
# The value is either true or false
prettyName=
# Default: false
prettyName=bool
#####################################################
# Signing configs for signing zips and APKs
@ -29,10 +27,10 @@ prettyName=
#####################################################
# Path to keystore file
keyStore=
keyStore=string
# Keystore password
keyStorePass=
keyStorePass=string
# The desired key alias in the keystore
keyAlias=
keyAlias=string
# Password of specified key alias
keyPass=
keyPass=string

View File

@ -21,7 +21,7 @@ org.gradle.parallel=true
# The developer environment is optimized for speed and feedback so we nearly always run Gradle jobs with the daemon.
org.gradle.daemon=true
#AndroidX
# Android
android.useAndroidX=true
android.enableJetifier=false
android.enableR8.fullMode=true
@ -29,3 +29,8 @@ android.databinding.incremental=true
android.injected.testOnly=false
kapt.incremental.apt=true
# Magisk
magisk.versionCode=21102
magisk.ndkVersion=21d
magisk.fullNdkVersion=21.3.6528147