From 1e8093ff6e744a3cbda346031104b3e58c77234e Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 29 Nov 2020 09:26:17 +0100 Subject: [PATCH 1/3] Revert "find_sdk_tools_cmd returns non if aapt is not found" This reverts commit 66414a9fc7096cc6f4a3b5e305400741d05f8df1. --- tests/common.TestCase | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/common.TestCase b/tests/common.TestCase index 158f7701..2677c5f7 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -715,9 +715,10 @@ class CommonTest(unittest.TestCase): fdroidserver.common.fill_config_defaults(config) fdroidserver.common.config = config self._set_build_tools() - aapt = fdroidserver.common.find_sdk_tools_cmd('aapt') - if aapt: + try: config['aapt'] = fdroidserver.common.find_sdk_tools_cmd('aapt') + except fdroidserver.exception.FDroidException: + pass # aapt is not required if androguard is present testcases = [ ('repo/obb.main.twoversions_1101613.apk', 'obb.main.twoversions', '1101613', '0.1'), From 1c7df94e760b5f332dcf844610daea06308f46be Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 27 Nov 2020 13:36:27 +0100 Subject: [PATCH 2/3] purge unneeded 'build_tools' config option Back when fdroidserver was built around aapt, that was needed to guarantee that a compatible version of aapt was used. Now, aapt is only optionally used for getting the APK ID, so this was just complicating maintenance. --- examples/config.yml | 3 --- fdroidserver/common.py | 31 ++++++------------------------- tests/build.TestCase | 19 ++----------------- tests/common.TestCase | 5 ++--- tests/vcs.TestCase | 1 - 5 files changed, 10 insertions(+), 49 deletions(-) diff --git a/examples/config.yml b/examples/config.yml index 555699fd..484ecc71 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -31,9 +31,6 @@ # java_paths: # 8: /usr/lib/jvm/java-8-openjdk -# Build tools version to be used -# build_tools: 28.0.3 - # Command or path to binary for running Ant # ant: ant diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 19a9abef..9e4f82bf 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -115,7 +115,6 @@ default_config = { 'r16b': None, }, 'cachedir': os.path.join(os.getenv('HOME'), '.cache', 'fdroidserver'), - 'build_tools': MINIMUM_APKSIGNER_BUILD_TOOLS_VERSION, 'java_paths': None, 'scan_binary': False, 'ant': "ant", @@ -498,18 +497,10 @@ def find_sdk_tools_cmd(cmd): tooldirs = [] if config is not None and 'sdk_path' in config and os.path.exists(config['sdk_path']): # try to find a working path to this command, in all the recent possible paths - if 'build_tools' in config: - build_tools = os.path.join(config['sdk_path'], 'build-tools') - # if 'build_tools' was manually set and exists, check only that one - configed_build_tools = os.path.join(build_tools, config['build_tools']) - if os.path.exists(configed_build_tools): - tooldirs.append(configed_build_tools) - else: - # no configed version, so hunt known paths for it - for f in sorted(os.listdir(build_tools), reverse=True): - if os.path.isdir(os.path.join(build_tools, f)): - tooldirs.append(os.path.join(build_tools, f)) - tooldirs.append(build_tools) + build_tools = os.path.join(config['sdk_path'], 'build-tools') + for f in sorted(os.listdir(build_tools), reverse=True): + if os.path.isdir(os.path.join(build_tools, f)): + tooldirs.append(os.path.join(build_tools, f)) sdk_tools = os.path.join(config['sdk_path'], 'tools') if os.path.exists(sdk_tools): tooldirs.append(sdk_tools) @@ -525,7 +516,8 @@ def find_sdk_tools_cmd(cmd): test_aapt_version(path) return path # did not find the command, exit with error message - ensure_build_tools_exists(config) + if not test_sdk_exists(config): + raise FDroidException(_("Android SDK not found!")) def test_aapt_version(aapt): @@ -578,17 +570,6 @@ def test_sdk_exists(thisconfig): return True -def ensure_build_tools_exists(thisconfig): - if not test_sdk_exists(thisconfig): - raise FDroidException(_("Android SDK not found!")) - build_tools = os.path.join(thisconfig['sdk_path'], 'build-tools') - versioned_build_tools = os.path.join(build_tools, thisconfig['build_tools']) - if not os.path.isdir(versioned_build_tools): - raise FDroidException( - _("Android build-tools path '{path}' does not exist!") - .format(path=versioned_build_tools)) - - def get_local_metadata_files(): '''get any metadata files local to an app's source repo diff --git a/tests/build.TestCase b/tests/build.TestCase index ea1af963..a696f196 100755 --- a/tests/build.TestCase +++ b/tests/build.TestCase @@ -28,23 +28,10 @@ import fdroidserver.scanner class BuildTest(unittest.TestCase): '''fdroidserver/build.py''' - def _set_build_tools(self): - build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools') - if os.path.exists(build_tools): - fdroidserver.common.config['build_tools'] = '' - for f in sorted(os.listdir(build_tools), reverse=True): - versioned = os.path.join(build_tools, f) - if os.path.isdir(versioned) \ - and os.path.isfile(os.path.join(versioned, 'aapt')): - fdroidserver.common.config['build_tools'] = versioned - break - return True - else: - print('no build-tools found: ' + build_tools) - return False - def setUp(self): logging.basicConfig(level=logging.DEBUG) + logger = logging.getLogger('androguard.axml') + logger.setLevel(logging.INFO) # tame the axml debug messages self.basedir = os.path.join(localmodule, 'tests') self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles')) if not os.path.exists(self.tmpdir): @@ -56,7 +43,6 @@ class BuildTest(unittest.TestCase): fdroidserver.common.fill_config_defaults(config) fdroidserver.common.config = config fdroidserver.build.config = config - self._set_build_tools() try: config['aapt'] = fdroidserver.common.find_sdk_tools_cmd('aapt') except fdroidserver.exception.FDroidException: @@ -183,7 +169,6 @@ class BuildTest(unittest.TestCase): config = dict() config['sdk_path'] = os.getenv('ANDROID_HOME') config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')} - config['build_tools'] = 'FAKE_BUILD_TOOLS_VERSION' fdroidserver.common.config = config app = fdroidserver.metadata.App() app.id = 'com.gpl.rpg.AndorsTrail' diff --git a/tests/common.TestCase b/tests/common.TestCase index 2677c5f7..d42bfe85 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -42,6 +42,8 @@ class CommonTest(unittest.TestCase): def setUp(self): logging.basicConfig(level=logging.DEBUG) + logger = logging.getLogger('androguard.axml') + logger.setLevel(logging.INFO) # tame the axml debug messages self.basedir = os.path.join(localmodule, 'tests') self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles')) if not os.path.exists(self.tmpdir): @@ -75,12 +77,10 @@ class CommonTest(unittest.TestCase): def _set_build_tools(self): build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools') if os.path.exists(build_tools): - fdroidserver.common.config['build_tools'] = '' for f in sorted(os.listdir(build_tools), reverse=True): versioned = os.path.join(build_tools, f) if os.path.isdir(versioned) \ and os.path.isfile(os.path.join(versioned, 'apksigner')): - fdroidserver.common.config['build_tools'] = versioned break return True else: @@ -235,7 +235,6 @@ class CommonTest(unittest.TestCase): config = dict() config['sdk_path'] = os.getenv('ANDROID_HOME') config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')} - config['build_tools'] = 'FAKE_BUILD_TOOLS_VERSION' fdroidserver.common.config = config app = fdroidserver.metadata.App() app.id = 'org.fdroid.froid' diff --git a/tests/vcs.TestCase b/tests/vcs.TestCase index a94521fa..a7e7c758 100755 --- a/tests/vcs.TestCase +++ b/tests/vcs.TestCase @@ -59,7 +59,6 @@ class VCSTest(unittest.TestCase): os.mkdir("build") config['sdk_path'] = 'MOCKPATH' config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')} - config['build_tools'] = 'FAKE_BUILD_TOOLS_VERSION' config['java_paths'] = {'fake': 'fake'} fdroidserver.common.config = config app = fdroidserver.metadata.App() From ce10fcb7591c49aa747404294f2b71fe7243098e Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 29 Nov 2020 10:02:30 +0100 Subject: [PATCH 3/3] Check if build_tools path exists before listdir --- fdroidserver/common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 9e4f82bf..2b82526c 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -498,9 +498,10 @@ def find_sdk_tools_cmd(cmd): if config is not None and 'sdk_path' in config and os.path.exists(config['sdk_path']): # try to find a working path to this command, in all the recent possible paths build_tools = os.path.join(config['sdk_path'], 'build-tools') - for f in sorted(os.listdir(build_tools), reverse=True): - if os.path.isdir(os.path.join(build_tools, f)): - tooldirs.append(os.path.join(build_tools, f)) + if os.path.isdir(build_tools): + for f in sorted(os.listdir(build_tools), reverse=True): + if os.path.isdir(os.path.join(build_tools, f)): + tooldirs.append(os.path.join(build_tools, f)) sdk_tools = os.path.join(config['sdk_path'], 'tools') if os.path.exists(sdk_tools): tooldirs.append(sdk_tools)