git.iko.soy/typeable/cabal2nix
on master help sign in
Rename --compiler-id to --compiler and add --system.

These command line flags allow users to specify the target to use when finalizing the Cabal file.

commit7cd23f86579fd934fafa3278a9f1d08c9e2a731d authorPeter Simons <simons@cryp.to> dateMon 13 Jun 2016, 18:19 (10 years ago) parent81eccfb
1 file changed+20−10
cabal2nix/src/Main.hs+20−10
cabal2nix/src/Main.hs+20−10
@@ -7,23 +7,23 @@ import Control.Exception ( bracket )
77import Control.Lens
88import Data.Maybe ( fromMaybe )
99import qualified Data.Set as Set
10+import qualified Distribution.Compat.ReadP as P
1011import Distribution.Compiler
1112import Distribution.Nixpkgs.Fetch
1213import Distribution.Nixpkgs.Haskell
1314import Distribution.Nixpkgs.Haskell.FromCabal
15+import Distribution.Nixpkgs.Haskell.PackageSourceSpec
1416import Distribution.Nixpkgs.Meta
1517import Distribution.PackageDescription ( FlagName(..), FlagAssignment )
1618import Distribution.Simple.Utils ( lowercase )
1719import Distribution.System
18−import Distribution.Text ( display, simpleParse )
20+import Distribution.Text
1921import Language.Nix
2022import Options.Applicative
2123import Paths_cabal2nix ( version )
2224import System.IO ( hFlush, stdout, stderr )
2325import qualified Text.PrettyPrint.ANSI.Leijen as P2 hiding ( (<$>), (<>) )
2426import Text.PrettyPrint.HughesPJClass ( Doc, Pretty(..), text, vcat, hcat, semi )
25−-- import Text.Show.Pretty
26−import Distribution.Nixpkgs.Haskell.PackageSourceSpec
2727
2828data Options = Options
2929 { optSha256 :: Maybe String
@@ -41,7 +41,8 @@ data Options = Options
4141 , optHackageDb :: Maybe FilePath
4242 , optNixShellOutput :: Bool
4343 , optFlags :: [String]
44− , optCompilerId :: Maybe String
44+ , optCompiler :: CompilerId
45+ , optSystem :: Platform
4546 , optUrl :: String
4647 }
4748 deriving (Show)
@@ -63,9 +64,21 @@ options = Options
6364 <*> optional (strOption $ long "hackage-db" <> metavar "PATH" <> help "path to the local hackage db in tar format")
6465 <*> switch (long "shell" <> help "generate output suitable for nix-shell")
6566 <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
66− <*> optional (strOption $ long "compiler-id" <> help "Compiler identifier to use when evaluating cabal file")
67+ <*> option (readP parse) (long "compiler" <> help "compiler to use when evaluating the Cabal file" <> value buildCompilerId <> showDefaultWith display)
68+ <*> option (readP parsePlatform) (long "system" <> help "target system to use when evaluating the Cabal file" <> value buildPlatform <> showDefaultWith display)
6769 <*> strArgument (metavar "URI")
6870
71+readP :: P.ReadP a a -> ReadM a
72+readP p = eitherReader $ \s -> case [ r' | (r',"") <- P.readP_to_S p s ] of
73+ (r:_) -> Right r
74+ _ -> Left ("invalid value " ++ show s)
75+
76+parsePlatform :: P.ReadP r Platform
77+parsePlatform = do arch <- P.choice [P.string "i686" >> return I386, P.string "x86_64" >> return X86_64]
78+ _ <- P.char '-'
79+ os <- P.choice [P.string "linux" >> return Linux, P.string "darwin" >> return OSX]
80+ return (Platform arch os)
81+
6982pinfo :: ParserInfo Options
7083pinfo = info
7184 ( helper
@@ -100,14 +113,11 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
100113 pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256)
101114
102115 let
103− compilerId :: CompilerId
104− compilerId = fromMaybe buildCompilerId (optCompilerId >>= simpleParse)
105−
106116 deriv :: Derivation
107117 deriv = fromGenericPackageDescription (const True)
108118 (\i -> Just (binding # (i, path # [i])))
109− buildPlatform
110− (unknownCompilerInfo compilerId NoAbiTag)
119+ optSystem
120+ (unknownCompilerInfo optCompiler NoAbiTag)
111121 (readFlagList optFlags)
112122 []
113123 (pkgCabal pkg)