Skip to content

Commit

Permalink
Update dscanner and invoke it from a more versatile Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Apr 23, 2018
1 parent d7f7a27 commit 8a87aef
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
2 changes: 1 addition & 1 deletion tests/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN apt-get install -yq --no-install-recommends curl gnupg

# Install dscanner
RUN mkdir -p /usr/local/bin/
RUN curl -L https://github.com/dlang-community/D-Scanner/releases/download/v0.5.1/dscanner-v0.5.1-linux-x86_64.tar.gz -o /tmp/dscanner.tar.gz
RUN curl -L https://github.com/dlang-community/D-Scanner/releases/download/v0.5.2/dscanner-v0.5.2-linux-x86_64.tar.gz -o /tmp/dscanner.tar.gz
RUN tar -xzf /tmp/dscanner.tar.gz -C /usr/local/bin/
RUN rm /tmp/dscanner.tar.gz
RUN dscanner --version
Expand Down
2 changes: 1 addition & 1 deletion tests/ci/build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ cd ..
#

# run D-Scanner
./tests/ci/run-dscanner.sh
./tests/ci/run-dscanner.py . tests/dscanner.ini
79 changes: 79 additions & 0 deletions tests/ci/run-dscanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

#
# This script is supposed to be used on the appstream-generator CI, and makes
# assumptions about the build environment.
# If you want to run dscanner locally, you will want to adapt this script.
# (at some point in future, we need DScanner to be run by a Meson module)
#

import os
import sys
import glob
import subprocess


BUILD_DIR_NAME = 'build'


def find_local_include_dirs(source_root):
res = list()
for fname in glob.iglob(source_root + '/contrib/subprojects/**/*'):
basename = os.path.basename(fname)
if basename == 'src' or basename == 'source':
res.append(fname)
return res


def find_include_dirs(source_root):
incdirs = find_local_include_dirs(source_root)
incdirs.append(os.path.join(source_root, 'src'))

extra_inc = ['containers',
'stdx-allocator',
'mustache-d']

for d in extra_inc:
for inc_root in ['/usr/include/d/', '/usr/local/include/d/']:
idir = os.path.join(inc_root, d)
if os.path.isdir(idir):
incdirs.append(idir)

# LDC internal includes
incdirs.extend(glob.glob('/usr/lib/ldc/*/include/d/'))
incdirs.extend(glob.glob('/usr/lib/ldc/*/include/d/ldc/'))

# Generated stuff
incdirs.append(source_root + '/' + BUILD_DIR_NAME + '/girepo/')
incdirs.append(source_root + '/' + BUILD_DIR_NAME + '/src/')

return ['-I' + d for d in incdirs]


def run(source_root, dscanner_config):
print('===========================')
print('= D-Scanner =')
print('===========================')

subprocess.run(['dscanner', '--version'])

cmd = ['dscanner',
'--styleCheck', os.path.join(source_root, 'src'),
'--config', dscanner_config]
cmd.extend(find_include_dirs(source_root))

pres = subprocess.run(cmd, cwd=source_root)

if pres.returncode == 0:
print('\033[92m:) Success \033[0m')
sys.exit(0)
else:
print('\033[91m:( D-Scanner found issues \033[0m')
print(pres)
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) < 3:
print('Need at least source-root and dscanner configuration as parameters!')
sys.exit(1)
run(source_root=sys.argv[1], dscanner_config=sys.argv[2])
32 changes: 0 additions & 32 deletions tests/ci/run-dscanner.sh

This file was deleted.

0 comments on commit 8a87aef

Please sign in to comment.