Un-ignore .bat files
[cabal.git] / cabal-testsuite / PackageTests / LinkerOptions / NonignoredConfigs / cabal.test.hs
blob8e7c8a6391db87765b1869a390449a916b6bc0ac
1 import Test.Cabal.Prelude
2 import Distribution.Simple.Utils
4 -- This test ensures the following fix holds:
5 -- > Fix project-local build flags being ignored.
6 -- >
7 -- > I noticed that running ‘cabal install’ with two separate sets of dynamic /
8 -- > static build flags (e.g. one with none, and one with ‘--enable-shared
9 -- > --enable-executable-dynamic --disable-library-vanilla’) produced packages with
10 -- > the same hash, instead of different hashes.
11 -- >
12 -- > After debugging this issue I found that this command (with no explicit cabal
13 -- > project file) was resulting in these build configuration flags being ignored,
14 -- > because in ProjectPlanning.hs, the sdist was not considered a local package, so
15 -- > the (non-shared) local-package-only configuration was being dropped.
16 -- >
17 -- > This fix ensures that these command-line arguments properly make it through to
18 -- > where they belong in cases like this.
20 -- Basically, take a simple package, build it under two sets of build flags:
21 -- > (nothing)
22 -- > --enable-shared --enable-executable-dynamic --disable-library-vanilla
24 -- And ensure that whereas before they produced the same hash, now the package
25 -- hashes produced are different. (And also supplementarily ensure that
26 -- re-running the same build with the same flags a second time produces a
27 -- deterministic hash too; the hash should differ only when we change these
28 -- flags.)
30 -- Based on the UniqueIPID test.
32 import Control.Monad (forM, foldM_)
33 import Data.List (isPrefixOf, tails)
35 data Linking = Static | Dynamic deriving (Eq, Ord, Show)
37 links :: [Linking]
38 links = [Static, Dynamic]
40 linkConfigFlags :: Linking -> [String]
41 linkConfigFlags Static =
44 linkConfigFlags Dynamic =
46 "--enable-shared",
47 "--enable-executable-dynamic",
48 "--disable-library-vanilla"
51 lrun :: [Linking]
52 lrun = [Static, Dynamic, Static, Dynamic]
54 main = cabalTest $ do
55 -- Skip if on Windows, since my default Chocolatey Windows setup (and the CI
56 -- server setup at the time, presumably) lacks support for dynamic builds
57 -- since the base package appears to be static only, lacking e.g. ‘.dyn_o’
58 -- files. Normal Windows installations would need support for dynamic
59 -- builds, or else this test would fail when it tries to build with the
60 -- dynamic flags.
61 skipIfWindows
63 env <- getTestEnv
64 withPackageDb $ do
65 -- Phase 1: get 4 hashes according to config flags.
66 results <- forM (zip [0..] lrun) $ \(idx, linking) -> do
67 liftIO $ copyDirectoryRecursive minBound (testCurrentDir env </> "basic") (testCurrentDir env </> "basic" ++ show idx)
68 withDirectory ("basic" ++ show idx) $ do
69 packageEnv <- (</> ("basic" ++ show idx ++ ".env")) . testWorkDir <$> getTestEnv
70 let installOptions = ["--disable-deterministic", "--lib", "--package-env=" ++ packageEnv] ++ linkConfigFlags linking ++ ["basic"]
71 recordMode RecordMarked $ do
72 recordHeader $ "install options:" : installOptions
73 cabal "v2-install" installOptions
74 recordHeader $ "install options:" : installOptions
75 fails $ cabal "v2-install" installOptions
76 recordHeader $ "install options:" : "--force-reinstalls" : installOptions
77 cabal "v2-install" $ "--force-reinstalls" : installOptions
78 let exIPID s = takeWhile (/= '\n') . head . filter (\t -> any (`isPrefixOf` t) ["basic-0.1-", "bsc-0.1-"]) $ tails s
79 hashedIpid <- exIPID <$> liftIO (readFile packageEnv)
80 return $ ((idx, linking), hashedIpid)
81 -- Phase 2: make sure we have different hashes iff we have different config flags.
82 -- In particular make sure the dynamic config flags weren't silently
83 -- dropped and ignored, since this is the bug that prompted this test.
84 (\step -> foldM_ step (const $ return ()) results) $ \acc x -> do
85 acc x
86 return $ \future -> acc future >> do
87 let
88 ((thisIdx, thisLinking), thisHashedIpid) = x
89 ((futureIdx, futureLinking), futureHashedIpid) = future
90 when ((thisHashedIpid == futureHashedIpid) /= (thisLinking == futureLinking)) $ do
91 assertFailure . unlines $
92 if thisLinking /= futureLinking
93 then
94 -- What we are primarily concerned with testing
95 -- here.
97 "Error: static and dynamic config flags produced an IPID with the same hash; were the dynamic flags silently dropped?",
98 "\thashed IPID: " ++ thisHashedIpid
100 else
101 -- Help test our test can also make equal
102 -- hashes.
104 "Error: config flags were equal, yet a different IPID hash was produced.",
105 "\thashed IPID 1 : " ++ thisHashedIpid,
106 "\thashed IPID 2 : " ++ futureHashedIpid,
107 "\tlinking flags : " ++ show thisLinking