From f29b892aa0bee984c19620c152ceff7fffc4f629 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Tue, 3 Sep 2019 17:17:31 +0000 Subject: [PATCH] Bug 1578471 - consolidate NDK version detection; r=nalexander We have an `ndk_version_major` and an `ndk_version_minor` that have a lot of duplicated code in them. We could factor them into a single function, but it seems better to just pull their logic into `ndk_version` directly, rearranging that function to be IMHO more understandable. Differential Revision: https://phabricator.services.mozilla.com/D44506 --HG-- extra : moz-landing-system : lando --- build/moz.configure/android-ndk.configure | 52 +++++++++-------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/build/moz.configure/android-ndk.configure b/build/moz.configure/android-ndk.configure index d497fec71283..c15299c98ea2 100644 --- a/build/moz.configure/android-ndk.configure +++ b/build/moz.configure/android-ndk.configure @@ -86,42 +86,28 @@ def ndk_version(ndk): # Building 'js/src' for non-Android. return with open(os.path.join(ndk, 'source.properties'), 'r') as f: - for line in f: - if not line.startswith('Pkg.Revision'): - continue - (_, version) = line.split('=') - if version: - return version.strip() + revision = [line for line in f if line.startswith('Pkg.Revision')] + if not revision: + die('Cannot determine NDK version from source.properties') + if len(revision) != 1: + die('Too many Pkg.Revision lines in source.properties') + + (_, version) = revision[0].split('=') + if not version: die('Unexpected Pkg.Revision line in source.properties') - die('Cannot determine NDK version from source.properties') + + (major, minor, revision) = version.strip().split('.') + if not major or not minor: + die('Unexpected NDK version string: ' + version) + + return namespace( + major=major, + minor=minor, + ) -@depends(ndk_version) -def ndk_major_version(ndk_version): - if not ndk_version: - # Building 'js/src' for non-Android. - return - (major, minor, revision) = ndk_version.split('.') - if major: - return major - die('Unexpected NDK version string: ' + ndk_version) - - -set_config('ANDROID_NDK_MAJOR_VERSION', ndk_major_version) - - -@depends(ndk_version) -def ndk_minor_version(ndk_version): - if not ndk_version: - # Building 'js/src' for non-Android. - return - (major, minor, revision) = ndk_version.split('.') - if minor: - return minor - die('Unexpected NDK version string: ' + ndk_version) - - -set_config('ANDROID_NDK_MINOR_VERSION', ndk_minor_version) +set_config('ANDROID_NDK_MAJOR_VERSION', ndk_version.major) +set_config('ANDROID_NDK_MINOR_VERSION', ndk_version.minor) @depends(target, android_version, ndk)