1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-18 20:50:10 +01:00

scanner: allow running without versionCode and as API

This lets `fdroid scanner my.package.name` run without requiring that the
versionCode is also specified.  It also allows scanner.scan_source() to be
called as a function in the public API of fdroidserver.
This commit is contained in:
Hans-Christoph Steiner 2018-01-23 21:55:37 +01:00
parent 53f603bf30
commit 32213ef040

View File

@ -40,7 +40,7 @@ def get_gradle_compile_commands(build):
return [re.compile(r'\s*' + c, re.IGNORECASE) for c in compileCommands] return [re.compile(r'\s*' + c, re.IGNORECASE) for c in compileCommands]
def scan_source(build_dir, build): def scan_source(build_dir, build=metadata.Build()):
"""Scan the source code in the given directory (and all subdirectories) """Scan the source code in the given directory (and all subdirectories)
and return the number of fatal problems encountered and return the number of fatal problems encountered
""" """
@ -294,19 +294,25 @@ def main():
if app.Disabled: if app.Disabled:
logging.info(_("Skipping {appid}: disabled").format(appid=appid)) logging.info(_("Skipping {appid}: disabled").format(appid=appid))
continue continue
if not app.builds:
logging.info(_("Skipping {appid}: no builds specified").format(appid=appid))
continue
logging.info(_("Processing {appid}").format(appid=appid))
try: try:
if app.RepoType == 'srclib': if app.RepoType == 'srclib':
build_dir = os.path.join('build', 'srclib', app.Repo) build_dir = os.path.join('build', 'srclib', app.Repo)
else: else:
build_dir = os.path.join('build', appid) build_dir = os.path.join('build', appid)
if app.builds:
logging.info(_("Processing {appid}").format(appid=appid))
else:
logging.info(_("{appid}: no builds specified, running on current source state")
.format(appid=appid))
count = scan_source(build_dir)
if count > 0:
logging.warn(_('Scanner found {count} problems in {appid}:')
.format(count=count, appid=appid))
probcount += count
continue
# Set up vcs interface and make sure we have the latest code... # Set up vcs interface and make sure we have the latest code...
vcs = common.getvcs(app.RepoType, app.Repo, build_dir) vcs = common.getvcs(app.RepoType, app.Repo, build_dir)
@ -315,19 +321,18 @@ def main():
if build.disable: if build.disable:
logging.info("...skipping version %s - %s" % ( logging.info("...skipping version %s - %s" % (
build.versionName, build.get('disable', build.commit[1:]))) build.versionName, build.get('disable', build.commit[1:])))
else: continue
logging.info("...scanning version " + build.versionName)
logging.info("...scanning version " + build.versionName)
# Prepare the source code... # Prepare the source code...
common.prepare_source(vcs, app, build, common.prepare_source(vcs, app, build,
build_dir, srclib_dir, build_dir, srclib_dir,
extlib_dir, False) extlib_dir, False)
# Do the scan...
count = scan_source(build_dir, build) count = scan_source(build_dir, build)
if count > 0: if count > 0:
logging.warn('Scanner found %d problems in %s (%s)' % ( logging.warn(_('Scanner found {count} problems in {appid}:{versionCode}:')
count, appid, build.versionCode)) .format(count=count, appid=appid, versionCode=build.versionCode))
probcount += count probcount += count
except BuildException as be: except BuildException as be: