killy971 / hpc-coveralls

coveralls.io support for haskell code coverage with hpc
http://hackage.haskell.org/package/hpc-coveralls
BSD 3-Clause "New" or "Revised" License
60 stars 20 forks source link

getMixPath returns an incorrect path in some cases with cabal 1.22 / ghc 7.10 #44

Closed killy971 closed 9 years ago

killy971 commented 9 years ago

Background analysis

Below is the current implementation of the getMixPath function, which computes a mix file path based on the hpc data directory, the test suite name, and the tix module:

getMixPath :: String -> String -> TixModule -> FilePath
getMixPath hpcDir testSuiteName tix = mixDir hpcDir ++ dirName ++ "/"
    where dirName = case span (/= '/') modName of
              (_, []) -> testSuiteName
              (packageId, _) -> packageId
          TixModule modName _ _ _ = tix

In some cases, this function doesn't return the correct path. For a concrete example, see this build output: https://travis-ci.org/guillaume-nargeot/hpc-coveralls/jobs/50498362 (throw away test branch hpc-data-dir-troubleshooting)

As a result of this build, the partial directory tree of the dist/hpc/vanilla/ folder is:

├── mix
│   ├── hpc-coveralls
│   │   └── Trace.Hpc.Coveralls.Util.mix
│   └── hpc-coveralls-0.8.4
│       └── hpcco_IlD5BmmDkZU34g6Jd9zefP
│           └── Trace.Hpc.Coveralls.Util.mix
└── tix
    ├── hpc-coveralls-0.8.4
    │   └── hpc-coveralls-0.8.4.tix
    └── test-all
        └── test-all.tix

In both hpc-coveralls-0.8.4.tix and test-all.tix, the modName value for the TraceHpcCoveralls.Util module is hpcco_IlD5BmmDkZU34g6Jd9zefP/Trace.Hpc.Coveralls.Util.

When building the same package with cabal 1.20 and ghc 7.8 (instead of cabal 1.22 and ghc 7.10), the hpcco_IlD5BmmDkZU34g6Jd9zefP bit found in the module name and directory structure is hpc-coveralls-0.8.4, which seems to be more correct.

This strange looking string is the reason why the getMixPath function fails, as it will produce the following path, which doesn't exist:

dist/hpc/vanilla/mix/hpcco_IlD5BmmDkZU34g6Jd9zefP/

The correct path should instead be:

dist/hpc/vanilla/mix/hpc-coveralls-0.8.4/

The fact that the referenced mix file paths have this additional indirection (two times the package name) is yet to be understood. A simpler package, such as this one, used for hpc-coveralls testing, doesn't seem to generate mix files in such a way (see this build), and therefore doesn't suffer from this issue.

Objective

Either find a way to better control hpc and where it outputs the tix/mix data files, or try to access the package name and pass it to the getMixPath function.

The package name can be parsed from the cabal file using Distribution.PackageDescription (distributed with cabal, so it should always be available). A new command line option may have to be introduced in order to specify the cabal file, or it could be found by inspecting the current folder.

Feature branch: read-cabal-file

zovt commented 9 years ago

I'm currently being affected by this issue. Has there been any progress?

killy971 commented 9 years ago

@zovt I'm working on it when I can find some time, and hope to fix it soon. Will keep you updated.

I've already implemented the module to read the package name-version.

killy971 commented 9 years ago

TODO: https://github.com/guillaume-nargeot/hpc-coveralls/commit/91924d159e77e24c77b39c23ff1e617d6c649ffb#commitcomment-12968500