8000 Do not use realpath for DirectoryPrefixFilter by whart222 · Pull Request #712 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Do not use realpath for DirectoryPrefixFilter #712

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 9 commits into from
Mar 8, 2023
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 @@ -50,6 +50,7 @@ Bug fixes and small improvements:
- Fix casing of files if filesystem is case insensitive. (:issue:`694`)
- Fix deadlock if :option:`-j` is used and there are errors from ``gcov`` execution. (:issue:`719`)
- Fix problem in decision parser if case is not on a single line with the break statement. (:issue:`738`)
- Do not use ``realpath`` for ``DirectoryPrefixFilter`` to support symlinks in root directory. (:issue:`712`)

Documentation:

Expand Down
10 changes: 0 additions & 10 deletions gcovr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,6 @@ 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: 1 addition & 3 deletions gcovr/tests/symlink-root/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ 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
cd symlink; $(GCOVR) --txt ../coverage.txt --root $${PWD}

clean:
ifeq ($(filter $(BASE_OS),MSYS_NT MINGW64_NT),)
Expand Down
3 changes: 2 additions & 1 deletion gcovr/tests/symlink-root/reference/clang-10/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Directory: ../symlink
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
main.cpp 2 2 100%
------------------------------------------------------------------------------
TOTAL 0 0 --%
TOTAL 2 2 100%
------------------------------------------------------------------------------
3 changes: 2 additions & 1 deletion gcovr/tests/symlink-root/reference/gcc-5/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Directory: ../symlink
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
main.cpp 2 2 100%
------------------------------------------------------------------------------
TOTAL 0 0 --%
TOTAL 2 2 100%
------------------------------------------------------------------------------
6 changes: 0 additions & 6 deletions gcovr/tests/test_gcovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,6 @@ def pytest_generate_tests(metafunc):
name == "cmake_gtest" and not GCOVR_ISOLATED_TEST,
reason="only available in docker",
),
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
7 changes: 3 additions & 4 deletions gcovr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,13 @@ def match(self, path):

class DirectoryPrefixFilter(Filter):
def __init__(self, directory):
path = realpath(directory)
os_independent_path = get_os_independent_path(path)
os_independent_path = get_os_independent_path(directory)
pattern = re.escape(f"{os_independent_path}/")
super().__init__(pattern)

def match(self, path: str):
realpath = os.path.normpath(path)
return super().match(realpath)
path = os.path.normpath(path)
return super().match(path)


def configure_logging() -> None:
Expand Down
0