diff options
author | tv <tv@krebsco.de> | 2024-06-05 14:04:22 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2024-06-05 14:04:22 +0200 |
commit | 2ab1cf2c1941442418454ec57629a28e0c70b172 (patch) | |
tree | acb6a6a8fcf57806f859770275174fa64945c875 /pkgs | |
parent | d6c3807d20b448c3c41d440c7d1391d4cacd4b10 (diff) |
cabal-read: import from stockholm
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/simple/cabal-read.nix | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pkgs/simple/cabal-read.nix b/pkgs/simple/cabal-read.nix new file mode 100644 index 0000000..03b42ef --- /dev/null +++ b/pkgs/simple/cabal-read.nix @@ -0,0 +1,39 @@ +{ writeHaskellPackage }: + +# Because `sed -n 's/.*\<ghc-options:\s\+\(.*\)/\1/p'` is too simple. +writeHaskellPackage "cabal-read" { + executables.ghc-options = { + extra-depends = ["Cabal"]; + text = /* haskell */ '' + {-# LANGUAGE CPP #-} + module Main (main) where + import Data.List + import Data.Maybe + import Distribution.Compiler + import Distribution.PackageDescription.Parsec + import Distribution.Types.BuildInfo + import Distribution.Types.CondTree + import Distribution.Types.Executable + import Distribution.Types.GenericPackageDescription + import Distribution.Types.UnqualComponentName + import Distribution.Verbosity + import System.Environment + main :: IO () + main = do + [path, name] <- getArgs + + desc <- readGenericPackageDescription normal path + + case lookup (mkUnqualComponentName name) (condExecutables desc) of + Just exe -> + putStrLn . intercalate " " . fromMaybe [] . lookup GHC + #if MIN_VERSION_Cabal(3,0,0) + . perCompilerFlavorToList + #endif + . options . buildInfo . condTreeData $ exe + + Nothing -> + error ("executable " <> name <> " not found in " <> path) + ''; + }; +} |