2013-10-31 13:25:39 +01:00
|
|
|
#!/usr/bin/env python2
|
2012-01-03 16:37:29 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# scanner.py - part of the FDroid server tools
|
2013-10-31 16:37:39 +01:00
|
|
|
# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
|
2012-01-03 16:37:29 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
2012-01-04 22:37:11 +01:00
|
|
|
import traceback
|
2012-01-03 16:37:29 +01:00
|
|
|
from optparse import OptionParser
|
2014-01-27 16:56:55 +01:00
|
|
|
import logging
|
|
|
|
|
2014-05-02 04:36:12 +02:00
|
|
|
import common
|
|
|
|
import metadata
|
2012-01-03 22:39:30 +01:00
|
|
|
from common import BuildException
|
|
|
|
from common import VCSException
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
config = None
|
|
|
|
options = None
|
2013-10-31 16:37:39 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
def main():
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
global config, options
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
# Parse command line...
|
2013-12-19 23:06:57 +01:00
|
|
|
parser = OptionParser(usage="Usage: %prog [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
|
2012-02-26 15:18:58 +01:00
|
|
|
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
|
|
|
help="Spew out even more information than normal")
|
2014-02-22 10:46:24 +01:00
|
|
|
parser.add_option("-q", "--quiet", action="store_true", default=False,
|
|
|
|
help="Restrict output to warnings and errors")
|
2012-03-06 20:55:40 +01:00
|
|
|
parser.add_option("--nosvn", action="store_true", default=False,
|
|
|
|
help="Skip svn repositories - for test purposes, because they are too slow.")
|
2012-02-26 15:18:58 +01:00
|
|
|
(options, args) = parser.parse_args()
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
config = common.read_config(options)
|
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
# Get all apps...
|
2013-12-19 23:06:57 +01:00
|
|
|
allapps = metadata.read_metadata()
|
|
|
|
apps = common.read_app_args(args, allapps, True)
|
2012-03-11 22:59:25 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
problems = []
|
2012-01-27 23:10:08 +01:00
|
|
|
|
2013-10-29 13:23:42 +01:00
|
|
|
build_dir = 'build'
|
|
|
|
if not os.path.isdir(build_dir):
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Creating build directory")
|
2013-10-29 13:23:42 +01:00
|
|
|
os.makedirs(build_dir)
|
|
|
|
srclib_dir = os.path.join(build_dir, 'srclib')
|
|
|
|
extlib_dir = os.path.join(build_dir, 'extlib')
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
for app in apps:
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2012-03-11 22:59:25 +01:00
|
|
|
if app['Disabled']:
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Skipping %s: disabled" % app['id'])
|
2013-12-19 23:06:57 +01:00
|
|
|
continue
|
|
|
|
if not app['builds']:
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Skipping %s: no builds specified" % app['id'])
|
2013-12-19 23:06:57 +01:00
|
|
|
continue
|
2012-03-06 20:55:40 +01:00
|
|
|
elif options.nosvn and app['Repo Type'] == 'svn':
|
2013-12-19 23:06:57 +01:00
|
|
|
continue
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Processing " + app['id'])
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
try:
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
build_dir = 'build/' + app['id']
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
# Set up vcs interface and make sure we have the latest code...
|
|
|
|
vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir)
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
for thisbuild in app['builds']:
|
2012-01-03 22:39:30 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
if 'disable' in thisbuild:
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("...skipping version %s - %s" % (
|
|
|
|
thisbuild['version'], thisbuild.get('disable', thisbuild['commit'][1:])))
|
2013-12-19 23:06:57 +01:00
|
|
|
else:
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("...scanning version " + thisbuild['version'])
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
# Prepare the source code...
|
|
|
|
root_dir, _ = common.prepare_source(vcs, app, thisbuild,
|
|
|
|
build_dir, srclib_dir, extlib_dir, False)
|
2012-01-28 10:41:46 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
# Do the scan...
|
|
|
|
buildprobs = common.scan_source(build_dir, root_dir, thisbuild)
|
|
|
|
for problem in buildprobs:
|
2013-12-30 17:04:16 +01:00
|
|
|
problems.append(problem +
|
2013-12-19 23:06:57 +01:00
|
|
|
' in ' + app['id'] + ' ' + thisbuild['version'])
|
2012-01-03 16:37:29 +01:00
|
|
|
|
2013-12-19 23:06:57 +01:00
|
|
|
except BuildException as be:
|
|
|
|
msg = "Could not scan app %s due to BuildException: %s" % (app['id'], be)
|
|
|
|
problems.append(msg)
|
|
|
|
except VCSException as vcse:
|
|
|
|
msg = "VCS error while scanning app %s: %s" % (app['id'], vcse)
|
|
|
|
problems.append(msg)
|
|
|
|
except Exception:
|
|
|
|
msg = "Could not scan app %s due to unknown error: %s" % (app['id'], traceback.format_exc())
|
|
|
|
problems.append(msg)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Finished:")
|
2012-02-26 15:18:58 +01:00
|
|
|
for problem in problems:
|
|
|
|
print problem
|
|
|
|
print str(len(problems)) + ' problems.'
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
2012-01-03 16:37:29 +01:00
|
|
|
|