MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / get_ndk_api_level

Function get_ndk_api_level

configure.py:775–820  ·  view source on GitHub ↗

Gets the appropriate NDK API level to use for the provided Android NDK path.

(environ_cp, android_ndk_home_path)

Source from the content-addressed store, hash-verified

773
774
775def get_ndk_api_level(environ_cp, android_ndk_home_path):
776 """Gets the appropriate NDK API level to use for the provided Android NDK path."""
777
778 # First check to see if we're using a blessed version of the NDK.
779 properties_path = '%s/source.properties' % android_ndk_home_path
780 if is_windows() or is_cygwin():
781 properties_path = cygpath(properties_path)
782 with open(properties_path, 'r') as f:
783 filedata = f.read()
784
785 revision = re.search(r'Pkg.Revision = (\d+)', filedata)
786 if revision:
787 ndk_version = revision.group(1)
788 else:
789 raise Exception('Unable to parse NDK revision.')
790 if int(ndk_version) not in _SUPPORTED_ANDROID_NDK_VERSIONS:
791 print('WARNING: The NDK version in %s is %s, which is not '
792 'supported by Bazel (officially supported versions: %s). Please use '
793 'another version. Compiling Android targets may result in confusing '
794 'errors.\n' %
795 (android_ndk_home_path, ndk_version, _SUPPORTED_ANDROID_NDK_VERSIONS))
796
797 # Now grab the NDK API level to use. Note that this is different from the
798 # SDK API level, as the NDK API level is effectively the *min* target SDK
799 # version.
800 platforms = os.path.join(android_ndk_home_path, 'platforms')
801 api_levels = sorted(os.listdir(platforms))
802 api_levels = [
803 x.replace('android-', '') for x in api_levels if 'android-' in x
804 ]
805
806 def valid_api_level(api_level):
807 return os.path.exists(
808 os.path.join(android_ndk_home_path, 'platforms',
809 'android-' + api_level))
810
811 android_ndk_api_level = prompt_loop_or_load_from_env(
812 environ_cp,
813 var_name='ANDROID_NDK_API_LEVEL',
814 var_default='18', # 18 is required for GPU acceleration.
815 ask_for_var=('Please specify the (min) Android NDK API level to use. '
816 '[Available levels: %s]') % api_levels,
817 check_success=valid_api_level,
818 error_msg='Android-%s is not present in the NDK path.')
819
820 return android_ndk_api_level
821
822
823def set_gcc_host_compiler_path(environ_cp):

Callers 1

create_android_ndk_ruleFunction · 0.85

Calls 8

is_windowsFunction · 0.85
is_cygwinFunction · 0.85
cygpathFunction · 0.85
replaceMethod · 0.80
readMethod · 0.45
groupMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected