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

@ -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: