"""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)
working-directory: .
- run: inv ci-auth-configure
- run: inv ci-auth-make-bear # This runs under pdns-$BUILDER_VERSION/pdns/
- - run: ln -s ../clang-tidy.full .clang-tidy
+ - name: Normalize paths in compilation DB
+ working-directory: .
+ run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION pdns-$BUILDER_VERSION/pdns/compile_commands.json
+ - name: Copy the compilation DB
+ working-directory: .
+ run: cp pdns-$BUILDER_VERSION/pdns/compile_commands.json .
+ - run: ln -s .clang-tidy.full .clang-tidy
+ working-directory: .
- name: Run clang-tidy
- working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns
- run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p2 -export-fixes clang-tidy-auth.yml
+ working-directory: .
+ run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-auth.yml
- name: Print clang-tidy fixes YAML
- working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns
+ working-directory: .
shell: bash
run: |
if [ -f clang-tidy-auth.yml ]; then
fi
- name: Result annotations
id: clang-tidy-annotations
+ working-directory: .
shell: bash
- working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns
run: |
if [ -f clang-tidy-auth.yml ]; then
set +e
- python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-auth.yml
+ python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-auth.yml
echo "failed=$?" >> $GITHUB_OUTPUT
fi
- run: inv ci-auth-install-remotebackend-test-deps
working-directory: ./pdns/recursordist/
- run: inv ci-rec-configure
- run: inv ci-rec-make-bear
- - run: ln -s ../../../.clang-tidy.full .clang-tidy
+ - name: Normalize paths in compilation DB
+ working-directory: .
+ run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION ./pdns/recursordist/pdns-recursor-$BUILDER_VERSION/compile_commands.json
+ - name: Copy compilation DB
+ working-directory: .
+ run: cp ./pdns/recursordist/pdns-recursor-$BUILDER_VERSION/compile_commands.json .
+ - run: ln -s .clang-tidy.full .clang-tidy
+ working-directory: .
- name: Run clang-tidy
- run: git diff -U0 HEAD^..HEAD | python3 ../../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p3 -export-fixes clang-tidy-rec.yml
+ working-directory: .
+ run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-rec.yml
- name: Print clang-tidy fixes YAML
+ working-directory: .
shell: bash
run: |
if [ -f clang-tidy-rec.yml ]; then
fi
- name: Result annotations
id: clang-tidy-annotations
+ working-directory: .
shell: bash
run: |
if [ -f clang-tidy-rec.yml ]; then
set +e
- python ../../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
+ python .github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
echo "failed=$?" >> $GITHUB_OUTPUT
fi
- run: inv ci-rec-run-unit-tests
working-directory: ./pdns/dnsdistdist/
- run: inv ci-dnsdist-configure ${{ matrix.features }}
- run: inv ci-dnsdist-make-bear
- - run: ln -s ../../../.clang-tidy.full .clang-tidy
+ - name: Normalize paths in compilation DB
+ working-directory: .
+ run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION ./pdns/dnsdistdist/dnsdist-$BUILDER_VERSION/compile_commands.json
+ - name: Copy compilation DB
+ run: cp ./pdns/dnsdistdist/dnsdist-$BUILDER_VERSION/compile_commands.json compile_commands.json
+ working-directory: .
+ - run: ln -s .clang-tidy.full .clang-tidy
+ working-directory: .
- name: Run clang-tidy
- run: git diff -U0 HEAD^..HEAD | python3 ../../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p3 -export-fixes clang-tidy-dnsdist.yml
+ working-directory: .
+ run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-dnsdist.yml
- name: Print clang-tidy fixes YAML
+ working-directory: .
shell: bash
run: |
if [ -f clang-tidy-dnsdist.yml ]; then
fi
- name: Result annotations
id: clang-tidy-annotations
+ working-directory: .
shell: bash
run: |
if [ -f clang-tidy-dnsdist.yml ]; then
set +e
- python ../../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
+ python .github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
echo "failed=$?" >> $GITHUB_OUTPUT
fi
- run: inv ci-dnsdist-run-unit-tests