auto-detect NDKs installed in standard paths

'ndk_paths' will be automatically filled out from well known sources
like $ANDROID_HOME/ndk-bundle and $ANDROID_HOME/ndk/*.  If a required
version is missing in the buildserver VM, it will be automatically
downloaded and installed into the standard $ANDROID_HOME/ndk/
directory.  Manually setting it here will override the auto-detected
values.  The keys can either be the "release" (e.g. r21e) or the
"revision" (e.g. 21.4.7075529).

https://developer.android.com/studio/projects/configure-agp-ndk#agp_version_41
* sdkmanager installs "ndk;12.3.4567890" into $ANDROID_SDK_ROOT/ndk/
* sdkmanager installs "ndk-bundle" into $ANDROID_SDK_ROOT/ndk-bundle/
This commit is contained in:
Hans-Christoph Steiner 2021-05-26 12:52:54 +02:00
parent 4686c06f62
commit 9f77044d0d
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
4 changed files with 64 additions and 20 deletions

View File

@ -1,8 +1,4 @@
sdk_path: /opt/android-sdk
ndk_paths:
r10e: /opt/android-sdk/ndk/r10e
r21e: /opt/android-sdk/ndk/21.4.7075529
r22b: /opt/android-sdk/ndk/22.0.7026061
java_paths:
8: /usr/lib/jvm/java-8-openjdk-amd64

View File

@ -5,24 +5,20 @@
# Custom path to the Android SDK, defaults to $ANDROID_HOME
# sdk_path: $ANDROID_HOME
# Paths to various installed versions of the Android NDK. If a
# required version is missing in the buildserver VM, it will be
# automatically downloaded and installed into a temporary dir.
# Paths to installed versions of the Android NDK. This will be
# automatically filled out from well known sources like
# $ANDROID_HOME/ndk-bundle and $ANDROID_HOME/ndk/*. If a required
# version is missing in the buildserver VM, it will be automatically
# downloaded and installed into the standard $ANDROID_HOME/ndk/
# directory. Manually setting it here will override the auto-detected
# values. The keys can either be the "release" (e.g. r21e) or the
# "revision" (e.g. 21.4.7075529).
#
# ndk_paths:
# r10e: None
# r11c: None
# r12b: None
# r13b: None
# r14b: None
# r15c: None
# r16b: None
# r17c: None
# r18b: None
# r19c: None
# r20b: None
# r21e: None
# r22b: None
# r10e: $ANDROID_HOME/android-ndk-r10e
# r17: ""
# 21.4.7075529: ~/Android/Ndk
# r22b: null
# Directory to store downloaded tools in (i.e. gradle versions)
# By default, these are stored in ~/.cache/fdroidserver

View File

@ -214,6 +214,14 @@ def _add_java_paths_to_config(pathlist, thisconfig):
def fill_config_defaults(thisconfig):
"""Fill in the global config dict with relevant defaults
For config values that have a path that can be expanded, e.g. an
env var or a ~/, this will store the original value using "_orig"
appended to the key name so that if the config gets written out,
it will preserve the original, unexpanded string.
"""
for k, v in default_config.items():
if k not in thisconfig:
thisconfig[k] = v
@ -281,6 +289,28 @@ def fill_config_defaults(thisconfig):
thisconfig[k][k2] = exp
thisconfig[k][k2 + '_orig'] = v
ndk_paths = thisconfig.get('ndk_paths', {})
ndk_bundle = os.path.join(thisconfig['sdk_path'], 'ndk-bundle')
if os.path.exists(ndk_bundle):
version = get_ndk_version(ndk_bundle)
if version not in ndk_paths:
ndk_paths[version] = ndk_bundle
ndk_dir = os.path.join(thisconfig['sdk_path'], 'ndk')
if os.path.exists(ndk_dir):
for ndk in glob.glob(os.path.join(ndk_dir, '*')):
version = get_ndk_version(ndk)
if version not in ndk_paths:
ndk_paths[version] = ndk
for k in list(ndk_paths.keys()):
if not re.match(r'r[1-9][0-9]*[a-z]?', k):
for ndkdict in NDKS:
if k == ndkdict['revision']:
ndk_paths[ndkdict['release']] = ndk_paths.pop(k)
break
def regsub_file(pattern, repl, path):
with open(path, 'rb') as f:

View File

@ -1832,6 +1832,28 @@ class CommonTest(unittest.TestCase):
fdroidserver.common.auto_install_ndk(build)
list_entry.assert_has_calls(calls)
def test_fill_config_defaults(self):
"""Test the auto-detection of NDKs installed in standard paths"""
sdk_path = tempfile.mkdtemp(
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
)
ndk_bundle = os.path.join(sdk_path, 'ndk-bundle')
os.makedirs(ndk_bundle)
with open(os.path.join(ndk_bundle, 'source.properties'), 'w') as fp:
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 17.2.4988734\n')
config = {'sdk_path': sdk_path}
fdroidserver.common.fill_config_defaults(config)
self.assertEqual({'r17c': ndk_bundle}, config['ndk_paths'])
r21e = os.path.join(sdk_path, 'ndk', '21.4.7075529')
os.makedirs(r21e)
with open(os.path.join(r21e, 'source.properties'), 'w') as fp:
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 21.4.7075529\n')
config = {'sdk_path': sdk_path}
fdroidserver.common.fill_config_defaults(config)
self.assertEqual({'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths'])
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))