forked from ganeti/ganeti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Cabal to enforce dependency versions
This uses `cabal configure` to determine which exact dependency versions we are compiling against, and ensures that these versions are used by passing -package-id flags to GHC. The `cabal configure` step makes the build fail before compiling / type checking if the user tries to compile against a dependency version we don't support; before, this case led to type errors which were not clearly user errors. This fixes issue ganeti#988. The output of `cabal configure` is also used to generate MIN_VERSION_* macros. MIN_VERSION_* macros are the standard way to build CPP dependency switches in Haskell packages, and they replace our custom macros (like PARALLEL3 and NO_REGEX_PCRE) which had to be hand-built for each dependency. We can now query the version of any Haskell dependency without having to manually add a flag via autoconf. All ghc and hlint invocations were adjusted to take these macros into account. This change introduces a Haskell-build-time dependency on cabal-install (for `cabal configure`) and the Cabal API (for obtaining the configured dependency versions and generating the macros). Any cabal version since Debian Squeeze is supported. Note that our use of Cabal does not imply any downloading of dependencies at build time, hermetic builds are unaffected by this change. For developers we now require hlint >= 1.8.60, to make use of its --cpp-file option. However, hlint >= 1.9.12 is recommended since for hlint >= 1.8.58 && < 1.9.12 the --utf8 flag is non-functional (see ndmitchell/hlint#96); this can be worked though by using the equivalent `--encoding=UTF-8` flag.
- Loading branch information
Showing
5 changed files
with
141 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Main where | ||
|
||
import Control.Applicative | ||
import qualified Data.Set as Set | ||
import qualified Distribution.Simple.Build.Macros as Macros | ||
import Distribution.Simple.Configure (maybeGetPersistBuildConfig) | ||
import Distribution.Simple.LocalBuildInfo (externalPackageDeps) | ||
import Distribution.PackageDescription (packageDescription) | ||
import Distribution.PackageDescription.Parse (readPackageDescription) | ||
import Distribution.Text (display) | ||
import Distribution.Verbosity (normal) | ||
import System.Environment (getArgs) | ||
|
||
|
||
main :: IO () | ||
main = do | ||
-- Get paths from program arguments. | ||
(cabalPath, depsPath, macrosPath) <- do | ||
args <- getArgs | ||
case args of | ||
[c, d, m] -> return (c, d, m) | ||
_ -> error "Expected 3 arguments: cabalPath depsPath macrosPath" | ||
|
||
-- Read the cabal file. | ||
pkgDesc <- packageDescription <$> readPackageDescription normal cabalPath | ||
|
||
-- Read the setup-config. | ||
m'conf <- maybeGetPersistBuildConfig "dist" | ||
case m'conf of | ||
Nothing -> error "could not read dist/setup-config" | ||
Just conf -> do | ||
|
||
-- Write package dependencies. | ||
let deps = map (display . fst) $ externalPackageDeps conf | ||
writeFile depsPath (unwords $ map ("-package-id " ++) deps) | ||
|
||
-- Write package MIN_VERSION_* macros. | ||
writeFile macrosPath $ Macros.generate pkgDesc conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters