eddyxu / cpp-coveralls

Upload gcov results to coveralls.io
Apache License 2.0
282 stars 74 forks source link

What is the meaning of the error or warning `cannot open source file`? And how do I solve it? #124

Open chrisbra opened 6 years ago

chrisbra commented 6 years ago

Hi, trying to get cpp-coveralls to work with Vim and the included subproject src/xxd

Currently it runs ~/.local/bin/coveralls -b ./src -x .xs -e ./src/if_perl.c --encodings utf-8 latin-1 EUC-KR (see the log)

This does not create coverage information for src/xxd/xxd.c and in fact it crashes with

Traceback (most recent call last):
  File "/home/travis/.local/bin/coveralls", line 11, in <module>
    sys.exit(run())
  File "/home/travis/.local/lib/python2.7/site-packages/cpp_coveralls/__init__.py", line 97, in run
    cov_report = coverage.collect(args)
  File "/home/travis/.local/lib/python2.7/site-packages/cpp_coveralls/coverage.py", line 447, in collect
    with io.open(source_file_path, mode='rb') as src_file:
IOError: [Errno 2] No such file or directory: './src/xxd.c'

I am testing locally to add the parameter -i src/xxd. This at least get's rid of the crash, but it still complains about Cannot open file xxd.c, which is clear, since it resides in src/xxd/ and not in src. So how do I fix it? Do I need to link it into the main src directory? Or is this not critical and coverage information will be correctly uploaded anyhow?

chrisosaurus commented 6 years ago

Can you please provide information on how you are compiling Vim and how you are generating your testing coverage output before you invoke coveralls.

I could try to pick it out of that travis log, but a minimum example would be much nicer as that is a lot of data to sift through.

Generally the path given to -b has to match the pwd for the compiler so all the paths line up.

From the log I can see

$ if [ "$COVERAGE" = "yes" ]; then ~/.local/bin/coveralls -b $SRCDIR -x .xs -e ${SRCDIR}/if_perl.c --encodings utf-8 latin-1 EUC-KR; fi
xxd.c: No such file or directory
File 'xxd.c'
Lines executed:59.22% of 385
xxd.c:creating 'xxd.c.gcov'

File 'fileio.c'
Lines executed:74.66% of 4064
fileio.c:creating 'fileio.c.gcov'

File 'evalfunc.c'
Lines executed:82.95% of 5655
evalfunc.c:creating 'evalfunc.c.gcov'

[...]

Traceback (most recent call last):
  File "/home/travis/.local/bin/coveralls", line 11, in <module>
    sys.exit(run())
  File "/home/travis/.local/lib/python2.7/site-packages/cpp_coveralls/__init__.py", line 97, in run
    cov_report = coverage.collect(args)
  File "/home/travis/.local/lib/python2.7/site-packages/cpp_coveralls/coverage.py", line 447, in collect
    with io.open(source_file_path, mode='rb') as src_file:
IOError: [Errno 2] No such file or directory: './src/xxd.c'

Very strange how it reports that is found fileio.c but was unable to find xxd.c (if I am reading this right)

In this case I wouldn't expect the coverage information to be uploaded, since coveralls is crashing, unless it happens to crash after the upload.

Later on I then see you invoking codecov which finds also finds fileio.c but also fails to find xxd.c

[0;90m==> Running gcov in /home/travis/build/vim/vim (disable via -X gcov)
xxd.c: No such file or directory
File 'xxd.c'
Lines executed:59.22% of 385
Branches executed:76.81% of 414
Taken at least once:51.21% of 414
No calls
xxd.c:creating 'xxd.c.gcov'

File 'fileio.c'
Lines executed:74.66% of 4064
Branches executed:82.73% of 3394
Taken at least once:65.26% of 3394
No calls
fileio.c:creating 'fileio.c.gcov'

[...]

This looks like a path problem to me, what happens if you run it without setting the -b in the same way, such as ~/.local/bin/coveralls -x .xs -e ./src/if_perl.c --encodings utf-8 latin-1 EUC-KR

chrisosaurus commented 6 years ago

I'm not able to reproduce this.

I have cloned vim, performed a make and make test, and I cannot get coveralls to complain.

I can also see that src/xxd/xxd.c is captured in the coverage report it generates.

$ git clone https://github.com/vim/vim.git
$ cd vim
$ make
$ make test
$ sudo pip install cpp-coveralls
$ coveralls -b src -e src/if_perl.c --dump HERE --encodings utf-8 latin-1 EUC-KR
$ grep 'src/xxd/xxd.c' -o HERE
src/xxd/xxd.c

I tested both of

$ coveralls -b src -e src/if_perl.c --dump HERE --encodings utf-8 latin-1 EUC-KR
$ coveralls -e src/if_perl.c --dump HERE --encodings utf-8 latin-1 EUC-KR

and neither produce an error.

If you are able to still make this happen please let me know the reproduction steps.

chrisbra commented 6 years ago

We tried several different ways to include xxd in the coverage process. Please see

Check the diff, for what has been actually done to try to include xxd coverage statistics.