Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ tests = testGroup "Distribution.Utils.Structured"
md5Check :: Structured a => Proxy a -> Integer -> Assertion
md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int

-- NB: if you need to update these values locally, you can run:
--
-- > cabal run Cabal-tests:unit-tests -- -p "/Structured/"

md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
md5CheckGenericPackageDescription proxy = md5Check proxy
0xfbca1c1f2a700fb3a174ec5346e86cbb

md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
md5CheckLocalBuildInfo proxy = md5Check proxy
0x3bf7bf1420847ce5fdaf6e36e33aecb2
0xd9542841ab7584d348aa142053fe934f
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ buildOptionsFromConfigFlags verbosity cfg comp = do
, exeCoverage = False
, libCoverage = False
, relocatable = fromFlagOrDefault False $ configRelocatable cfg
, programPrefix = flagToMaybe $ configProgPrefix cfg
, programSuffix = flagToMaybe $ configProgSuffix cfg
}

-- | Adjust 'LBC.BuildOptions' to be compatible with the given 'Compiler' and
Expand Down
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Types/LocalBuildConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ data BuildOptions = BuildOptions
-- ^ Whether to enable library program coverage
, relocatable :: Bool
-- ^ Whether to build a relocatable package
, programPrefix :: Maybe PathTemplate
-- ^ Installed executable prefix
, programSuffix :: Maybe PathTemplate
-- ^ Installed executable suffix
}
deriving (Eq, Generic, Read, Show)

Expand Down Expand Up @@ -229,4 +233,6 @@ buildOptionsConfigFlags (BuildOptions{..}) =
, configStripExes = toFlag stripExes
, configStripLibs = toFlag stripLibs
, configDebugInfo = toFlag withDebugInfo
, configProgPrefix = maybeToFlag programPrefix
, configProgSuffix = maybeToFlag programSuffix
}
19 changes: 15 additions & 4 deletions Cabal/src/Distribution/Types/LocalBuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Distribution.Types.LocalBuildInfo
, libCoverage
, extraCoverageFor
, relocatable
, programPrefix
, programSuffix
, ..
)

Expand Down Expand Up @@ -188,6 +190,8 @@ pattern LocalBuildInfo
-> Bool
-> [UnitId]
-> Bool
-> Maybe PathTemplate
-> Maybe PathTemplate
-> LocalBuildInfo
pattern LocalBuildInfo
{ configFlags
Expand Down Expand Up @@ -227,6 +231,8 @@ pattern LocalBuildInfo
, libCoverage
, extraCoverageFor
, relocatable
, programPrefix
, programSuffix
} =
NewLocalBuildInfo
{ localBuildDescr =
Expand Down Expand Up @@ -279,6 +285,8 @@ pattern LocalBuildInfo
, exeCoverage
, libCoverage
, relocatable
, programPrefix
, programSuffix
}
}
}
Expand Down Expand Up @@ -316,10 +324,13 @@ packageRoot cfg =
mbWorkDir = flagToMaybe $ setupWorkingDir cfg

progPrefix, progSuffix :: LocalBuildInfo -> PathTemplate
progPrefix (LocalBuildInfo{configFlags = cfg}) =
fromFlag $ configProgPrefix cfg
progSuffix (LocalBuildInfo{configFlags = cfg}) =
fromFlag $ configProgSuffix cfg
-- NB: make sure to read from 'BuildOptions' rather than the 'ConfigFlags'
-- stored in 'PackageBuildDescr', as the latter are the original command-line
-- input and are not updated by 'SetupHooks' configure hooks.
progPrefix (LocalBuildInfo{programPrefix = pfix}) =
fromMaybe (toPathTemplate "") pfix
progSuffix (LocalBuildInfo{programSuffix = sfix}) =
fromMaybe (toPathTemplate "") sfix

-- TODO: Get rid of these functions, as much as possible. They are
-- a bit useful in some cases, but you should be very careful!
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,8 @@ elaborateInstallPlan
, relocatable = perPkgOptionFlag pkgid False packageConfigRelocatable
, withProfLibDetail = elabProfExeDetail
, withProfExeDetail = elabProfLibDetail
, programPrefix = elabProgPrefix
, programSuffix = elabProgSuffix
}
okProfDyn = profilingDynamicSupportedOrUnknown compiler
profExe = perPkgOptionFlag pkgid False packageConfigProf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main where

import Distribution.Simple ( defaultMainWithSetupHooks )
import SetupHooks ( setupHooks )

main :: IO ()
main = defaultMainWithSetupHooks setupHooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module SetupHooks where

import Distribution.Simple.SetupHooks
import Distribution.Simple.InstallDirs ( toPathTemplate )
import Distribution.Types.LocalBuildConfig ( BuildOptions (..) )

setupHooks :: SetupHooks
setupHooks =
noSetupHooks
{ configureHooks =
noConfigureHooks
{ preConfPackageHook = Just preConfPkg }
}

preConfPkg :: PreConfPackageHook
preConfPkg inputs =
let outputs@PreConfPackageOutputs{buildOptions = opts} = noPreConfPackageOutputs inputs
in return outputs{buildOptions = opts{programPrefix = Just (toPathTemplate "pre-")}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.14
name: setup-hooks-prog-prefix
version: 0.1.0.0
license: BSD-3-Clause
build-type: Hooks

custom-setup
setup-depends: Cabal, Cabal-hooks, base

executable myexe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Test.Cabal.Prelude
import Distribution.System ( buildPlatform )
import Distribution.Simple.BuildPaths ( exeExtension )

-- Test that SetupHooks can set the programPrefix (#11168).
main = setupTest $ do
env <- getTestEnv
withPackageDb $ recordMode DoNotRecord $ do
setup "configure" []
setup "build" []
setup "copy" []
let binDir = testPrefixDir env </> "bin"
exeExt = exeExtension buildPlatform
shouldExist (binDir </> "pre-myexe" <.> exeExt)
shouldNotExist (binDir </> "myexe" <.> exeExt)
10 changes: 10 additions & 0 deletions changelog.d/hooks-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
synopsis: Add program prefix and suffix to `BuildOptions`
packages: [Cabal, Cabal-hooks]
prs: 11787
issues: 11168
---

Two new fields of `BuildOptions`, `programPrefix` and `programSuffix`, have
been added. This allows the installed executable program prefix and suffix to
be set by `SetupHooks` for packages with `build-type: Hooks`.
Loading