8000 Fails to work if source directory is read only · Issue #775 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fails to work if source directory is read only #775

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 8000 .

Already on GitHub? Sign in to your account

Closed
reddwarf69 opened this issue Apr 28, 2023 · 11 comments · Fixed by #781
Closed

Fails to work if source directory is read only #775

reddwarf69 opened this issue Apr 28, 2023 · 11 comments · Fixed by #781

Comments

@reddwarf69
Copy link
reddwarf69 commented Apr 28, 2023

Describe the bug
Fails to work if source directory is read only.

Given the following directory structure

bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main

I get this error

bash-5.2$ gcovr --xml coverage.xml -r src build
(ERROR) Trouble processing '/gcovr_test/build/main.gcda' with working directory '/gcovr_test/src'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended informations.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
(ERROR) Uncaught EXCEPTION
Traceback (most recent call last):
  File "/usr/bin/gcovr", line 33, in <module>
    sys.exit(load_entry_point('gcovr==6.0', 'console_scripts', 'gcovr')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 328, in main
    covdata = collect_coverage_from_gcov(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 380, in collect_coverage_from_gcov
    with Workers(
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 173, in __exit__
    self.wait()
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 387, in collect_coverage_from_gcov
    contexts = pool.wait()
               ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.

when src doesn't have write permissions.

Desktop:

  • OS: Fedora 38
  • GCC version 13.0.1 20230401 (Red Hat 13.0.1-0)
  • GCOVR version 6.0

Additional context
After running it with verbose, I can see the problem is that gcov is called from src. When running the gcov command by hand, I get

Could not open output file '<file>.cpp##cbf27be0b5f705b4af2ee29fcff338c1.gcov'

Making the source directory writable, makes the gcovr invocation work.

bash-5.2$ chmod +w src/
bash-5.2$ gcovr --xml coverage.xml -r src build
bash-5.2$
@reddwarf69
Copy link
Author
reddwarf69 commented Apr 28, 2023

In https://github.com/gcovr/gcovr/blob/master/gcovr/formats/gcov/read.py#L312 it says

    Finding a suitable working directory is tricky.
    The coverage files (gcda and gcno) are stored next to object (.o) files.
    However, gcov needs to also resolve the source file name.
    The relative source file paths in the coverage data
    are relative to the gcc working directory.
    Therefore, gcov must be invoked in the same directory as gcc.

But I don't think this is true if the program has been built with absolute paths.
See

bash-5.2$ find
.
./src
./src/main.c
./build
bash-5.2$ pushd build; gcc --coverage /gcovr_test/src/main.c -o main; ./main; popd
/gcovr_test/build /gcovr_test
/gcovr_test
bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$ gcov /gcovr_test/build/main.gcda --branch-counts --branch-probabilities --demangled-names --hash-filenames --object-directory /gcovr_test/build
File '/gcovr_test/src/main.c'
Lines executed:100.00% of 1
No branches
No calls
Creating 'main.c##f105fbf7a48467648adbd0cd61e29589.gcov'

Lines executed:100.00% of 1
bash-5.2$

@reddwarf69
Copy link
Author

gcov also has the "--stdout" option. I guess it could be used to run gcov from the source directory but write the .gcov files somewhere else?

@reddwarf69
Copy link
Author

With gcovr 5.0, in Fedora 37 it works... apparently because it uses, somehow, a temporary directory (/tmp/tmpaeroqqpv).

bash-5.2$ gcovr -v --xml coverage.xml -r src build
Filters for --root: (1)
- re.compile('^/gcovr_test/src/')
Filters for --filter: (1)
- DirectoryPrefixFilter(/gcovr_test/src/)
Filters for --exclude: (0)
Filters for --gcov-filter: (1)
- AlwaysMatchFilter()
Filters for --gcov-exclude: (0)
Filters for --exclude-directories: (0)
Scanning directory build for gcda/gcno files...
Found 2 files (and will process 1)
Pool started with 1 threads
Processing file: /gcovr_test/build/main.gcda
Running gcov: 'gcov /gcovr_test/build/main.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /gcovr_test/build' in '/tmp/tmpaeroqqpv'
Finding source file corresponding to a gcov data file
  currdir      /gcovr_test
  gcov_fname   /tmp/tmpaeroqqpv/#gcovr_test#src#main.c.gcov
               ['        -', '    0', 'Source', '/gcovr_test/src/main.c\n']
  source_fname /gcovr_test/build/main.gcda
  root         /gcovr_test/src
  fname        /gcovr_test/src/main.c
Parsing coverage data for file /gcovr_test/src/main.c
Gathered coveraged data for 1 files

With gcovr 6.0, the problem also seems to be that it's not invoked in the same directory as gcc as the source code comment recommends.

In

bash-5.2$ find
.
./src
./src/main.c
./build
bash-5.2$ pushd build; gcc --coverage /gcovr_test/src/main.c -o main; ./main; popd
/gcovr_test/build /gcovr_test
/gcovr_test
bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$ gcovr -v --xml coverage.xml -r src build
(DEBUG) File system is case sensitive.
(DEBUG) Filters for --root: (1)
(DEBUG)  - re.compile('^/gcovr_test/src/')
(DEBUG) Filters for --filter: (1)
(DEBUG)  - DirectoryPrefixFilter(/gcovr_test/src/)
(DEBUG) Filters for --exclude: (0)
(DEBUG) Filters for --gcov-filter: (1)
(DEBUG)  - AlwaysMatchFilter()
(DEBUG) Filters for --gcov-exclude: (0)
(DEBUG) Filters for --exclude-directories: (0)
(DEBUG) Scanning directory build for gcda/gcno files...
(DEBUG) Found 2 files (and will process 1)
(DEBUG) Pool started with 1 threads
(DEBUG) Processing file: /gcovr_test/build/main.gcda
(DEBUG) Running gcov: 'gcov --help' in '.'
(DEBUG) Running gcov: 'gcov --help-hidden' in '.'
(DEBUG) Running gcov: 'gcov /gcovr_test/build/main.gcda --branch-counts --branch-probabilities --demangled-names --hash-filenames --object-directory /gcovr_test/build' in '/gcovr_test/src'
(DEBUG) Finding source file corresponding to a gcov data file
  gcov_fname   /gcovr_test/src/main.c##f105fbf7a48467648adbd0cd61e29589.gcov
  currdir      /gcovr_test
  root         /gcovr_test/src
  starting_dir /gcovr_test
  obj_dir      None
  gcda_fname   /gcovr_test/build/main.gcda
  --> fname    /gcovr_test/src/main.c
(DEBUG) Parsing coverage data for file /gcovr_test/src/main.c
(DEBUG) Gathered coveraged data for 1 files
bash-5.2$

gcc runs in build, but gcov in src. Had it run in build, it would have been more likely to be writable.

@Spacetown
Copy link
Member

But I don't think this is true if the program has been built with absolute paths.
See

Even if you use absolute paths for calling the compiler the files referenced in *.gcov are relative. You can check the created file main.c##f105fbf7a48467648adbd0cd61e29589.gcov.

With gcovr 5.0, in Fedora 37 it works... apparently because it uses, somehow, a temporary directory (/tmp/tmpaeroqqpv).

There is a heuristic to get the correct working directory for running gcovr. The temporary directory was removed in version 5.1 with #525 because there was always a Source not found error from gcov.

Can you try to run gcovr in the build directory and remove the option -r .. instead of -r src?

gcov also has the "--stdout" option. I guess it could be used to run gcov from the source directory but write the .gcov files somewhere else?

This option was introduced 2018 so it's not available in older versions of gcov and it's not usable for the newer json intermediate format.

@reddwarf69
Copy link
Author

But I don't think this is true if the program has been built with absolute paths.
See

Even if you use absolute paths for calling the compiler the files referenced in *.gcov are relative. You can check the created file main.c##f105fbf7a48467648adbd0cd61e29589.gcov.

I guess it may depend on the version, but

bash-5.2$ find
.
./src
./src/main.c
./build
bash-5.2$ pushd build; gcc --coverage /gcovr_test/src/main.c -o main; ./main; popd
/gcovr_test/build /gcovr_test
/gcovr_test
bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$ gcov /gcovr_test/build/main.gcda --branch-counts --branch-probabilities --demangled-names --hash-filenames --object-directory /gcovr_test/build
File '/gcovr_test/src/main.c'
File '/gcovr_test/src/main.c'
Lines executed:100.00% of 1
No branches
No calls
Creating 'main.c##f105fbf7a48467648adbd0cd61e29589.gcov'

Lines executed:100.00% of 1
bash: File: command not found
bash-5.2$ cat main.c##f105fbf7a48467648adbd0cd61e29589.gcov 
        -:    0:Source:/gcovr_test/src/main.c
        -:    0:Graph:/gcovr_test/build/main.gcno
        -:    0:Data:/gcovr_test/build/main.gcda
        -:    0:Runs:1
function main called 1 returned 100% blocks executed 100%
        1:    1:int main(){}
bash-5.2$

Even when using gcovr

bash-5.2$ find
.
./src
./src/main.c
./build
bash-5.2$ pushd build; gcc --coverage /gcovr_test/src/main.c -o main; ./main; popd
/gcovr_test/build /gcovr_test
/gcovr_test
bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$ gcovr --xml /gcovr_test/coverage.xml -r /gcovr_test/src /gcovr_test/build -k
bash-5.2$ cat src/main.gcda.main.c##f105fbf7a48467648adbd0cd61e29589.gcov 
        -:    0:Source:/gcovr_test/src/main.c
        -:    0:Graph:/gcovr_test/build/main.gcno
        -:    0:Data:/gcovr_test/build/main.gcda
        -:    0:Runs:1
function main called 1 returned 100% blocks executed 100%
        1:    1:int main(){}
bash-5.2$

Can you try to run gcovr in the build directory and remove the option -r .. instead of -r src?

With -r .., in the build directory, it seems to work.

bash-5.2$ find /gcovr_test/
/gcovr_test/
/gcovr_test/src
/gcovr_test/src/main.c
/gcovr_test/build
/gcovr_test/build/main.gcno
/gcovr_test/build/main.gcda
/gcovr_test/build/main
bash-5.2$ pwd
/gcovr_test/build
bash-5.2$ gcovr --xml /gcovr_test/coverage.xml -r /gcovr_test/src /gcovr_test/build
(ERROR) Trouble processing '/gcovr_test/build/main.gcda' with working directory '/gcovr_test/src'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended informations.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
(ERROR) Uncaught EXCEPTION
Traceback (most recent call last):
  File "/usr/bin/gcovr", line 33, in <module>
    sys.exit(load_entry_point('gcovr==6.0', 'console_scripts', 'gcovr')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 328, in main
    covdata = collect_coverage_from_gcov(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 380, in collect_coverage_from_gcov
    with Workers(
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 173, in __exit__
    self.wait()
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 387, in collect_coverage_from_gcov
    contexts = pool.wait()
               ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
bash-5.2$ gcovr --xml /gcovr_test/coverage.xml -r ../src /gcovr_test/build
(ERROR) Trouble processing '/gcovr_test/build/main.gcda' with working directory '/gcovr_test/src'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended informations.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
(ERROR) Uncaught EXCEPTION
Traceback (most recent call last):
  File "/usr/bin/gcovr", line 33, in <module>
    sys.exit(load_entry_point('gcovr==6.0', 'console_scripts', 'gcovr')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 328, in main
    covdata = collect_coverage_from_gcov(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 380, in collect_coverage_from_gcov
    with Workers(
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 173, in __exit__
    self.wait()
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/__main__.py", line 387, in collect_coverage_from_gcov
    contexts = pool.wait()
               ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 164, in wait
    raise self.exceptions[0][1]
  File "/usr/lib/python3.11/site-packages/gcovr/workers.py", line 80, in worker
    work(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 323, in process_datafile
    done = run_gcov_and_process_files(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
    out, err = gcov_cmd.run_with_args(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gcovr/gcov.py", line 519, in run_with_args
    raise RuntimeError(f"GCOV returncode was {gcov_process.returncode}.")
RuntimeError: GCOV returncode was 6.
bash-5.2$ gcovr --xml /gcovr_test/coverage.xml -r .. /gcovr_test/build
bash-5.2$ gcovr --xml /gcovr_test/coverage.xml -r .. /gcovr_test/build -k
bash-5.2$ find /gcovr_test/
/gcovr_test/
/gcovr_test/src
/gcovr_test/src/main.c
/gcovr_test/main.gcda.main.c##f105fbf7a48467648adbd0cd61e29589.gcov
/gcovr_test/coverage.xml
/gcovr_test/build
/gcovr_test/build/main.gcno
/gcovr_test/build/main.gcda
/gcovr_test/build/main
bash-5.2$

As does not using any -r at all from the same directory as before.

bash-5.2$ find
.
./src
./src/main.c
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$ gcovr -k --xml /gcovr_test/coverage.xml /gcovr_test/build   
bash-5.2$ find
.
./src
./src/main.c
./main.gcda.main.c##f105fbf7a48467648adbd0cd61e29589.gcov
./coverage.xml
./build
./build/main.gcno
./build/main.gcda
./build/main
bash-5.2$

Naturally, the output is different, though (has "src" in the path)

bash-5.2$ xmllint --format /gcovr_test/coverage.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="1.0" branch-rate="0.0" lines-covered="1" lines-valid="1" branches-covered="
8000
0" branches-valid="0" complexity="0.0" timestamp="1682832073" version="gcovr 6.0">
  <sources>
    <source>..</source>
  </sources>
  <packages>
    <package name="src" line-rate="1.0" branch-rate="0.0" complexity="0.0">
      <classes>
        <class name="main_c" filename="src/main.c" line-rate="1.0" branch-rate="0.0" complexity="0.0">
          <methods/>
          <lines>
            <line number="1" hits="1" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

vs

bash-5.2$ xmllint --format /gcovr_test/coverage.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="1.0" branch-rate="0.0" lines-covered="1" lines-valid="1" branches-covered="0" branches-valid="0" complexity="0.0" timestamp="1682832124" version="gcovr 6.0">
  <sources>
    <source>src</source>
  </sources>
  <packages>
    <package name="" line-rate="1.0" branch-rate="0.0" complexity="0.0">
      <classes>
        <class name="main_c" filename="main.c" line-rate="1.0" branch-rate="0.0" complexity="0.0">
          <methods/>
          <lines>
            <line number="1" hits="1" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

@Spacetown
Copy link
Member

The root directory is used for running gcov if no object directory is given. With following command you should be able to run gcovr without using the src directory as working directory to execute gcov:

gcovr --xml /gcovr_test/coverage.xml -r /gcovr_test/src --object-directory /gcovr_test/build /gcovr_test/build

@Spacetown
Copy link
Member

I played a little bit yesterday, with gcc-11 the behavior is as expected, we grep the error message in the output of gcov and try the next directory. But gcc-mirror/gcc@815f15d introduced proper exit codes and is released first with gcc-12.

I'll first extend our test matrix with gcc-13 or gcc-12 and then I'll fix this problem. For now the workaround from the last comment is the only thing I can do for you.

@reddwarf69
Copy link
Author

For now the workaround from the last comment is the only thing I can do for you.

It works for me!

@Spacetown
Copy link
Member

@reddwarf69 Can you test the branch from #781 with your old command line?

@Thallamsaisowmya23
Copy link

(ERROR) Error occurred while reading reports:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr_main_.py", line 389, in main
covdata: CovData = gcovr_formats.read_reports(options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats_init_.py", line 68, in read_reports
covdata = GcovHandler(options).read_report()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov_init_.py", line 202, in read_report
return read_report(self.options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\read.py", line 79, in read_report
with Workers(
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\workers.py", line 173, in exit
self.wait()
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\workers.py", line 164, in wait
raise self.exceptions[0][1]
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\read.py", line 86, in read_report
contexts = pool.wait()
^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\workers.py", line 164, in wait
raise self.exceptions[0][1]
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\workers.py", line 80, in worker
work(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\gcovr\formats\gcov\read.py", line 450, in process_datafile
raise RuntimeError(errors_output)
RuntimeError: GCOV produced the following errors processing F:\add\add.gcda:
Trouble processing 'F:/add/add.gcda' with working directory 'F:\add'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
Trouble processing 'F:/add/add.gcda' with working directory 'F:/add'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
Trouble processing 'F:/add/add.gcda' with working directory 'F:/'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
(gcovr could not infer a working directory that resolved it.)
To ignore this error use option --gcov-ignore-errors=no_working_dir_found.

GCOV produced the following errors processing F:\add\add.gcda:
Trouble processing 'F:/add/add.gcda' with working directory 'F:\add'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
Trouble processing 'F:/add/add.gcda' with working directory 'F:/add'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
Trouble processing 'F:/add/add.gcda' with working directory 'F:/'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Exception was >>[WinError 2] The system cannot find the file specified<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended information.
(gcovr could not infer a working directory that resolved it.)
To ignore this error use option --gcov-ignore-errors=no_working_dir_found.

@Spacetown
Copy link
Member

Posting the same log in 3 closed issues without any information doesn't help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0