8000 Print a warning if root directory contains symlinks. by Spacetown · Pull Request #652 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Print a warning if root directory contains symlinks. #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ New features and notable changes:
- New :option:`--json-base` to define a base bath used in JSON reports. (:issue:`656`)
- New :option:`--calls` to report call coverage: function calls invoked/total (:issue:`666`)
- New nox session to generate a portable application with pyinstaller, see :ref:`standalone application`. (:issue:`661`)
- Print a warning if root directory contains symlinks. (:issue:`652`)

Bug fixes and small improvements:

Expand Down
10 changes: 10 additions & 0 deletions gcovr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ def main(args=None):

options.starting_dir = os.path.abspath(os.getcwd())
options.root_dir = os.path.abspath(options.root)
root_dir_realpath = os.path.realpath(options.root_dir)
if options.root_dir != root_dir_realpath and not options.filter:
logger.warning(
"Your project --root directory seems to contain a symlink. "
"This will EXCLUDE source files in your root directory! "
"To fix this, you may have to add a --filter option:\n"
" --filter='%s'\n"
"For details, see https://github.com/gcovr/gcovr/issues/635",
re.escape(root_dir_realpath),
)

#
# Setup filters
Expand Down
4 changes: 4 additions & 0 deletions gcovr/tests/symlink-root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root/stdout.log

# Ignore the linked directory
symlink_root
38 changes: 38 additions & 0 deletions gcovr/tests/symlink-root/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CFLAGS= -fprofile-arcs -ftest-coverage -fPIC

BASE_OS:=$(shell uname | cut -d'-' -f1)

all: links
cd symlink; $(CXX) $(CFLAGS) main.cpp -o testcase

run: txt

txt:
cd symlink; ./testcase
cd symlink; $(GCOVR) --txt ../coverage.txt --root $${PWD} > out.log 2>&1
cd symlink; cat out.log
cd symlink; grep -F "Your project --root directory seems to contain a symlink." out.log

clean:
ifeq ($(filter $(BASE_OS),MSYS_NT MINGW64_NT),)
rm -Rf symlink
else
if [ -d "symlink" ]; then\
cmd.exe /C "rmdir /S /Q symlink";\
fi
endif
rm -f root/*.gc* root/coverage*.* root/sonarqube*.* root/coveralls.json root/out.log

links:
ifeq ($(filter $(BASE_OS),MSYS_NT MINGW64_NT),)
if [ -d "symlink" ]; then\
rm -Rf symlink;\
fi
ln -s ./root symlink;
else
if [ -d "symlink" ]; then\
cmd.exe /C "rmdir /S /Q symlink";\
fi
cmd.exe /C "mklink /j symlink .\root"
endif
find ./root -name '*.o' -or -name '*.gc*' -delete || exit 0
9 changes: 9 additions & 0 deletions gcovr/tests/symlink-root/reference/clang-10/coverage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../symlink
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
------------------------------------------------------------------------------
TOTAL 0 0 --%
------------------------------------------------------------------------------
9 changes: 9 additions & 0 deletions gcovr/tests/symlink-root/reference/gcc-5/coverage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../symlink
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
------------------------------------------------------------------------------
TOTAL 0 0 --%
------------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions gcovr/tests/symlink-root/root/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

int main() {
return 0;
}
6 changes: 6 additions & 0 deletions gcovr/tests/test_gcovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ def pytest_generate_tests(metafunc):
name == "simple1-drive-subst" and not IS_WINDOWS,
reason="drive substitution only available on Windows",
),
pytest.mark.skipif(
name == "symlink-root"
and IS_WINDOWS
and (sys.version_info < (3, 8)),
reason="os.path.realpath resolves symlinks on windows starting with 3.8",
),
pytest.mark.xfail(
name == "exclude-throw-branches"
and format == "html"
Expand Down
0