mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-12 18:20:11 +01:00
scan_source: print problems, only return the total count
This commit is contained in:
parent
d6289b7832
commit
0c11f7bc49
@ -445,14 +445,12 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
|
|||||||
if not options.skipscan:
|
if not options.skipscan:
|
||||||
# Scan before building...
|
# Scan before building...
|
||||||
logging.info("Scanning source for common problems...")
|
logging.info("Scanning source for common problems...")
|
||||||
buildprobs = common.scan_source(build_dir, root_dir, thisbuild)
|
count = common.scan_source(build_dir, root_dir, thisbuild)
|
||||||
if len(buildprobs) > 0:
|
if count > 0:
|
||||||
logging.warn('Scanner found %d problems:' % len(buildprobs))
|
if force:
|
||||||
for problem in buildprobs:
|
logging.warn('Scanner found %d problems:' % count)
|
||||||
logging.info(' %s' % problem)
|
else:
|
||||||
if not force:
|
raise BuildException("Can't build due to %d scanned problems" % count)
|
||||||
raise BuildException("Can't build due to " +
|
|
||||||
str(len(buildprobs)) + " scanned problems")
|
|
||||||
|
|
||||||
if not options.notarball:
|
if not options.notarball:
|
||||||
# Build the source tarball right before we build the release...
|
# Build the source tarball right before we build the release...
|
||||||
|
@ -1161,10 +1161,10 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
|
|||||||
return (root_dir, srclibpaths)
|
return (root_dir, srclibpaths)
|
||||||
|
|
||||||
# Scan the source code in the given directory (and all subdirectories)
|
# Scan the source code in the given directory (and all subdirectories)
|
||||||
# and return a list of potential problems.
|
# and return the number of fatal problems encountered
|
||||||
def scan_source(build_dir, root_dir, thisbuild):
|
def scan_source(build_dir, root_dir, thisbuild):
|
||||||
|
|
||||||
problems = []
|
count = 0
|
||||||
|
|
||||||
# Common known non-free blobs (always lower case):
|
# Common known non-free blobs (always lower case):
|
||||||
usual_suspects = ['flurryagent',
|
usual_suspects = ['flurryagent',
|
||||||
@ -1223,14 +1223,16 @@ def scan_source(build_dir, root_dir, thisbuild):
|
|||||||
logging.info('Removing %s at %s' % (what, fd))
|
logging.info('Removing %s at %s' % (what, fd))
|
||||||
os.remove(fp)
|
os.remove(fp)
|
||||||
|
|
||||||
|
def warnproblem(what, fd):
|
||||||
|
logging.warn('Found %s at %s' % (what, fd))
|
||||||
|
|
||||||
def handleproblem(what, fd, fp):
|
def handleproblem(what, fd, fp):
|
||||||
if todelete(fd):
|
if todelete(fd):
|
||||||
removeproblem(what, fd, fp)
|
removeproblem(what, fd, fp)
|
||||||
else:
|
else:
|
||||||
problems.append('Found %s at %s' % (what, fd))
|
logging.error('Found %s at %s' % (what, fd))
|
||||||
|
return True
|
||||||
def warnproblem(what, fd, fp):
|
return False
|
||||||
logging.warn('Found %s at %s' % (what, fd))
|
|
||||||
|
|
||||||
def insidedir(path, dirname):
|
def insidedir(path, dirname):
|
||||||
return path.endswith('/%s' % dirname) or '/%s/' % dirname in path
|
return path.endswith('/%s' % dirname) or '/%s/' % dirname in path
|
||||||
@ -1253,13 +1255,13 @@ def scan_source(build_dir, root_dir, thisbuild):
|
|||||||
|
|
||||||
for suspect in usual_suspects:
|
for suspect in usual_suspects:
|
||||||
if suspect in curfile.lower():
|
if suspect in curfile.lower():
|
||||||
handleproblem('usual supect', fd, fp)
|
count += handleproblem('usual supect', fd, fp)
|
||||||
|
|
||||||
mime = magic.from_file(fp, mime=True) if ms is None else ms.file(fp)
|
mime = magic.from_file(fp, mime=True) if ms is None else ms.file(fp)
|
||||||
if mime == 'application/x-sharedlib':
|
if mime == 'application/x-sharedlib':
|
||||||
handleproblem('shared library', fd, fp)
|
count += handleproblem('shared library', fd, fp)
|
||||||
elif mime == 'application/x-archive':
|
elif mime == 'application/x-archive':
|
||||||
handleproblem('static library', fd, fp)
|
count += handleproblem('static library', fd, fp)
|
||||||
elif mime == 'application/x-executable':
|
elif mime == 'application/x-executable':
|
||||||
handleproblem('binary executable', fd, fp)
|
handleproblem('binary executable', fd, fp)
|
||||||
elif mime == 'application/x-java-applet':
|
elif mime == 'application/x-java-applet':
|
||||||
@ -1271,14 +1273,14 @@ def scan_source(build_dir, root_dir, thisbuild):
|
|||||||
'application/java-archive',
|
'application/java-archive',
|
||||||
'binary',
|
'binary',
|
||||||
]:
|
]:
|
||||||
warnproblem('JAR file', fd, fp)
|
warnproblem('JAR file', fd)
|
||||||
elif mime == 'application/zip':
|
elif mime == 'application/zip':
|
||||||
warnproblem('ZIP file', fd, fp)
|
warnproblem('ZIP file', fd)
|
||||||
|
|
||||||
elif has_extension(fp, 'java'):
|
elif has_extension(fp, 'java'):
|
||||||
for line in file(fp):
|
for line in file(fp):
|
||||||
if 'DexClassLoader' in line:
|
if 'DexClassLoader' in line:
|
||||||
handleproblem('DexClassLoader', fd, fp)
|
count += handleproblem('DexClassLoader', fd, fp)
|
||||||
break
|
break
|
||||||
if ms is not None:
|
if ms is not None:
|
||||||
ms.close()
|
ms.close()
|
||||||
@ -1288,10 +1290,10 @@ def scan_source(build_dir, root_dir, thisbuild):
|
|||||||
# buildjni=no to bypass this check)
|
# buildjni=no to bypass this check)
|
||||||
if (os.path.exists(os.path.join(root_dir, 'jni')) and
|
if (os.path.exists(os.path.join(root_dir, 'jni')) and
|
||||||
thisbuild.get('buildjni') is None):
|
thisbuild.get('buildjni') is None):
|
||||||
msg = 'Found jni directory, but buildjni is not enabled'
|
logging.warn('Found jni directory, but buildjni is not enabled')
|
||||||
problems.append(msg)
|
count += 1
|
||||||
|
|
||||||
return problems
|
return count
|
||||||
|
|
||||||
|
|
||||||
class KnownApks:
|
class KnownApks:
|
||||||
|
Loading…
Reference in New Issue
Block a user