mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
find cmds from SDK build-tools in a more flexible way, on the fly
This is a more flexible approach than testing for the complete SDK and build-tools up front. This will only test for the commands that are actually being run, so that if you only have `aapt` installed, you can do `fdroid update` without errors, but other commands will still give appropriate errors. This also makes the build_tools item in config.py optional, it is only needed if you want to force a specific version of the build-tools.
This commit is contained in:
parent
298a88a498
commit
9244256461
@ -35,7 +35,7 @@ import logging
|
|||||||
|
|
||||||
import common
|
import common
|
||||||
import metadata
|
import metadata
|
||||||
from common import FDroidException, BuildException, VCSException, FDroidPopen, SilentPopen
|
from common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import paramiko
|
import paramiko
|
||||||
@ -754,7 +754,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
|
|||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
raise BuildException("Unsigned apk is not at expected location of " + src)
|
raise BuildException("Unsigned apk is not at expected location of " + src)
|
||||||
|
|
||||||
p = SilentPopen([config['aapt'], 'dump', 'badging', src])
|
p = SdkToolsPopen(['aapt', 'dump', 'badging', src])
|
||||||
|
|
||||||
vercode = None
|
vercode = None
|
||||||
version = None
|
version = None
|
||||||
|
@ -130,9 +130,6 @@ def read_config(opts, config_file='config.py'):
|
|||||||
|
|
||||||
fill_config_defaults(config)
|
fill_config_defaults(config)
|
||||||
|
|
||||||
if not test_build_tools_exists(config):
|
|
||||||
sys.exit(3)
|
|
||||||
|
|
||||||
bin_paths = {
|
bin_paths = {
|
||||||
'aapt': [
|
'aapt': [
|
||||||
os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'aapt'),
|
os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'aapt'),
|
||||||
@ -194,7 +191,42 @@ def read_config(opts, config_file='config.py'):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def find_sdk_tools_cmd(cmd):
|
||||||
|
'''find a working path to a tool from the Android SDK'''
|
||||||
|
|
||||||
|
tooldirs = []
|
||||||
|
if '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)
|
||||||
|
sdk_tools = os.path.join(config['sdk_path'], 'tools')
|
||||||
|
if os.path.exists(sdk_tools):
|
||||||
|
tooldirs.append(sdk_tools)
|
||||||
|
sdk_platform_tools = os.path.join(config['sdk_path'], 'platform-tools')
|
||||||
|
if os.path.exists(sdk_platform_tools):
|
||||||
|
tooldirs.append(sdk_platform_tools)
|
||||||
|
tooldirs.append('/usr/bin')
|
||||||
|
for d in tooldirs:
|
||||||
|
if os.path.isfile(os.path.join(d, cmd)):
|
||||||
|
return os.path.join(d, cmd)
|
||||||
|
# did not find the command, exit with error message
|
||||||
|
ensure_build_tools_exists(config)
|
||||||
|
|
||||||
|
|
||||||
def test_sdk_exists(thisconfig):
|
def test_sdk_exists(thisconfig):
|
||||||
|
if 'sdk_path' not in thisconfig:
|
||||||
|
logging.error("'sdk_path' not set in config.py!")
|
||||||
|
return False
|
||||||
if thisconfig['sdk_path'] == default_config['sdk_path']:
|
if thisconfig['sdk_path'] == default_config['sdk_path']:
|
||||||
logging.error('No Android SDK found!')
|
logging.error('No Android SDK found!')
|
||||||
logging.error('You can use ANDROID_HOME to set the path to your SDK, i.e.:')
|
logging.error('You can use ANDROID_HOME to set the path to your SDK, i.e.:')
|
||||||
@ -214,16 +246,15 @@ def test_sdk_exists(thisconfig):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_build_tools_exists(thisconfig):
|
def ensure_build_tools_exists(thisconfig):
|
||||||
if not test_sdk_exists(thisconfig):
|
if not test_sdk_exists(thisconfig):
|
||||||
return False
|
sys.exit(3)
|
||||||
build_tools = os.path.join(thisconfig['sdk_path'], 'build-tools')
|
build_tools = os.path.join(thisconfig['sdk_path'], 'build-tools')
|
||||||
versioned_build_tools = os.path.join(build_tools, thisconfig['build_tools'])
|
versioned_build_tools = os.path.join(build_tools, thisconfig['build_tools'])
|
||||||
if not os.path.isdir(versioned_build_tools):
|
if not os.path.isdir(versioned_build_tools):
|
||||||
logging.critical('Android Build Tools path "'
|
logging.critical('Android Build Tools path "'
|
||||||
+ versioned_build_tools + '" does not exist!')
|
+ versioned_build_tools + '" does not exist!')
|
||||||
return False
|
sys.exit(3)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def write_password_file(pwtype, password=None):
|
def write_password_file(pwtype, password=None):
|
||||||
@ -1597,8 +1628,7 @@ def isApkDebuggable(apkfile, config):
|
|||||||
|
|
||||||
:param apkfile: full path to the apk to check"""
|
:param apkfile: full path to the apk to check"""
|
||||||
|
|
||||||
p = SilentPopen([config['aapt'],
|
p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'])
|
||||||
'dump', 'xmltree', apkfile, 'AndroidManifest.xml'])
|
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
logging.critical("Failed to get apk manifest information")
|
logging.critical("Failed to get apk manifest information")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -1637,6 +1667,14 @@ class PopenResult:
|
|||||||
output = ''
|
output = ''
|
||||||
|
|
||||||
|
|
||||||
|
def SdkToolsPopen(commands, cwd=None, shell=False):
|
||||||
|
cmd = commands[0]
|
||||||
|
if cmd not in config:
|
||||||
|
config[cmd] = find_sdk_tools_cmd(commands[0])
|
||||||
|
return FDroidPopen([config[cmd]] + commands[1:],
|
||||||
|
cwd=cwd, shell=shell, output=False)
|
||||||
|
|
||||||
|
|
||||||
def SilentPopen(commands, cwd=None, shell=False):
|
def SilentPopen(commands, cwd=None, shell=False):
|
||||||
return FDroidPopen(commands, cwd=cwd, shell=shell, output=False)
|
return FDroidPopen(commands, cwd=cwd, shell=shell, output=False)
|
||||||
|
|
||||||
|
@ -168,28 +168,31 @@ def main():
|
|||||||
logging.info('Try running `fdroid init` in an empty directory.')
|
logging.info('Try running `fdroid init` in an empty directory.')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# try to find a working aapt, in all the recent possible paths
|
if os.path.exists('/usr/bin/aapt'):
|
||||||
build_tools = os.path.join(test_config['sdk_path'], 'build-tools')
|
# make sure at least aapt is found, since this can't do anything without it
|
||||||
aaptdirs = []
|
config['aapt'] = common.find_sdk_tools_cmd('aapt')
|
||||||
aaptdirs.append(os.path.join(build_tools, test_config['build_tools']))
|
else:
|
||||||
aaptdirs.append(build_tools)
|
# try to find a working aapt, in all the recent possible paths
|
||||||
for f in os.listdir(build_tools):
|
build_tools = os.path.join(test_config['sdk_path'], 'build-tools')
|
||||||
if os.path.isdir(os.path.join(build_tools, f)):
|
aaptdirs = []
|
||||||
aaptdirs.append(os.path.join(build_tools, f))
|
aaptdirs.append(os.path.join(build_tools, test_config['build_tools']))
|
||||||
for d in sorted(aaptdirs, reverse=True):
|
aaptdirs.append(build_tools)
|
||||||
if os.path.isfile(os.path.join(d, 'aapt')):
|
for f in os.listdir(build_tools):
|
||||||
aapt = os.path.join(d, 'aapt')
|
if os.path.isdir(os.path.join(build_tools, f)):
|
||||||
break
|
aaptdirs.append(os.path.join(build_tools, f))
|
||||||
if os.path.isfile(aapt):
|
for d in sorted(aaptdirs, reverse=True):
|
||||||
dirname = os.path.basename(os.path.dirname(aapt))
|
if os.path.isfile(os.path.join(d, 'aapt')):
|
||||||
if dirname == 'build-tools':
|
aapt = os.path.join(d, 'aapt')
|
||||||
# this is the old layout, before versioned build-tools
|
break
|
||||||
test_config['build_tools'] = ''
|
if os.path.isfile(aapt):
|
||||||
else:
|
dirname = os.path.basename(os.path.dirname(aapt))
|
||||||
test_config['build_tools'] = dirname
|
if dirname == 'build-tools':
|
||||||
write_to_config(test_config, 'build_tools')
|
# this is the old layout, before versioned build-tools
|
||||||
if not common.test_build_tools_exists(test_config):
|
test_config['build_tools'] = ''
|
||||||
sys.exit(3)
|
else:
|
||||||
|
test_config['build_tools'] = dirname
|
||||||
|
write_to_config(test_config, 'build_tools')
|
||||||
|
common.ensure_build_tools_exists(test_config)
|
||||||
|
|
||||||
# now that we have a local config.py, read configuration...
|
# now that we have a local config.py, read configuration...
|
||||||
config = common.read_config(options)
|
config = common.read_config(options)
|
||||||
|
@ -39,7 +39,7 @@ import logging
|
|||||||
|
|
||||||
import common
|
import common
|
||||||
import metadata
|
import metadata
|
||||||
from common import FDroidPopen, SilentPopen
|
from common import FDroidPopen, SdkToolsPopen
|
||||||
from metadata import MetaDataException
|
from metadata import MetaDataException
|
||||||
|
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
thisinfo['features'] = set()
|
thisinfo['features'] = set()
|
||||||
thisinfo['icons_src'] = {}
|
thisinfo['icons_src'] = {}
|
||||||
thisinfo['icons'] = {}
|
thisinfo['icons'] = {}
|
||||||
p = SilentPopen([config['aapt'], 'dump', 'badging', apkfile])
|
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile])
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
if options.delete_unknown:
|
if options.delete_unknown:
|
||||||
if os.path.exists(apkfile):
|
if os.path.exists(apkfile):
|
||||||
|
@ -21,9 +21,50 @@ import fdroidserver.common
|
|||||||
class CommonTest(unittest.TestCase):
|
class CommonTest(unittest.TestCase):
|
||||||
'''fdroidserver/common.py'''
|
'''fdroidserver/common.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 _find_all(self):
|
||||||
|
for cmd in ('aapt', 'adb', 'android', 'zipalign'):
|
||||||
|
path = fdroidserver.common.find_sdk_tools_cmd(cmd)
|
||||||
|
if path is not None:
|
||||||
|
self.assertTrue(os.path.exists(path))
|
||||||
|
self.assertTrue(os.path.isfile(path))
|
||||||
|
|
||||||
|
def test_find_sdk_tools_cmd(self):
|
||||||
|
fdroidserver.common.config = dict()
|
||||||
|
# TODO add this once everything works without sdk_path set in config
|
||||||
|
#self._find_all()
|
||||||
|
sdk_path = os.getenv('ANDROID_HOME')
|
||||||
|
if os.path.exists(sdk_path):
|
||||||
|
fdroidserver.common.config['sdk_path'] = sdk_path
|
||||||
|
if os.path.exists('/usr/bin/aapt'):
|
||||||
|
# this test only works when /usr/bin/aapt is installed
|
||||||
|
self._find_all()
|
||||||
|
build_tools = os.path.join(sdk_path, 'build-tools')
|
||||||
|
if self._set_build_tools():
|
||||||
|
self._find_all()
|
||||||
|
else:
|
||||||
|
print 'no build-tools found: ' + build_tools
|
||||||
|
|
||||||
def testIsApkDebuggable(self):
|
def testIsApkDebuggable(self):
|
||||||
config = dict()
|
config = dict()
|
||||||
config['aapt'] = '/usr/bin/aapt'
|
config['sdk_path'] = os.getenv('ANDROID_HOME')
|
||||||
|
fdroidserver.common.config = config
|
||||||
|
self._set_build_tools();
|
||||||
|
config['aapt'] = fdroidserver.common.find_sdk_tools_cmd('aapt')
|
||||||
# these are set debuggable
|
# these are set debuggable
|
||||||
testfiles = []
|
testfiles = []
|
||||||
testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip.apk'))
|
testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip.apk'))
|
||||||
|
@ -209,16 +209,20 @@ $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
|
|||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
echo_header "check that 'fdroid init' fails when build-tools cannot be found"
|
echo_header "check that 'fdroid init' fails when build-tools cannot be found"
|
||||||
|
|
||||||
REPOROOT=`create_test_dir`
|
if [ -e /usr/bin/aapt ]; then
|
||||||
FAKE_ANDROID_HOME=`create_test_dir`
|
echo "/usr/bin/aapt exists, not running test"
|
||||||
create_fake_android_home $FAKE_ANDROID_HOME
|
else
|
||||||
rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
|
REPOROOT=`create_test_dir`
|
||||||
KEYSTORE=$REPOROOT/keystore.jks
|
FAKE_ANDROID_HOME=`create_test_dir`
|
||||||
cd $REPOROOT
|
create_fake_android_home $FAKE_ANDROID_HOME
|
||||||
set +e
|
rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
|
||||||
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
|
KEYSTORE=$REPOROOT/keystore.jks
|
||||||
[ $? -eq 0 ] && exit 1
|
cd $REPOROOT
|
||||||
set -e
|
set +e
|
||||||
|
$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
|
||||||
|
[ $? -eq 0 ] && exit 1
|
||||||
|
set -e
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
|
Loading…
Reference in New Issue
Block a user