"""
+import argparse
import os
import sys
+from pathlib import Path
import helpers
import unidiff
+def create_argument_parser():
+ """Create command-line argument parser."""
+ parser = argparse.ArgumentParser(
+ description="Filter git diff files that are not in the product"
+ )
+ parser.add_argument(
+ "--product",
+ type=str,
+ required=True,
+ help="Product (auth, dnsdist or rec)",
+ )
+ return parser.parse_args()
+
def main():
"""Start the script."""
- # It might be tempting to normalize the paths here instead of
- # rewriting the compilation database, but then clang-tidy
- # loses the depth of files in the repository, outputing for
- # example "credentials.cc" instead of "pdns/credentials.cc"
+ args = create_argument_parser()
+ product = args.product
+
compdb = helpers.load_compdb("compile_commands.json")
compdb = helpers.index_compdb(compdb)
- pdns_path = os.path.join("pdns", "")
- cwd = os.getcwd()
- root = helpers.get_repo_root()
+ cwd = Path(os.getcwd())
diff = sys.stdin.read()
patch_set = unidiff.PatchSet(diff)
for patch in patch_set:
- path = os.path.join(root, patch.path)
- if path in compdb:
- print(patch)
+ path = Path(patch.path)
+ if product == 'auth':
+ path = Path(cwd).joinpath(path)
else:
- msg = f"Skipping {path}: it is not in the compilation db"
- print(msg, file=sys.stderr)
+ if str(path).startswith('modules'):
+ print(f'Skipping {path}: modules do not apply to {product}', file=sys.stderr)
+ continue
+
+ if str(path).startswith('ext'):
+ subpath = Path(cwd).joinpath(path)
+ else:
+ subpath = Path(cwd).joinpath(path.name)
+
+ if not subpath.exists():
+ print(f'Skipping {path}: does not exist for {product} ({subpath})', file=sys.stderr)
+ continue
+
+ path = subpath
+ if patch.source_file is not None:
+ patch.source_file = str(path)
+ patch.target_file = str(path)
+
+ if not str(path) in compdb:
+ print(f'Skipping {path}: it is not in the compilation db', file=sys.stderr)
+ continue
+
+ print(patch, file=sys.stderr)
+ print(patch)
return 0
"""Helpers for dealing with git, compilation databases, etc."""
-import pathlib
import json
import os
-import sys
import git
import yaml
filename = os.path.join(item["directory"], item["file"])
result.add(filename)
return result
-
-def normalize_dist_dir(version, distPath):
- """Map the path of a source file from inside the dist directory
- to its path in the git repository."""
- # get rid of the distdir path, to get file paths as they are in the repository
- repositoryPath = pathlib.Path(get_repo_root()).resolve()
- distPath = pathlib.Path(distPath).resolve()
- if f'pdns-{version}' in distPath.parts:
- # authoritative or tool
- authPath = repositoryPath.joinpath(f'pdns-{version}').resolve()
- relativeToAuth = distPath.relative_to(authPath)
- return str(repositoryPath.joinpath(relativeToAuth))
-
- if f'pdns-recursor-{version}' in distPath.parts:
- recPath = repositoryPath.joinpath('pdns', 'recursordist', f'pdns-recursor-{version}').resolve()
- relativeToRec = distPath.relative_to(recPath)
- return str(repositoryPath.joinpath('pdns', 'recursordist', relativeToRec).resolve())
-
- if f'dnsdist-{version}' in distPath.parts:
- dnsdistPath = repositoryPath.joinpath('pdns', 'dnsdistdist', f'dnsdist-{version}').resolve()
- relativeToDist = distPath.relative_to(dnsdistPath)
- return str(repositoryPath.joinpath('pdns', 'dnsdistdist', relativeToDist).resolve())
-
- print(f'Unable to map {distPath}', file=sys.stderr)
- return str(distPath)
+++ /dev/null
-#!/usr/bin/env python3
-
-import argparse
-import os
-
-import json
-
-import helpers
-
-def create_argument_parser():
- """Create command-line argument parser."""
- parser = argparse.ArgumentParser(
- description="Normalize paths in compilation database"
- )
- parser.add_argument(
- "--version",
- type=str,
- required=True,
- help="Version number of the current build",
- )
- parser.add_argument('database')
- return parser.parse_args()
-
-if __name__ == "__main__":
- """Start the script."""
- args = create_argument_parser()
-
- compDB = helpers.load_compdb(args.database)
- for entry in compDB:
- for key in ['file', 'directory']:
- if key in entry:
- entry[key] = helpers.normalize_dist_dir(args.version, entry[key])
-
- with open(args.database + '.temp', 'w', encoding='utf-8') as outputFile:
- json.dump(compDB, outputFile, ensure_ascii=False, indent=2)
-
- os.rename(args.database + '.temp', args.database)
inv ci-auth-make-bear
- run: ln -s .clang-tidy.full .clang-tidy
if: matrix.product == 'auth'
- - run: cp ./pdns/compile_commands.json .
- if: matrix.product == 'auth'
- - run: cat compile_commands.json
- if: matrix.product == 'auth'
- name: Run clang-tidy for auth
if: matrix.product == 'auth'
- run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-auth.yml
+ run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py --product auth | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-auth.yml
- name: Print clang-tidy fixes YAML for auth
if: matrix.product == 'auth'
shell: bash
working-directory: ./pdns/dnsdistdist/
run: |
inv ci-dnsdist-make-bear
- - run: ln -s .clang-tidy.full .clang-tidy
- if: matrix.product == 'dnsdist'
- - run: cp ./pdns/dnsdistdist/compile_commands.json .
- if: matrix.product == 'dnsdist'
- - run: cat compile_commands.json
+ - run: ln -s ../../.clang-tidy.full .clang-tidy
if: matrix.product == 'dnsdist'
+ working-directory: ./pdns/dnsdistdist/
- name: Run clang-tidy for dnsdist
if: matrix.product == 'dnsdist'
- run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-dnsdist.yml
+ working-directory: ./pdns/dnsdistdist/
+ run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py --product dnsdist | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-dnsdist.yml
- name: Print clang-tidy fixes YAML for dnsdist
if: matrix.product == 'dnsdist'
+ working-directory: ./pdns/dnsdistdist/
shell: bash
run: |
if [ -f clang-tidy-dnsdist.yml ]; then
- name: Result annotations for dnsdist
if: matrix.product == 'dnsdist'
id: clang-tidy-annotations-dnsdist
+ working-directory: ./pdns/dnsdistdist/
shell: bash
run: |
if [ -f clang-tidy-dnsdist.yml ]; then
set +e
- python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
+ python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
echo "failed=$?" >> $GITHUB_OUTPUT
fi
working-directory: ./pdns/recursordist/
run: |
CONCURRENCY=4 inv ci-rec-make-bear
- - run: ln -s .clang-tidy.full .clang-tidy
- if: matrix.product == 'rec'
- - run: cp ./pdns/recursordist/compile_commands.json .
- if: matrix.product == 'rec'
- - run: cat compile_commands.json
+ - run: ln -s ../../.clang-tidy.full .clang-tidy
if: matrix.product == 'rec'
+ working-directory: ./pdns/recursordist/
- name: Run clang-tidy for rec
if: matrix.product == 'rec'
- run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-rec.yml
+ working-directory: ./pdns/recursordist/
+ run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py --product rec | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-rec.yml
- name: Print clang-tidy fixes YAML for rec
if: matrix.product == 'rec'
+ working-directory: ./pdns/recursordist/
shell: bash
run: |
if [ -f clang-tidy-rec.yml ]; then
- name: Result annotations for rec
if: matrix.product == 'rec'
id: clang-tidy-annotations-rec
+ working-directory: ./pdns/recursordist/
shell: bash
run: |
if [ -f clang-tidy-rec.yml ]; then
set +e
- python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
+ python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
echo "failed=$?" >> $GITHUB_OUTPUT
fi
@task
def ci_auth_make_bear(c):
concurrency = os.getenv('CONCURRENCY', 8)
- # Needed for clang-tidy -line-filter vs project structure shenanigans
- with c.cd('pdns'):
- c.run(f'bear --append -- make -j{concurrency} -k V=1 -C ..')
+ c.run(f'bear --append -- make -j{concurrency} -k V=1')
@task
def ci_rec_make(c):