From ee1393c4301e6d10da667ebcfd0f02479438e55f Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Mon, 15 Jan 2018 11:01:55 -0800 Subject: [PATCH] Build with lts-10.3. Needs to disable `-Werror` due to haskell/cabal#4739. (We could also work around it by changing the module structure.) --- src/Pier/Build/Components.hs | 27 ++++++++++++++------------- src/Pier/Build/Package.hs | 6 ++++-- src/Pier/Orphans.hs | 22 ++++++++++++++++++++-- stack.yaml | 4 ++-- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/Pier/Build/Components.hs b/src/Pier/Build/Components.hs index 49fd10f..0ad92f1 100644 --- a/src/Pier/Build/Components.hs +++ b/src/Pier/Build/Components.hs @@ -25,11 +25,11 @@ import Development.Shake.FilePath hiding (exe) import Distribution.ModuleName import Distribution.Simple.Build.Macros (generatePackageVersionMacros) import Distribution.Package -import Distribution.PackageDescription +import Distribution.PackageDescription hiding (libName) import qualified Distribution.InstalledPackageInfo as IP import Distribution.Text import Distribution.System (buildOS, OS(..)) -import Distribution.Version (Version(..)) +import Distribution.Version (Version, versionNumbers) import Distribution.Compiler import qualified Data.Set as Set import Data.Set (Set) @@ -253,7 +253,7 @@ buildExecutables p = getConfiguredPackage p >>= \case Left _ -> return Map.empty Right confd -> fmap Map.fromList - . mapM (\e -> (exeName e,) <$> buildExecutable confd e) + . mapM (\e -> (display $ exeName e,) <$> buildExecutable confd e) . filter (buildable . buildInfo) $ executables (confdDesc confd) @@ -263,7 +263,7 @@ buildExecutableNamed p e = getConfiguredPackage p >>= \case Left pid -> error $ "Built-in package " ++ display pid ++ " has no executables" Right confd - | Just exe <- find ((== e) . exeName) (executables $ confdDesc confd) + | Just exe <- find ((== e) . display . exeName) (executables $ confdDesc confd) -> buildExecutable confd exe | otherwise -> error $ "Package " ++ display (packageId confd) ++ " has no executable named " ++ e @@ -273,6 +273,7 @@ buildExecutable -> Executable -> Action BuiltExecutable buildExecutable confd exe = do + let name = display $ exeName exe let desc = confdDesc confd let packageSourceDir = confdSourceDir confd let bi = buildInfo exe @@ -281,7 +282,7 @@ buildExecutable confd exe = do conf <- askConfig let ghc = configGhc conf let outputPrefix = display (packageName $ package desc) - "exe" exeName exe + "exe" name let cIncludeDirs = transitiveIncludeDirs transDeps <> Set.map (packageSourceDir />) (Set.fromList $ ifNullDirs $ includeDirs bi) @@ -296,13 +297,13 @@ buildExecutable confd exe = do moduleBootFiles <- catMaybes <$> mapM findBootFile otherModuleFiles let cFiles = map (packageSourceDir />) $ cSources bi cIncludes <- collectCIncludes desc bi (packageSourceDir />) - bin <- runCommand (output $ exeName exe) + bin <- runCommand (output $ name) $ message (display (package desc) ++ ": building executable " - ++ exeName exe) + ++ name) <> inputList moduleBootFiles <> inputList cIncludes <> ghcCommand ghc deps bi confd - [ "-o", pathOut (exeName exe) + [ "-o", pathOut name , "-hidir", outputPrefix "hi" , "-odir", outputPrefix "o" , "-dynamic" @@ -459,8 +460,7 @@ genPathsModule m pkg datas = do [ "{-# LANGUAGE CPP #-}" , "module " ++ display m ++ " (getDataFileName, getDataDir, version) where" , "import Data.Version (Version(..))" - , "version :: Version" - , "version = Version " ++ show (versionBranch + , "version = Version " ++ show (versionNumbers $ pkgVersion pkg) ++ "" ++ " []" -- tags are deprecated @@ -495,7 +495,7 @@ search ghc bi cIncludeDirs m srcDir let yFile = srcDir /> toFilePath m <.> ext exists yFile let relOutput = toFilePath m <.> "hs" - happy <- lift $ buildExecutableNamed (PackageName "happy") "happy" + happy <- lift $ buildExecutableNamed (mkPackageName "happy") "happy" lift . runCommand (output relOutput) $ progExe happy ["-o", pathOut relOutput, pathIn yFile] @@ -521,7 +521,8 @@ search ghc bi cIncludeDirs m srcDir let xFile = srcDir /> toFilePath m <.> ext exists xFile let relOutput = toFilePath m <.> "hs" - alex <- lift $ buildExecutableNamed (PackageName "alex") "alex" + -- TODO: mkPackageName doesn't exist in older ones + alex <- lift $ buildExecutableNamed (mkPackageName "alex") "alex" lift . runCommand (output relOutput) $ progExe alex ["-o", pathOut relOutput, pathIn xFile] @@ -582,7 +583,7 @@ collectPlainDataFiles desc dir = do (dataFiles desc) cppVersion :: Version -> String -cppVersion v = case versionBranch v of +cppVersion v = case versionNumbers v of (v1:v2:_) -> show v1 ++ if v2 < 10 then '0':show v2 else show v2 _ -> error $ "cppVersion: " ++ display v diff --git a/src/Pier/Build/Package.hs b/src/Pier/Build/Package.hs index 2cc572a..136a4da 100644 --- a/src/Pier/Build/Package.hs +++ b/src/Pier/Build/Package.hs @@ -16,6 +16,7 @@ import Distribution.Version (withinRange) import Distribution.PackageDescription import Distribution.PackageDescription.Parse import Distribution.Compiler +import Distribution.Types.CondTree (CondBranch(..)) import Pier.Build.Stackage import Pier.Core.Command @@ -70,7 +71,7 @@ parseCabalFileInDir dir = do cabalFile <- findCabalFile dir cabalContents <- readArtifact cabalFile -- TODO: better error message when parse fails; and maybe warnings too? - case parsePackageDescription cabalContents of + case parseGenericPackageDescription cabalContents of ParseFailed err -> error $ show err ParseOk _ pkg -> return pkg @@ -106,7 +107,8 @@ resolve plan flags node = sconcat $ condTreeData node :| [ resolve plan flags t - | (cond,ifTrue,ifFalse) <- condTreeComponents node + | CondBranch cond ifTrue ifFalse + <- condTreeComponents node , Just t <- [if isTrue plan flags cond then Just ifTrue else ifFalse]] diff --git a/src/Pier/Orphans.hs b/src/Pier/Orphans.hs index 6448ff4..0776b6e 100644 --- a/src/Pier/Orphans.hs +++ b/src/Pier/Orphans.hs @@ -1,4 +1,5 @@ -- | All-purpose module for defining orphan instances. +{-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# OPTIONS_GHC -Wno-orphans #-} module Pier.Orphans () where @@ -11,6 +12,9 @@ import Distribution.PackageDescription import Distribution.Package import qualified Distribution.Text as Cabal +import Distribution.Version +import Distribution.Utils.ShortText + instance Hashable a => Hashable (Set.Set a) where hashWithSalt k = hashWithSalt k . Set.toList @@ -19,15 +23,29 @@ instance Hashable PackageId instance Hashable PackageName instance Hashable ComponentId instance Hashable UnitId +instance Hashable ShortText +instance Hashable Version + +instance FromJSON Version where + parseJSON = withText "Version" simpleParser + +instance FromJSONKey Version where + fromJSONKey = cabalKeyTextParser + +instance FromJSON PackageName where + parseJSON = withText "PackageName" simpleParser + +instance FromJSONKey PackageName where + fromJSONKey = cabalKeyTextParser instance FromJSON PackageIdentifier where parseJSON = withText "PackageIdentifier" simpleParser -deriving instance FromJSONKey PackageName - simpleParser :: Cabal.Text a => T.Text -> Parser a simpleParser t = case Cabal.simpleParse (T.unpack t) of Just v -> pure v Nothing -> fail $ "Unable to parse PackageIdentifier: " ++ show t +cabalKeyTextParser :: Cabal.Text a => FromJSONKeyFunction a +cabalKeyTextParser = FromJSONKeyTextParser simpleParser diff --git a/stack.yaml b/stack.yaml index 1b35a28..6af02b4 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,10 +1,10 @@ -resolver: lts-9.6 +resolver: lts-10.3 packages: - '.' ghc-options: - "$locals": -Wall -Werror + "$locals": -Wall extra-deps: - shake-0.16