Skip to content

Commit

Permalink
Log package hash inputs file and contents / regression test for #6906 (
Browse files Browse the repository at this point in the history
…#7759)

* Debug package hash inputs

* Add test skeleton for #6906

* Improve output of hash inputs

* Add tests over pks hash inputs

* Correct typos and formatting

* Add missing do

* Add missing cabal result arg

* Make consistent log about hash.txt

* Update log msg creating file

* Change var name to hashFileName
  • Loading branch information
jneira authored Oct 18, 2021
1 parent 5066f7f commit 980a532
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cabal-install/src/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Lazy.Char8 as LBS.Char8

import Control.Exception (Handler (..), SomeAsyncException, assert, catches, handle)
import System.Directory (canonicalizePath, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, removeFile, renameDirectory)
Expand Down Expand Up @@ -1016,9 +1017,18 @@ buildAndInstallUnpackedPackage verbosity
-- https://github.com/haskell/cabal/issues/4130
createDirectoryIfMissingVerbose verbosity True entryDir

LBS.writeFile
(entryDir </> "cabal-hash.txt")
(renderPackageHashInputs (packageHashInputs pkgshared pkg))
let hashFileName = entryDir </> "cabal-hash.txt"
outPkgHashInputs = renderPackageHashInputs (packageHashInputs pkgshared pkg)

info verbosity $
"creating file with the inputs used to compute the package hash: " ++ hashFileName

LBS.writeFile hashFileName outPkgHashInputs

debug verbosity "Package hash inputs:"
traverse_
(debug verbosity . ("> " ++))
(lines $ LBS.Char8.unpack outPkgHashInputs)

-- Ensure that there are no files in `tmpDir`, that are
-- not in `entryDir`. While this breaks the
Expand Down
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6906/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extra-include-dirs: foo
extra-lib-dirs: bar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6906/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

main = cabalTest $ do
res <- cabalG' ["--config=cabal.config"] "v2-install" ["-v3"]
assertOutputContains "creating file with the inputs used to compute the package hash:" res
assertOutputContains "extra-lib-dirs: bar" res
expectBroken 6906 $ assertOutputDoesNotContain "extra-lib-dirs: bar bar" res
assertOutputContains "extra-include-dirs: foo" res
expectBroken 6906 $ assertOutputDoesNotContain "extra-include-dirs: foo foo" res
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6906/issue6906.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cabal-version: 3.0
name: issue6906
version: 0
synopsis: No duplicate entries for extra-*-dirs config options in the inputs used to compute the package hash
description: When informed in the global config
author: Javier Neira
category: Tests
maintainer: [email protected]

executable issue6906
build-depends: base
main-is: main.hs
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/Regression/T6906/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "Hello issue6906"

0 comments on commit 980a532

Please sign in to comment.