diff --git a/src/Options/Applicative/Complicated.hs b/src/Options/Applicative/Complicated.hs index f6dc0b14fa..ecf94aa97a 100644 --- a/src/Options/Applicative/Complicated.hs +++ b/src/Options/Applicative/Complicated.hs @@ -44,7 +44,7 @@ complicatedOptions -> ExceptT b (Writer (Mod CommandFields (b,a))) () -- ^ commands (use 'addCommand') -> IO (a,b) -complicatedOptions numericVersion versionString numericHpackVersion h pd footerStr commonParser mOnFailure commandParser = +complicatedOptions numericVersion stringVersion numericHpackVersion h pd footerStr commonParser mOnFailure commandParser = do args <- getArgs (a,(b,c)) <- case execParserPure (prefs noBacktrack) parser args of Failure _ | null args -> withArgs ["--help"] (execParser parser) @@ -55,8 +55,8 @@ complicatedOptions numericVersion versionString numericHpackVersion h pd footerS where parser = info (helpOption <*> versionOptions <*> complicatedParser "COMMAND|FILE" commonParser commandParser) desc desc = fullDesc <> header h <> progDesc pd <> footer footerStr versionOptions = - case versionString of - Nothing -> versionOption (displayC numericVersion) + case stringVersion of + Nothing -> versionOption (versionString numericVersion) Just s -> versionOption s <*> numericVersionOption <*> numericHpackVersionOption versionOption s = infoOption @@ -65,7 +65,7 @@ complicatedOptions numericVersion versionString numericHpackVersion h pd footerS help "Show version") numericVersionOption = infoOption - (displayC numericVersion) + (versionString numericVersion) (long "numeric-version" <> help "Show only version number") numericHpackVersionOption = diff --git a/src/Stack/Build.hs b/src/Stack/Build.hs index 950b3ee8c3..40a8f88acb 100644 --- a/src/Stack/Build.hs +++ b/src/Stack/Build.hs @@ -155,7 +155,7 @@ checkCabalVersion = do when (allowNewer && cabalVer < $(mkVersion "1.22")) $ throwM $ CabalVersionException $ "Error: --allow-newer requires at least Cabal version 1.22, but version " ++ - displayC cabalVer ++ + versionString cabalVer ++ " was found." newtype CabalVersionException = CabalVersionException { unCabalVersionException :: String } @@ -176,7 +176,7 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do exesText pkgs = T.intercalate ", " - ["'" <> displayC p <> ":" <> exe <> "'" | p <- pkgs] + ["'" <> T.pack (packageNameString p) <> ":" <> exe <> "'" | p <- pkgs] (logWarn . display . T.unlines . concat) [ [ "Building " <> exe_s <> " " <> exesText toBuild <> "." ] , [ "Only one of them will be available via 'stack exec' or locally installed." @@ -389,7 +389,7 @@ rawBuildInfo = do ] where localToPair lp = - (displayC $ packageName p, value) + (T.pack $ packageNameString $ packageName p, value) where p = lpPackage lp value = object diff --git a/src/Stack/Build/Cache.hs b/src/Stack/Build/Cache.hs index bb43bfda27..e0773d755f 100644 --- a/src/Stack/Build/Cache.hs +++ b/src/Stack/Build/Cache.hs @@ -86,7 +86,7 @@ markExeInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow markExeInstalled loc ident = do dir <- exeInstalledDir loc ensureDir dir - ident' <- parseRelFile $ displayC ident + ident' <- parseRelFile $ packageIdentifierString ident let fp = toFilePath $ dir ident' -- Remove old install records for this package. -- TODO: This is a bit in-efficient. Put all this metadata into one file? @@ -103,7 +103,7 @@ markExeNotInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThr => InstallLocation -> PackageIdentifier -> m () markExeNotInstalled loc ident = do dir <- exeInstalledDir loc - ident' <- parseRelFile $ displayC ident + ident' <- parseRelFile $ packageIdentifierString ident liftIO $ ignoringAbsence (removeFile $ dir ident') buildCacheFile :: (HasEnvConfig env, MonadReader env m, MonadThrow m) @@ -185,7 +185,7 @@ flagCacheFile installed = do rel <- parseRelFile $ case installed of Library _ gid _ -> ghcPkgIdString gid - Executable ident -> displayC ident + Executable ident -> packageIdentifierString ident dir <- flagCacheLocal return $ dir rel @@ -257,7 +257,7 @@ precompiledCacheFile loc copts installedPackageIDs = do ec <- view envConfigL compiler <- view actualCompilerVersionL >>= parseRelDir . compilerVersionString - cabal <- view cabalVersionL >>= parseRelDir . displayC + cabal <- view cabalVersionL >>= parseRelDir . versionString -- The goal here is to come up with a string representing the -- package location which is unique. Luckily @TreeKey@s are exactly diff --git a/src/Stack/Build/ConstructPlan.hs b/src/Stack/Build/ConstructPlan.hs index 69725386cb..5efddb2d0a 100644 --- a/src/Stack/Build/ConstructPlan.hs +++ b/src/Stack/Build/ConstructPlan.hs @@ -315,7 +315,7 @@ mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap initialBuildSteps = = Just "Switching to snapshot installed package" -- Check if a dependency is going to be unregistered | (dep, _):_ <- mapMaybe (`Map.lookup` toUnregister) deps - = Just $ "Dependency being unregistered: " <> displayC dep + = Just $ "Dependency being unregistered: " <> T.pack (packageIdentifierString dep) -- None of the above, keep it! | otherwise = Nothing where @@ -539,7 +539,7 @@ installPackageGivenDeps isAllInOne ps package minstalled (missing, present, minL shouldInstall <- checkDirtiness ps installed package present (wanted ctx) return $ if shouldInstall then Nothing else Just installed (Just _, False) -> do - let t = T.intercalate ", " $ map (displayC . pkgName) (Set.toList missing) + let t = T.intercalate ", " $ map (T.pack . packageNameString . pkgName) (Set.toList missing) tell mempty { wDirty = Map.singleton name $ "missing dependencies: " <> addEllipsis t } return Nothing (Nothing, _) -> return Nothing @@ -643,9 +643,9 @@ addPackageDeps treatAsDep package = do [ "WARNING: Ignoring out of range dependency" , reason , ": " - , displayC $ PackageIdentifier depname (adrVersion adr) + , T.pack $ packageIdentifierString $ PackageIdentifier depname (adrVersion adr) , ". " - , displayC $ packageName package + , T.pack $ packageNameString $ packageName package , " requires: " , versionRangeText range ] @@ -865,7 +865,7 @@ toolWarningText (ToolWarning (ExeName toolName) pkgName) = "No packages found in snapshot which provide a " <> T.pack (show toolName) <> " executable, which is a build-tool dependency of " <> - displayC pkgName + T.pack (packageNameString pkgName) -- | Strip out anything from the @Plan@ intended for the local database stripLocals :: Plan -> Plan @@ -1005,7 +1005,7 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = pprintException (DependencyCycleDetected pNames) = Just $ flow "Dependency cycle detected in packages:" <> line <> - indent 4 (encloseSep "[" "]" "," (map (style Error . displayC) pNames)) + indent 4 (encloseSep "[" "]" "," (map (style Error . fromString . packageNameString) pNames)) pprintException (DependencyPlanFailures pkg pDeps) = case mapMaybe pprintDep (Map.toList pDeps) of [] -> Nothing @@ -1019,18 +1019,18 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = Just (target:path) -> line <> flow "needed due to" <+> encloseSep "" "" " -> " pathElems where pathElems = - [style Target . displayC $ target] ++ - map displayC path ++ + [style Target . fromString . packageIdentifierString $ target] ++ + map (fromString . packageIdentifierString) path ++ [pkgIdent] where - pkgName = style Current . displayC $ packageName pkg - pkgIdent = style Current . displayC $ packageIdentifier pkg + pkgName = style Current . fromString . packageNameString $ packageName pkg + pkgIdent = style Current . fromString . packageIdentifierString $ packageIdentifier pkg -- Skip these when they are redundant with 'NotInBuildPlan' info. pprintException (UnknownPackage name) | name `Set.member` allNotInBuildPlan = Nothing | name `Set.member` wiredInPackages = - Just $ flow "Can't build a package with same name as a wired-in-package:" <+> (style Current . displayC $ name) - | otherwise = Just $ flow "Unknown package:" <+> (style Current . displayC $ name) + Just $ flow "Can't build a package with same name as a wired-in-package:" <+> (style Current . fromString . packageNameString $ name) + | otherwise = Just $ flow "Unknown package:" <+> (style Current . fromString . packageNameString $ name) pprintFlags flags | Map.null flags = "" @@ -1040,7 +1040,7 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = pprintDep (name, (range, mlatestApplicable, badDep)) = case badDep of NotInBuildPlan -> Just $ - style Error (displayC name) <+> + style Error (fromString $ packageNameString name) <+> align ((if range == Cabal.anyVersion then flow "needed" else flow "must match" <+> goodRange) <> "," <> softline <> @@ -1048,7 +1048,7 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = latestApplicable Nothing) -- TODO: For local packages, suggest editing constraints DependencyMismatch version -> Just $ - (style Error . displayC) (PackageIdentifier name version) <+> + (style Error . fromString . packageIdentifierString) (PackageIdentifier name version) <+> align (flow "from stack configuration does not match" <+> goodRange <+> latestApplicable (Just version)) -- I think the main useful info is these explain why missing @@ -1056,11 +1056,11 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = -- path from a target to the package. Couldn'tResolveItsDependencies _version -> Nothing HasNoLibrary -> Just $ - style Error (displayC name) <+> + style Error (fromString $ packageNameString name) <+> align (flow "is a library dependency, but the package provides no library") BDDependencyCycleDetected names -> Just $ - style Error (displayC name) <+> - align (flow $ "dependency cycle detected: " ++ intercalate ", " (map displayC names)) + style Error (fromString $ packageNameString name) <+> + align (flow $ "dependency cycle detected: " ++ intercalate ", " (map packageNameString names)) where goodRange = style Good (fromString (Cabal.display range)) latestApplicable mversion = @@ -1073,7 +1073,7 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted = | Just laVer == mversion -> softline <> flow "(latest matching version is specified)" | otherwise -> softline <> - flow "(latest matching version is" <+> style Good (displayC laVer) <> ")" + flow "(latest matching version is" <+> style Good (fromString $ versionString laVer) <> ")" -- | Get the shortest reason for the package to be in the build plan. In -- other words, trace the parent dependencies back to a 'wanted' @@ -1126,14 +1126,14 @@ data DepsPath = DepsPath startDepsPath :: PackageIdentifier -> DepsPath startDepsPath ident = DepsPath { dpLength = 1 - , dpNameLength = T.length (displayC (pkgName ident)) + , dpNameLength = length (packageNameString (pkgName ident)) , dpPath = [ident] } extendDepsPath :: PackageIdentifier -> DepsPath -> DepsPath extendDepsPath ident dp = DepsPath { dpLength = dpLength dp + 1 - , dpNameLength = dpNameLength dp + T.length (displayC (pkgName ident)) + , dpNameLength = dpNameLength dp + length (packageNameString (pkgName ident)) , dpPath = [ident] } diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index f7416c5593..df1419854d 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -124,7 +124,7 @@ printPlan plan = do xs -> do logInfo "Would unregister locally:" forM_ xs $ \(ident, reason) -> logInfo $ - displayC ident <> + fromString (packageIdentifierString ident) <> if T.null reason then "" else " (" <> RIO.display reason <> ")" @@ -168,7 +168,7 @@ printPlan plan = do -- | For a dry run displayTask :: Task -> Utf8Builder displayTask task = - displayC (taskProvides task) <> + fromString (packageIdentifierString (taskProvides task)) <> ": database=" <> (case taskLocation task of Snap -> "snapshot" @@ -180,7 +180,7 @@ displayTask task = (if Set.null missing then "" else ", after: " <> - mconcat (intersperse "," (displayC <$> Set.toList missing))) + mconcat (intersperse "," (fromString . packageIdentifierString <$> Set.toList missing))) where missing = tcoMissing $ taskConfigOpts task @@ -250,7 +250,7 @@ getSetupExe setupHs setupShimHs tmpdir = do wc <- view $ actualCompilerVersionL.whichCompilerL platformDir <- platformGhcRelDir config <- view configL - cabalVersionString <- view $ cabalVersionL.to displayC + cabalVersionString <- view $ cabalVersionL.to versionString actualCompilerVersionString <- view $ actualCompilerVersionL.to compilerVersionString platform <- view platformL let baseNameS = concat @@ -597,7 +597,7 @@ executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do localDB <- packageDatabaseLocal forM_ ids $ \(id', (ident, reason)) -> do logInfo $ - displayC ident <> + fromString (packageIdentifierString ident) <> ": unregistering" <> if T.null reason then "" @@ -631,10 +631,10 @@ executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do run $ logStickyDone ("Completed " <> RIO.display total <> " action(s).") | otherwise = do inProgress <- readTVarIO actionsVar - let packageNames = map (\(ActionId pkgID _) -> displayC pkgID) (toList inProgress) + let packageNames = map (\(ActionId pkgID _) -> pkgName pkgID) (toList inProgress) nowBuilding :: [PackageName] -> Utf8Builder nowBuilding [] = "" - nowBuilding names = mconcat $ ": " : intersperse ", " (map displayC names) + nowBuilding names = mconcat $ ": " : intersperse ", " (map (fromString . packageNameString) names) when terminal $ run $ logSticky $ "Progress " <> RIO.display prev <> "/" <> RIO.display total <> @@ -872,7 +872,7 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = announceTask :: HasLogFunc env => Task -> Text -> RIO env () announceTask task x = logInfo $ - displayC (taskProvides task) <> + fromString (packageIdentifierString (taskProvides task)) <> ": " <> RIO.display x @@ -944,7 +944,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi case taskType of TTFilePath lp _ -> inner (lpPackage lp) (lpCabalFile lp) (parent $ lpCabalFile lp) TTRemote package _ pkgloc -> do - suffix <- parseRelDir $ displayC $ packageIdent package + suffix <- parseRelDir $ packageIdentifierString $ packageIdent package let dir = eeTempDir suffix unpackPackageLocation dir pkgloc @@ -963,14 +963,15 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi renameDir oldDist newDist let name = pkgName taskProvides - cabalfpRel <- parseRelFile $ displayC name ++ ".cabal" + cabalfpRel <- parseRelFile $ packageNameString name ++ ".cabal" let cabalfp = dir cabalfpRel inner package cabalfp dir withOutputType pkgDir package inner -- If the user requested interleaved output, dump to the console with a -- prefix. - | boptsInterleavedOutput eeBuildOpts = inner $ OTConsole $ displayC (packageName package) <> "> " + | boptsInterleavedOutput eeBuildOpts = + inner $ OTConsole $ fromString (packageNameString (packageName package)) <> "> " -- Not in interleaved mode. When building a single wanted package, dump -- to the console with no prefix. @@ -1025,7 +1026,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi -- https://github.com/commercialhaskell/stack/issues/1356 | packageName package == $(mkPackageName "Cabal") = [] | otherwise = - ["-package=" ++ displayC + ["-package=" ++ packageIdentifierString (PackageIdentifier cabalPackageName eeCabalPkgVer)] packageDBArgs = @@ -1044,7 +1045,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi (TTFilePath lp Local, C.Custom) | lpWanted lp -> do prettyWarnL [ flow "Package" - , displayC $ packageName package + , fromString $ packageNameString $ packageName package , flow "uses a custom Cabal build, but does not use a custom-setup stanza" ] _ -> return () @@ -1060,7 +1061,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi (Just customSetupDeps, _) -> do unless (Map.member $(mkPackageName "Cabal") customSetupDeps) $ prettyWarnL - [ displayC $ packageName package + [ fromString $ packageNameString $ packageName package , "has a setup-depends field, but it does not mention a Cabal dependency. This is likely to cause build errors." ] allDeps <- @@ -1076,11 +1077,11 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi case filter (matches . fst) (Map.toList allDeps) of x:xs -> do unless (null xs) - (logWarn ("Found multiple installed packages for custom-setup dep: " <> displayC name)) + (logWarn ("Found multiple installed packages for custom-setup dep: " <> fromString (packageNameString name))) return ("-package-id=" ++ ghcPkgIdString (snd x), Just (fst x)) [] -> do - logWarn ("Could not find custom-setup dep: " <> displayC name) - return ("-package=" ++ displayC name, Nothing) + logWarn ("Could not find custom-setup dep: " <> fromString (packageNameString name)) + return ("-package=" ++ packageNameString name, Nothing) let depsArgs = map fst matchedDeps -- Generate setup_macros.h and provide it to ghc let macroDeps = mapMaybe snd matchedDeps @@ -1342,8 +1343,8 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap TTFilePath lp _ -> packageInternalLibraries $ lpPackage lp TTRemote p _ _ -> packageInternalLibraries p PackageIdentifier name version = taskProvides - mainLibName = displayC name - mainLibVersion = displayC version + mainLibName = packageNameString name + mainLibVersion = versionString version pkgName = mainLibName ++ "-" ++ mainLibVersion -- z-package-z-internal for internal lib internal of package package toCabalInternalLibName n = concat ["z-", mainLibName, "-z-", n, "-", mainLibVersion] @@ -1401,7 +1402,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap executableBuildStatuses <- getExecutableBuildStatuses package pkgDir when (not (cabalIsSatisfied executableBuildStatuses) && taskIsTarget task) (logInfo - ("Building all executables for `" <> displayC (packageName package) <> + ("Building all executables for `" <> fromString (packageNameString (packageName package)) <> "' once. After a successful build of all of them, only specified executables will be rebuilt.")) _neededConfig <- ensureConfig cache pkgDir ee (announce ("configure" <> annSuffix executableBuildStatuses)) cabal cabalfp task @@ -1590,7 +1591,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap sublibsPkgIds <- fmap catMaybes $ forM (Set.toList $ packageInternalLibraries package) $ \sublib -> do -- z-haddock-library-z-attoparsec for internal lib attoparsec of haddock-library - let sublibName = T.concat ["z-", displayC $ packageName package, "-z-", sublib] + let sublibName = T.concat ["z-", T.pack $ packageNameString $ packageName package, "-z-", sublib] case parsePackageName $ T.unpack sublibName of Nothing -> return Nothing -- invalid lib, ignored Just subLibName -> loadInstalledPkg wc [installedPkgDb] installedDumpPkgsTVar subLibName @@ -1840,7 +1841,7 @@ singleTest topts testsToRun ac ee task installedMap = do logError $ displayShow $ TestSuiteExeMissing (packageBuildType package == C.Simple) exeName - (displayC (packageName package)) + (packageNameString (packageName package)) (T.unpack testName) return $ Map.singleton testName Nothing @@ -2012,7 +2013,7 @@ primaryComponentOptions executableBuildStatuses lp = NoLibraries -> [] HasLibraries names -> map T.unpack - $ T.append "lib:" (displayC (packageName package)) + $ T.append "lib:" (T.pack (packageNameString (packageName package))) : map (T.append "flib:") (Set.toList names)) ++ map (T.unpack . T.append "lib:") (Set.toList $ packageInternalLibraries package) ++ map (T.unpack . T.append "exe:") (Set.toList $ exesToBuild executableBuildStatuses lp) diff --git a/src/Stack/Build/Haddock.hs b/src/Stack/Build/Haddock.hs index c04f84375f..fc7e99e644 100644 --- a/src/Stack/Build/Haddock.hs +++ b/src/Stack/Build/Haddock.hs @@ -62,7 +62,7 @@ openHaddocksInBrowser bco pkgLocations buildTargets = do docFile <- case (cliTargets, map (`Map.lookup` pkgLocations) (Set.toList buildTargets)) of ([_], [Just (pkgId, iloc)]) -> do - pkgRelDir <- (parseRelDir . displayC) pkgId + pkgRelDir <- (parseRelDir . packageIdentifierString) pkgId let docLocation = case iloc of Snap -> snapDocDir bco @@ -234,8 +234,8 @@ generateHaddockIndex descr wc bco dumpPackages docRelFP destDir = do let (PackageIdentifier name _) = dpPackageIdent destInterfaceRelFP = docRelFP FP. - displayC dpPackageIdent FP. - (displayC name FP.<.> "haddock") + packageIdentifierString dpPackageIdent FP. + (packageNameString name FP.<.> "haddock") destInterfaceAbsFile <- parseCollapsedAbsFile (toFilePath destDir FP. destInterfaceRelFP) esrcInterfaceModTime <- tryGetModificationTime srcInterfaceAbsFile return $ @@ -245,7 +245,7 @@ generateHaddockIndex descr wc bco dumpPackages docRelFP destDir = do Just ( [ "-i" , concat - [ docRelFP FP. displayC dpPackageIdent + [ docRelFP FP. packageIdentifierString dpPackageIdent , "," , destInterfaceRelFP ]] , srcInterfaceModTime diff --git a/src/Stack/Build/Installed.hs b/src/Stack/Build/Installed.hs index c17b826961..9aab51f86d 100644 --- a/src/Stack/Build/Installed.hs +++ b/src/Stack/Build/Installed.hs @@ -171,16 +171,16 @@ processLoadResult _ True (WrongVersion actual wanted, lh) | fst (lhPair lh) `Set.member` ghcjsBootPackages = do logWarn $ "Ignoring that the GHCJS boot package \"" <> - displayC (fst (lhPair lh)) <> + fromString (packageNameString (fst (lhPair lh))) <> "\" has a different version, " <> - displayC actual <> + fromString (versionString actual) <> ", than the resolver's wanted version, " <> - displayC wanted + fromString (versionString wanted) return (Just lh) processLoadResult mdb _ (reason, lh) = do logDebug $ "Ignoring package " <> - displayC (fst (lhPair lh)) <> + fromString (packageNameString (fst (lhPair lh))) <> maybe mempty (\db -> ", from " <> displayShow db <> ",") mdb <> " due to" <> case reason of @@ -192,9 +192,9 @@ processLoadResult mdb _ (reason, lh) = do WrongLocation mloc loc -> " wrong location: " <> displayShow (mloc, loc) WrongVersion actual wanted -> " wanting version " <> - displayC wanted <> + fromString (versionString wanted) <> " instead of " <> - displayC actual + fromString (versionString actual) return Nothing data Allowed diff --git a/src/Stack/Build/Target.hs b/src/Stack/Build/Target.hs index 8b009f4f83..b26fceefb0 100644 --- a/src/Stack/Build/Target.hs +++ b/src/Stack/Build/Target.hs @@ -103,7 +103,7 @@ getRawInput boptscli locals = textTargets = -- Handle the no targets case, which means we pass in the names of all project packages if null textTargets' - then map displayC (Map.keys locals) + then map (T.pack . packageNameString) (Map.keys locals) else textTargets' in (textTargets', map RawInput textTargets) @@ -254,7 +254,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = ] go (RTPackageComponent name ucomp) = return $ case Map.lookup name locals of - Nothing -> Left $ T.pack $ "Unknown local package: " ++ displayC name + Nothing -> Left $ T.pack $ "Unknown local package: " ++ packageNameString name Just lpv -> case ucomp of ResolvedComponent comp @@ -269,7 +269,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = [ "Component " , show comp , " does not exist in package " - , displayC name + , packageNameString name ] UnresolvedComponent comp -> case filter (isCompNamed comp) $ Set.toList $ lpvComponents lpv of @@ -277,7 +277,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = [ "Component " , comp , " does not exist in package " - , displayC name + , T.pack $ packageNameString name ] [x] -> Right ResolveResult { rrName = name @@ -290,7 +290,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = [ "Ambiguous component name " , comp , " for package " - , displayC name + , T.pack $ packageNameString name , ": " , T.pack $ show matches ] @@ -343,7 +343,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = go (RTPackageIdentifier ident@(PackageIdentifier name version)) | Map.member name locals = return $ Left $ T.concat - [ tshow (displayC name :: String) + [ tshow (packageNameString name) , " target has a specific version number, but it is a local package." , "\nTo avoid confusion, we will not install the specified version or build the local one." , "\nTo build the local package, specify the target without an explicit version." @@ -369,7 +369,7 @@ resolveRawTarget globals snap deps locals (ri, rt) = -- index, so refuse to do the override Just loc' -> Left $ T.concat [ "Package with identifier was targeted on the command line: " - , displayC ident + , T.pack $ packageIdentifierString ident , ", but it was specified from a non-index location: " , T.pack $ show loc' , ".\nRecommendation: add the correctly desired version to extra-deps." @@ -432,7 +432,7 @@ combineResolveResults results = do | all isJust mcomps -> Right $ Map.singleton name $ TargetComps $ Set.fromList $ catMaybes mcomps | otherwise -> Left $ T.concat [ "The package " - , displayC name + , T.pack $ packageNameString name , " was specified in multiple, incompatible ways: " , T.unwords $ map (unRawInput . rrRaw) rrs ] diff --git a/src/Stack/BuildPlan.hs b/src/Stack/BuildPlan.hs index 7da91fbac0..b74888c9e6 100644 --- a/src/Stack/BuildPlan.hs +++ b/src/Stack/BuildPlan.hs @@ -86,20 +86,20 @@ instance Show BuildPlanException where [] -> [] noKnown -> [ "There are no known versions of the following packages:" - , intercalate ", " $ map displayC noKnown + , intercalate ", " $ map packageNameString noKnown ] ] where - go (dep, (_, users)) | Set.null users = displayC dep + go (dep, (_, users)) | Set.null users = packageNameString dep go (dep, (_, users)) = concat - [ displayC dep + [ packageNameString dep , " (used by " - , intercalate ", " $ map displayC $ Set.toList users + , intercalate ", " $ map packageNameString $ Set.toList users , ")" ] goRecommend (name, (Just version, _)) = - Just $ "- " ++ displayC (PackageIdentifier name version) + Just $ "- " ++ packageIdentifierString (PackageIdentifier name version) goRecommend (_, (Nothing, _)) = Nothing getNoKnown (name, (Nothing, _)) = Just name @@ -118,17 +118,17 @@ instance Show BuildPlanException where , ["Note: further dependencies may need to be added"] ] where - go (dep, users) | Set.null users = displayC dep ++ " (internal stack error: this should never be null)" + go (dep, users) | Set.null users = packageNameString dep ++ " (internal stack error: this should never be null)" go (dep, users) = concat - [ displayC dep + [ packageNameString dep , " (used by " , intercalate ", " - $ map (displayC . pkgName) + $ map (packageNameString . pkgName) $ Set.toList users , ")" ] - extraDeps = map (\ident -> "- " ++ displayC ident) + extraDeps = map (\ident -> "- " ++ packageIdentifierString ident) $ Set.toList $ Set.unions $ Map.elems shadowed @@ -427,7 +427,7 @@ showPackageFlags pkg fl = if not $ Map.null fl then T.concat [ " - " - , T.pack $ displayC pkg + , T.pack $ packageNameString pkg , ": " , T.pack $ intercalate ", " $ map formatFlags (Map.toList fl) @@ -438,7 +438,7 @@ showPackageFlags pkg fl = formatFlags (f, v) = show f ++ " = " ++ show v showMapPackages :: Map PackageName a -> Text -showMapPackages mp = showItems $ map displayC $ Map.keys mp +showMapPackages mp = showItems $ map packageNameString $ Map.keys mp showCompilerErrors :: Map PackageName (Map FlagName Bool) @@ -467,12 +467,12 @@ showDepErrors flags errs = ] showDepVersion depName mversion = T.concat - [ T.pack $ displayC depName + [ T.pack $ packageNameString depName , case mversion of Nothing -> " not found" Just version -> T.concat [ " version " - , T.pack $ displayC version + , T.pack $ versionString version , " found" ] , "\n" @@ -480,7 +480,7 @@ showDepErrors flags errs = showRequirement (user, range) = T.concat [ " - " - , T.pack $ displayC user + , T.pack $ packageNameString user , " requires " , T.pack $ display range , "\n" diff --git a/src/Stack/Config/Nix.hs b/src/Stack/Config/Nix.hs index 517cbc8d46..e58e88426b 100644 --- a/src/Stack/Config/Nix.hs +++ b/src/Stack/Config/Nix.hs @@ -55,7 +55,7 @@ nixCompiler :: WantedCompiler -> Either StringException T.Text nixCompiler compilerVersion = case compilerVersion of WCGhc version -> - case T.split (== '.') (displayC version) of + case T.split (== '.') (fromString $ versionString version) of x : y : minor -> Right $ case minor of @@ -70,7 +70,7 @@ nixCompiler compilerVersion = \(lib.attrNames haskell.compiler); in \ \if compilers == [] \ \then abort \"No compiler found for GHC " - <> displayC version <> "\"\ + <> T.pack (versionString version) <> "\"\ \else haskell.compiler.${builtins.head compilers})" _ -> "haskell.compiler.ghc" <> T.concat (x : y : minor) _ -> Left $ stringException "GHC major version not specified" diff --git a/src/Stack/Constants/Config.hs b/src/Stack/Constants/Config.hs index 299cb5ca75..c1ca27fcab 100644 --- a/src/Stack/Constants/Config.hs +++ b/src/Stack/Constants/Config.hs @@ -126,7 +126,7 @@ distRelativeDir = do envDir <- parseRelDir $ (if wc == Ghcjs then (++ "_ghcjs") else id) $ - displayC $ + packageIdentifierString $ PackageIdentifier cabalPackageName cabalPkgVer platformAndCabal <- useShaPathOnWindows (platform envDir) workDir <- view workDirL diff --git a/src/Stack/Coverage.hs b/src/Stack/Coverage.hs index 54b087066a..76c0ab0a6d 100644 --- a/src/Stack/Coverage.hs +++ b/src/Stack/Coverage.hs @@ -81,7 +81,7 @@ updateTixFile pkgName' tixSrc testName = do hpcPkgPath :: HasEnvConfig env => PackageName -> RIO env (Path Abs Dir) hpcPkgPath pkgName' = do outputDir <- hpcReportDir - pkgNameRel <- parseRelDir (displayC pkgName') + pkgNameRel <- parseRelDir (packageNameString pkgName') return (outputDir pkgNameRel) -- | Get the tix file location, given the name of the file (without extension), and the package @@ -100,8 +100,8 @@ generateHpcReport pkgDir package tests = do compilerVersion <- view actualCompilerVersionL -- If we're using > GHC 7.10, the hpc 'include' parameter must specify a ghc package key. See -- https://github.com/commercialhaskell/stack/issues/785 - let pkgName' = displayC (packageName package) - pkgId = displayC (packageIdentifier package) + let pkgName' = T.pack $ packageNameString (packageName package) + pkgId = packageIdentifierString (packageIdentifier package) ghcVersion = getGhcVersion compilerVersion hasLibrary = case packageLibraries package of @@ -234,7 +234,7 @@ generateHpcReportForTargets opts = do case target of TargetAll Dependency -> throwString $ "Error: Expected a local package, but " ++ - displayC name ++ + packageNameString name ++ " is either an extra-dep or in the snapshot." TargetComps comps -> do pkgPath <- hpcPkgPath name @@ -244,7 +244,7 @@ generateHpcReportForTargets opts = do liftM (pkgPath ) $ parseRelFile (T.unpack testName ++ "/" ++ T.unpack testName ++ ".tix") _ -> fail $ "Can't specify anything except test-suites as hpc report targets (" ++ - displayC name ++ + packageNameString name ++ " is used with a non test-suite target)" TargetAll ProjectPackage -> do pkgPath <- hpcPkgPath name @@ -432,7 +432,7 @@ findPackageFieldForBuiltPackage findPackageFieldForBuiltPackage pkgDir pkgId internalLibs field = do distDir <- distDirFromDir pkgDir let inplaceDir = distDir $(mkRelDir "package.conf.inplace") - pkgIdStr = displayC pkgId + pkgIdStr = packageIdentifierString pkgId notFoundErr = return $ Left $ "Failed to find package key for " <> T.pack pkgIdStr extractField path = do contents <- liftIO $ T.readFile (toFilePath path) diff --git a/src/Stack/Dot.hs b/src/Stack/Dot.hs index b5fe391042..9d9936697c 100644 --- a/src/Stack/Dot.hs +++ b/src/Stack/Dot.hs @@ -141,7 +141,7 @@ listDependencies opts = do if listDepsLicense opts then maybe "" (Text.pack . display . either licenseFromSPDX id) (payloadLicense payload) else maybe "" (Text.pack . show) (payloadVersion payload) - line = displayC name <> listDepsSep opts <> payloadText + line = Text.pack (packageNameString name) <> listDepsSep opts <> payloadText in liftIO $ Text.putStrLn line -- | @pruneGraph dontPrune toPrune graph@ prunes all packages in @@ -217,7 +217,7 @@ createDepLoader sourceMap installed globalDumpMap globalIdMap loadPackageDeps pk Nothing -> pure (Set.empty, payloadFromInstalled (Map.lookup pkgName installed)) -- For wired-in-packages, use information from ghc-pkg (see #3084) else case Map.lookup pkgName globalDumpMap of - Nothing -> error ("Invariant violated: Expected to find wired-in-package " ++ displayC pkgName ++ " in global DB") + Nothing -> error ("Invariant violated: Expected to find wired-in-package " ++ packageNameString pkgName ++ " in global DB") Just dp -> pure (Set.fromList deps, payloadFromDump dp) where deps = map (\depId -> maybe (error ("Invariant violated: Expected to find " ++ ghcPkgIdString depId ++ " in global DB")) @@ -258,7 +258,7 @@ printGraph dotOpts locals graph = do void (Map.traverseWithKey printEdges (fst <$> graph)) liftIO $ Text.putStrLn "}" where filteredLocals = Set.filter (\local' -> - displayC local' `Set.notMember` dotPrune dotOpts) locals + packageNameString local' `Set.notMember` dotPrune dotOpts) locals -- | Print the local nodes with a different style depending on options printLocalNodes :: (F.Foldable t, MonadIO m) @@ -289,7 +289,7 @@ printEdge from to' = liftIO $ Text.putStrLn (Text.concat [ nodeName from, " -> " -- | Convert a package name to a graph node name. nodeName :: PackageName -> Text -nodeName name = "\"" <> displayC name <> "\"" +nodeName name = "\"" <> Text.pack (packageNameString name) <> "\"" -- | Print a node with no dependencies printLeaf :: MonadIO m => PackageName -> m () diff --git a/src/Stack/GhcPkg.hs b/src/Stack/GhcPkg.hs index 818e3bb17c..99f3129d20 100644 --- a/src/Stack/GhcPkg.hs +++ b/src/Stack/GhcPkg.hs @@ -146,7 +146,7 @@ findGhcPkgVersion :: (HasProcessContext env, HasLogFunc env) -> PackageName -> RIO env (Maybe Version) findGhcPkgVersion wc pkgDbs name = do - mv <- findGhcPkgField wc pkgDbs (displayC name) "version" + mv <- findGhcPkgField wc pkgDbs (packageNameString name) "version" case mv of Just !v -> return (parseVersion $ T.unpack v) _ -> return Nothing @@ -168,7 +168,7 @@ unregisterGhcPkgId wc cv pkgDb gid ident = do args = "unregister" : "--user" : "--force" : (case cv of ACGhc v | v < $(mkVersion "7.9") -> - [displayC ident] + [packageIdentifierString ident] _ -> ["--ipid", ghcPkgIdString gid]) -- | Get the version of Cabal from the global package database. diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index e6978199cf..4d899cd3d1 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -176,7 +176,7 @@ ghci opts@GhciOpts{..} = do figureOutMainFile bopts mainIsTargets localTargets pkgs0 -- Build required dependencies and setup local packages. stackYaml <- view stackYamlL - buildDepsAndInitialSteps opts (map (displayC . fst) localTargets) + buildDepsAndInitialSteps opts (map (T.pack . packageNameString . fst) localTargets) targetWarnings stackYaml localTargets nonLocalTargets mfileTargets -- Load the list of modules _after_ building, to catch changes in -- unlisted dependencies (#1180) @@ -293,7 +293,7 @@ getAllLocalTargets GhciOpts{..} targets0 mainIsTargets sourceMap = do then return directlyWanted else do let extraList = - mconcat $ intersperse ", " (map (displayC . fst) extraLoadDeps) + mconcat $ intersperse ", " (map (fromString . packageNameString . fst) extraLoadDeps) if ghciLoadLocalDeps then logInfo $ "The following libraries will also be loaded into GHCi because " <> @@ -362,7 +362,7 @@ runGhci GhciOpts{..} targets mainFile pkgs extraFiles exposePackages = do -- is because it tries to use the interpreter to set -- buffering options on standard IO. (if null targets then ["-package", "base"] else []) ++ - concatMap (\n -> ["-package", displayC n]) exposePackages + concatMap (\n -> ["-package", packageNameString n]) exposePackages else [] oneWordOpts bio | shouldHidePackages = bioOneWordOpts bio ++ bioPackageFlags bio @@ -386,7 +386,7 @@ runGhci GhciOpts{..} targets mainFile pkgs extraFiles exposePackages = do , "-hidir=" <> toFilePathNoTrailingSep oiDir ] logInfo $ "Configuring GHCi with the following packages: " <> - mconcat (intersperse ", " (map (displayC . ghciPkgName) pkgs)) + mconcat (intersperse ", " (map (fromString . packageNameString . ghciPkgName) pkgs)) let execGhci extras = do menv <- liftIO $ configProcessContextSettings config defaultEnvSettings withProcessContext menv $ exec @@ -543,7 +543,7 @@ figureOutMainFile bopts mainIsTargets targets0 packages = do renderCandidate c@(pkgName,namedComponent,mainIs) = let candidateIndex = T.pack . show . (+1) . fromMaybe 0 . elemIndex c in candidateIndex candidates <> ". Package `" <> - displayC pkgName <> + T.pack (packageNameString pkgName) <> "' component " <> renderComp namedComponent <> " with main-is file: " <> @@ -576,9 +576,9 @@ figureOutMainFile bopts mainIsTargets targets0 packages = do CTest name -> "test:" <> name CBench name -> "bench:" <> name sampleTargetArg (pkg,comp,_) = - displayC pkg <> ":" <> renderComp comp + T.pack (packageNameString pkg) <> ":" <> renderComp comp sampleMainIsArg (pkg,comp,_) = - "--main-is " <> displayC pkg <> ":" <> renderComp comp + "--main-is " <> T.pack (packageNameString pkg) <> ":" <> renderComp comp loadGhciPkgDescs :: HasEnvConfig env @@ -618,7 +618,7 @@ loadGhciPkgDesc buildOptsCLI name cabalfp target = do -- Source the package's *.buildinfo file created by configure if any. See -- https://www.haskell.org/cabal/users-guide/developing-packages.html#system-dependent-parameters - buildinfofp <- parseRelFile (displayC name ++ ".buildinfo") + buildinfofp <- parseRelFile (packageNameString name ++ ".buildinfo") hasDotBuildinfo <- doesFileExist (parent cabalfp buildinfofp) let mbuildinfofp | hasDotBuildinfo = Just (parent cabalfp buildinfofp) @@ -820,7 +820,7 @@ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets = do unless (null nonLocalTargets) $ prettyWarnL [ flow "Some targets" - , parens $ fillSep $ punctuate "," $ map (style Good . displayC) nonLocalTargets + , parens $ fillSep $ punctuate "," $ map (style Good . fromString . packageNameString) nonLocalTargets , flow "are not local packages, and so cannot be directly loaded." , flow "In future versions of stack, this might be supported - see" , style Url "https://github.com/commercialhaskell/stack/issues/1441" diff --git a/src/Stack/Hoogle.hs b/src/Stack/Hoogle.hs index 310fe6ce8e..dd83b3b694 100644 --- a/src/Stack/Hoogle.hs +++ b/src/Stack/Hoogle.hs @@ -95,11 +95,11 @@ hoogleCmd (args,setup,rebuild,startServer) go = withBuildConfig go $ do case hooglePackageIdentifier of Left{} -> logInfo $ "Minimum " <> - displayC hoogleMinIdent <> + fromString (packageIdentifierString hoogleMinIdent) <> " is not in your index. Installing the minimum version." Right ident -> logInfo $ "Minimum version is " <> - displayC hoogleMinIdent <> + fromString (packageIdentifierString hoogleMinIdent) <> ". Found acceptable " <> display ident <> " in your index, installing it." @@ -117,7 +117,7 @@ hoogleCmd (args,setup,rebuild,startServer) go = withBuildConfig go $ do { boptsCLITargets = pure $ either - displayC + (T.pack . packageIdentifierString) (utf8BuilderToText . display) hooglePackageIdentifier })) @@ -167,7 +167,7 @@ hoogleCmd (args,setup,rebuild,startServer) go = withBuildConfig go $ do [ "Installed Hoogle is too old, " , T.pack hooglePath , " is version " - , displayC ver + , T.pack $ versionString ver , " but >= 5.0 is required." ] case eres of diff --git a/src/Stack/IDE.hs b/src/Stack/IDE.hs index b978677e23..03bceec4ed 100644 --- a/src/Stack/IDE.hs +++ b/src/Stack/IDE.hs @@ -27,7 +27,7 @@ listPackages = do packageDirs <- liftM (map lpvRoot . Map.elems . lpProject) getLocalPackages forM_ packageDirs $ \dir -> do (gpd, _) <- loadCabalFilePath dir NoPrintWarnings - (logInfo . displayC) (gpdPackageName gpd) + (logInfo . fromString . packageNameString) (gpdPackageName gpd) -- | List the targets in the current project. listTargets :: HasEnvConfig env => RIO env () diff --git a/src/Stack/Init.hs b/src/Stack/Init.hs index 69254ba03a..b67bb38a78 100644 --- a/src/Stack/Init.hs +++ b/src/Stack/Init.hs @@ -393,13 +393,13 @@ getWorkingResolverPlan whichCmd initOpts bundle sd = do if length ignored > 1 then do logWarn "*** Ignoring packages:" - logWarn $ display $ indent $ showItems $ map displayC ignored + logWarn $ display $ indent $ showItems $ map packageNameString ignored else logWarn $ "*** Ignoring package: " - <> displayC + <> fromString (case ignored of [] -> error "getWorkingResolverPlan.head" - x:_ -> x) + x:_ -> packageNameString x) go available where diff --git a/src/Stack/New.hs b/src/Stack/New.hs index 1cef4c02a9..b7a1fb664c 100644 --- a/src/Stack/New.hs +++ b/src/Stack/New.hs @@ -65,7 +65,7 @@ new opts forceOverwrite = do throwM $ Can'tUseWiredInName (newOptsProjectName opts) pwd <- getCurrentDir absDir <- if bare then return pwd - else do relDir <- parseRelDir (displayC project) + else do relDir <- parseRelDir (packageNameString project) liftM (pwd ) (return relDir) exists <- doesDirExist absDir configTemplate <- view $ configL.to configDefaultTemplate @@ -99,7 +99,7 @@ new opts forceOverwrite = do logInfo (loading <> " template \"" <> display (templateName template) <> "\" to create project \"" <> - displayC project <> + fromString (packageNameString project) <> "\" in " <> if bare then "the current directory" else fromString (toFilePath (dirname absDir)) <> @@ -197,9 +197,9 @@ applyTemplate project template nonceParams dir templateText = do return $ T.pack . show $ year let context = M.unions [nonceParams, nameParams, configParams, yearParam] where - nameAsVarId = T.replace "-" "_" $ displayC project - nameAsModule = T.filter (/= '-') $ T.toTitle $ displayC project - nameParams = M.fromList [ ("name", displayC project) + nameAsVarId = T.replace "-" "_" $ T.pack $ packageNameString project + nameAsModule = T.filter (/= '-') $ T.toTitle $ T.pack $ packageNameString project + nameParams = M.fromList [ ("name", T.pack $ packageNameString project) , ("name-as-varid", nameAsVarId) , ("name-as-module", nameAsModule) ] configParams = configTemplateParams config @@ -368,7 +368,7 @@ instance Show NewException where " " <> key <> ": value") (S.toList missingKeys)) , "Or you can pass each one as parameters like this:" - , "stack new " <> displayC name <> " " <> + , "stack new " <> packageNameString name <> " " <> T.unpack (templateName template) <> " " <> unwords @@ -389,4 +389,4 @@ instance Show NewException where show (BadTemplatesHelpEncoding url err) = "UTF-8 decoding error on template info from\n " <> url <> "\n\n" <> show err show (Can'tUseWiredInName name) = - "The name \"" <> displayC name <> "\" is used by GHC wired-in packages, and so shouldn't be used as a package name" + "The name \"" <> packageNameString name <> "\" is used by GHC wired-in packages, and so shouldn't be used as a package name" diff --git a/src/Stack/Options/BuildParser.hs b/src/Stack/Options/BuildParser.hs index e2036520c6..9a0529fdcb 100644 --- a/src/Stack/Options/BuildParser.hs +++ b/src/Stack/Options/BuildParser.hs @@ -89,7 +89,7 @@ targetsParser = completer targetCompleter <> help ("If none specified, use all local packages. " <> "See https://docs.haskellstack.org/en/v" <> - displayC stackMinorVersion <> + versionString stackMinorVersion <> "/build_command/#target-syntax for details."))) flagsParser :: Parser (Map.Map (Maybe PackageName) (Map.Map FlagName Bool)) diff --git a/src/Stack/Options/Completion.hs b/src/Stack/Options/Completion.hs index c2b5bd104f..f8cb6b8489 100644 --- a/src/Stack/Options/Completion.hs +++ b/src/Stack/Options/Completion.hs @@ -86,7 +86,7 @@ flagCompleter = buildConfigCompleter $ \input -> do $ Map.toList lpvs normalFlags = concatMap (\(name, lpv) -> - map (\fl -> displayC name ++ ":" ++ flagString name fl) + map (\fl -> packageNameString name ++ ":" ++ flagString name fl) (C.genPackageFlags (lpvGPD lpv))) $ Map.toList lpvs flagString name fl = diff --git a/src/Stack/Options/GhciParser.hs b/src/Stack/Options/GhciParser.hs index 1e7dad467b..e28249ae66 100644 --- a/src/Stack/Options/GhciParser.hs +++ b/src/Stack/Options/GhciParser.hs @@ -20,7 +20,7 @@ ghciOptsParser = GhciOpts completer (targetCompleter <> fileExtCompleter [".hs", ".lhs"]) <> help ("If none specified, use all local packages. " <> "See https://docs.haskellstack.org/en/v" <> - displayC stackMinorVersion <> + versionString stackMinorVersion <> "/build_command/#target-syntax for details. " <> "If a path to a .hs or .lhs file is specified, it will be loaded."))) <*> fmap concat (many (argsOption (long "ghci-options" <> diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index aaa17cd48e..1eb48b2cf9 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -286,7 +286,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg -- Is the package dependency mentioned here me: either the package -- name itself, or the name of one of the sub libraries - isMe name' = name' == name || displayC name' `S.member` extraLibNames + isMe name' = name' == name || fromString (packageNameString name') `S.member` extraLibNames -- | Generate GHC options for the package's components, and a list of -- options which apply generally to the package, not one specific @@ -402,9 +402,9 @@ generateBuildInfoOpts BioInput {..} = concat [ case M.lookup name biInstalledMap of Just (_, Stack.Types.Package.Library _ident ipid _) -> ["-package-id=" <> ghcPkgIdString ipid] - _ -> ["-package=" <> displayC name <> + _ -> ["-package=" <> packageNameString name <> maybe "" -- This empty case applies to e.g. base. - ((("-" <>) . displayC) . piiVersion) + ((("-" <>) . versionString) . piiVersion) (M.lookup name biSourceMap)] | name <- pkgs] pkgs = @@ -1252,7 +1252,7 @@ findCandidate dirs name = do DotCabalMain{} -> DotCabalMainPath DotCabalFile{} -> DotCabalFilePath DotCabalCFile{} -> DotCabalCFilePath - paths_pkg pkg = "Paths_" ++ displayC pkg + paths_pkg pkg = "Paths_" ++ packageNameString pkg makeNameCandidates = liftM (nubOrd . concat) (mapM makeDirCandidates dirs) makeDirCandidates :: Path Abs Dir @@ -1348,7 +1348,7 @@ buildLogPath package' msuffix = do env <- ask let stack = getProjectWorkDir env fp <- parseRelFile $ concat $ - displayC (packageIdentifier package') : + packageIdentifierString (packageIdentifier package') : maybe id (\suffix -> ("-" :) . (suffix :)) msuffix [".log"] return $ stack $(mkRelDir "logs") fp diff --git a/src/Stack/PackageDump.hs b/src/Stack/PackageDump.hs index a9433c76ad..7273fbe4e9 100644 --- a/src/Stack/PackageDump.hs +++ b/src/Stack/PackageDump.hs @@ -68,7 +68,7 @@ ghcPkgDescribe -> [Path Abs Dir] -- ^ if empty, use global -> ConduitM Text Void (RIO env) a -> RIO env a -ghcPkgDescribe pkgName' = ghcPkgCmdArgs ["describe", "--simple-output", displayC pkgName'] +ghcPkgDescribe pkgName' = ghcPkgCmdArgs ["describe", "--simple-output", packageNameString pkgName'] -- | Call ghc-pkg and stream to the given @Sink@, for a single database ghcPkgCmdArgs diff --git a/src/Stack/SDist.hs b/src/Stack/SDist.hs index 20ec6b3db7..bc7c24885f 100644 --- a/src/Stack/SDist.hs +++ b/src/Stack/SDist.hs @@ -155,7 +155,7 @@ getSDistTarball mpvpBounds pkgDir = do | otherwise = packWith packFileEntry False fp isCabalFp fp = toFilePath pkgDir FP. fp == toFilePath cabalfp tarName = pkgId FP.<.> "tar.gz" - pkgId = displayC (packageIdentifier (lpPackage lp)) + pkgId = packageIdentifierString (packageIdentifier (lpPackage lp)) dirEntries <- mapM packDir (dirsFromFiles files) fileEntries <- mapM packFile files mcabalFileRevision <- liftIO (readIORef cabalFileRevisionRef) @@ -405,7 +405,7 @@ checkPackageInExtractedTarball pkgDir = do config <- getDefaultPackageConfig (gdesc, PackageDescriptionPair pkgDesc _) <- readPackageDescriptionDir config pkgDir NoPrintWarnings logInfo $ - "Checking package '" <> displayC name <> "' for common mistakes" + "Checking package '" <> fromString (packageNameString name) <> "' for common mistakes" let pkgChecks = -- MSS 2017-12-12: Try out a few different variants of -- pkgDesc to try and provoke an error or warning. I don't diff --git a/src/Stack/Script.hs b/src/Stack/Script.hs index 24f8bc6165..b3857d3361 100644 --- a/src/Stack/Script.hs +++ b/src/Stack/Script.hs @@ -81,12 +81,12 @@ scriptCmd opts go' = do $ words $ S8.unpack $ S8.concat bss - if Set.null $ Set.difference (Set.map displayC targetsSet) installed + if Set.null $ Set.difference (Set.map packageNameString targetsSet) installed then logDebug "All packages already installed" else do logDebug "Missing packages, performing installation" Stack.Build.build Nothing lk defaultBuildOptsCLI - { boptsCLITargets = map displayC $ Set.toList targetsSet + { boptsCLITargets = map (T.pack . packageNameString) $ Set.toList targetsSet } let ghcArgs = concat @@ -95,7 +95,7 @@ scriptCmd opts go' = do , map (\x -> "-package" ++ x) $ Set.toList $ Set.insert "base" - $ Set.map displayC targetsSet + $ Set.map packageNameString targetsSet , case soCompile opts of SEInterpret -> [] SECompile -> [] @@ -147,9 +147,9 @@ getPackagesFromModuleInfo mi scriptFP = do [pn] -> return $ Set.singleton pn pns' -> throwString $ concat [ "Module " - , displayC mn + , moduleNameString mn , " appears in multiple packages: " - , unwords $ map displayC pns' + , unwords $ map packageNameString pns' ] Nothing -> return Set.empty return $ Set.unions pns `Set.difference` blacklist diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index cda1d49ec8..1b27a5bb40 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -197,7 +197,7 @@ instance Show SetupException where show (DockerStackExeNotFound stackVersion' osKey) = concat [ stackProgName , "-" - , displayC stackVersion' + , versionString stackVersion' , " executable not found for " , T.unpack osKey , "\nUse the '" @@ -670,7 +670,7 @@ ensureDockerStackExe containerPlatform = do "Downloading Docker-compatible " <> fromString stackProgName <> " executable" - sri <- downloadStackReleaseInfo Nothing Nothing (Just (displayC stackMinorVersion)) + sri <- downloadStackReleaseInfo Nothing Nothing (Just (versionString stackMinorVersion)) platforms <- runReaderT preferredPlatforms (containerPlatform, PlatformVariantNone) downloadStackExe platforms sri stackExeDir False (const $ return ()) return stackExePath @@ -692,7 +692,7 @@ upgradeCabal wc upgradeTo = do else logInfo $ "No install necessary. Cabal " <> - displayC installed <> + fromString (versionString installed) <> " is already installed" Latest -> do mversion <- getLatestHackageVersion name YesPreferredVersions @@ -704,9 +704,9 @@ upgradeCabal wc upgradeTo = do else logInfo $ "No upgrade necessary: Cabal-" <> - displayC latestVersion <> + fromString (versionString latestVersion) <> " is the same or newer than latest hackage version " <> - displayC installed + fromString (versionString installed) -- Configure and run the necessary commands for a cabal install doCabalInstall :: (HasConfig env, HasGHCVariant env) @@ -722,18 +722,18 @@ doCabalInstall wc installed wantedVersion = do withSystemTempDir "stack-cabal-upgrade" $ \tmpdir -> do logInfo $ "Installing Cabal-" <> - displayC wantedVersion <> + fromString (versionString wantedVersion) <> " to replace " <> - displayC installed + fromString (versionString installed) let name = $(mkPackageName "Cabal") - suffix <- parseRelDir $ "Cabal-" ++ displayC wantedVersion + suffix <- parseRelDir $ "Cabal-" ++ versionString wantedVersion let dir = tmpdir suffix unpackPackageLocation dir $ PLIHackage (PackageIdentifierRevision name wantedVersion CFILatest) Nothing compilerPath <- findExecutable (compilerExeName wc) >>= either throwM parseAbsFile - versionDir <- parseRelDir $ displayC wantedVersion + versionDir <- parseRelDir $ versionString wantedVersion let installRoot = toFilePath $ parent (parent compilerPath) $(mkRelDir "new-cabal") versionDir @@ -1091,7 +1091,7 @@ installGHCPosix version downloadInfo _ archiveFile archiveType tempDir destDir = dir <- liftM (tempDir ) $ parseRelDir $ - "ghc-" ++ displayC version + "ghc-" ++ versionString version let runStep step wd env cmd args = do menv' <- modifyEnvVars menv (Map.union env) @@ -1248,7 +1248,7 @@ ensureGhcjsBooted cv shouldBoot bootOpts = do actualStackYaml <- if stackYamlExists then return stackYaml else liftM ((destDir $(mkRelDir "src")) ) $ - parseRelFile $ "ghcjs-" ++ displayC ghcjsVersion ++ "/stack.yaml" + parseRelFile $ "ghcjs-" ++ versionString ghcjsVersion ++ "/stack.yaml" actualStackYamlExists <- doesFileExist actualStackYaml unless actualStackYamlExists $ throwString "Error: Couldn't find GHCJS stack.yaml in old or new location." @@ -1270,20 +1270,20 @@ bootGhcjs ghcjsVersion stackYaml destDir bootOpts = | v < $(mkVersion "1.22.4") -> do logInfo $ "The cabal-install found on PATH is too old to be used for booting GHCJS (version " <> - displayC v <> + fromString (versionString v) <> ")." return True | v >= $(mkVersion "1.23") -> do logWarn $ "The cabal-install found on PATH is a version stack doesn't know about, version " <> - displayC v <> + fromString (versionString v) <> ". This may or may not work.\n" <> "See this issue: https://github.com/ghcjs/ghcjs/issues/470" return False | ghcjsVersion >= $(mkVersion "0.2.0.20160413") && v >= $(mkVersion "1.22.8") -> do logWarn $ "The cabal-install found on PATH, version " <> - displayC v <> + fromString (versionString v) <> ", is >= 1.22.8.\n" <> "That version has a bug preventing ghcjs < 0.2.0.20160413 from booting.\n" <> "See this issue: https://github.com/ghcjs/ghcjs/issues/470" @@ -1408,7 +1408,7 @@ installGHCWindows :: HasConfig env -> Path Abs Dir -> RIO env () installGHCWindows version si archiveFile archiveType _tempDir destDir = do - tarComponent <- parseRelDir $ "ghc-" ++ displayC version + tarComponent <- parseRelDir $ "ghc-" ++ versionString version withUnpackedTarball7z "GHC" si archiveFile archiveType (Just tarComponent) destDir logInfo $ "GHC installed to " <> fromString (toFilePath destDir) diff --git a/src/Stack/Setup/Installed.hs b/src/Stack/Setup/Installed.hs index bf4ce97589..72d4f8606f 100644 --- a/src/Stack/Setup/Installed.hs +++ b/src/Stack/Setup/Installed.hs @@ -45,11 +45,11 @@ data Tool | ToolGhcjs ActualCompiler -- ^ e.g. ghcjs-0.1.0_ghc-7.10.2 toolString :: Tool -> String -toolString (Tool ident) = displayC ident +toolString (Tool ident) = packageIdentifierString ident toolString (ToolGhcjs cv) = compilerVersionString cv toolNameString :: Tool -> String -toolNameString (Tool ident) = displayC $ pkgName ident +toolNameString (Tool ident) = packageNameString $ pkgName ident toolNameString ToolGhcjs{} = "ghcjs" parseToolText :: Text -> Maybe Tool diff --git a/src/Stack/Sig/Sign.hs b/src/Stack/Sig/Sign.hs index 7c5c606afe..becfd3e52e 100644 --- a/src/Stack/Sig/Sign.hs +++ b/src/Stack/Sig/Sign.hs @@ -96,7 +96,7 @@ signPackage url pkg filePath = do let (PackageIdentifier name version) = pkg fingerprint <- gpgVerify sig filePath let fullUrl = - url <> "/upload/signature/" <> displayC name <> "/" <> displayC version <> + url <> "/upload/signature/" <> packageNameString name <> "/" <> versionString version <> "/" <> show fingerprint req <- parseUrlThrow fullUrl diff --git a/src/Stack/Snapshot.hs b/src/Stack/Snapshot.hs index 0a90a7e74f..19b6c5a400 100644 --- a/src/Stack/Snapshot.hs +++ b/src/Stack/Snapshot.hs @@ -72,7 +72,7 @@ instance Show SnapshotException where ] show (PackageDefinedTwice name loc1 loc2) = concat [ "Package " - , displayC name + , packageNameString name , " is defined twice, at " , show loc1 , " and " @@ -83,19 +83,19 @@ instance Show SnapshotException where where go (name, deps) = concat $ "\n" - : displayC name + : packageNameString name : " is missing:\n" : map goDep (Map.toList deps) goDep (dep, (intervals, mversion)) = concat [ "- " - , displayC dep + , packageNameString dep , ". Requires: " , display $ toVersionRange intervals , ", " , case mversion of Nothing -> "none present" - Just version -> displayC version ++ " found" + Just version -> versionString version ++ " found" , "\n" ] show (FilepathInCustomSnapshot url) = @@ -106,7 +106,7 @@ instance Show SnapshotException where T.unpack url show (MissingPackages names) = "The following packages specified by flags or options are not found: " ++ - unwords (map displayC (Set.toList names)) + unwords (map packageNameString (Set.toList names)) show (CustomResolverException url loc e) = concat [ "Unable to load custom resolver " , T.unpack url @@ -360,7 +360,8 @@ fromGlobalHints = -- project compatibility. , lpiLocation = either impureThrow id $ parseGhcPkgId - $ displayC + $ fromString + $ packageIdentifierString $ PackageIdentifier name ver , lpiFlags = Map.empty , lpiGhcOptions = [] diff --git a/src/Stack/Solver.hs b/src/Stack/Solver.hs index 2be8141523..526ce2e360 100644 --- a/src/Stack/Solver.hs +++ b/src/Stack/Solver.hs @@ -135,7 +135,7 @@ cabalSolver cabalfps constraintType when (any isNothing mPkgNames) $ do logInfo $ "*** Only some package names could be parsed: " <> - mconcat (intersperse ", " (map displayC pkgNames)) + mconcat (intersperse ", " (map (fromString . packageNameString) pkgNames)) error $ T.unpack $ "*** User packages involved in cabal failure: " <> T.intercalate ", " (parseConflictingPkgs msg) @@ -176,7 +176,7 @@ cabalSolver cabalfps constraintType formatFlagConstraint package flag enabled = let sign = if enabled then '+' else '-' in - "--constraint=" ++ unwords [displayC package, sign : displayC flag] + "--constraint=" ++ unwords [packageNameString package, sign : flagNameString flag] -- Note the order of the Map union is important -- We override a package in snapshot by a src package @@ -237,15 +237,15 @@ getCabalConfig dir constraintType constraints = do return $ cache : remote : map goConstraint (Map.toList constraints) where goConstraint (name, version) = - assert (not . T.null . displayC $ version) $ + assert (not . null . versionString $ version) $ T.concat [ if constraintType == Constraint || name `Set.member` wiredInPackages then "constraint: " else "preference: " - , displayC name + , T.pack $ packageNameString name , "==" - , displayC version + , T.pack $ versionString version ] setupCompiler @@ -300,12 +300,12 @@ setupCabalEnv compiler inner = do Just version | version < $(mkVersion "1.24") -> prettyWarn $ "Installed version of cabal-install (" <> - displayC version <> + fromString (versionString version) <> ") doesn't support custom-setup clause, and so may not yield correct results." <> line <> "To resolve this, install a newer version via 'stack install cabal-install'." <> line | version >= $(mkVersion "1.25") -> prettyWarn $ "Installed version of cabal-install (" <> - displayC version <> + fromString (versionString version) <> ") is newer than stack has been tested with. If you run into difficulties, consider downgrading." <> line | otherwise -> return () @@ -539,7 +539,7 @@ cabalPackagesCheck cabaldirs noPkgMsg dupErrMsg = do let normalizeString = T.unpack . T.normalize T.NFC . T.pack getNameMismatchPkg (fp, gpd) - | (normalizeString . displayC . gpdPackageName) gpd /= (normalizeString . FP.takeBaseName . toFilePath) fp + | (normalizeString . packageNameString . gpdPackageName) gpd /= (normalizeString . FP.takeBaseName . toFilePath) fp = Just fp | otherwise = Nothing nameMismatchPkgs = mapMaybe getNameMismatchPkg packages diff --git a/src/Stack/Types/Build.hs b/src/Stack/Types/Build.hs index 8f75f173de..c01d8153c7 100644 --- a/src/Stack/Types/Build.hs +++ b/src/Stack/Types/Build.hs @@ -138,9 +138,9 @@ data UnusedFlags = UFNoPackage FlagSource PackageName instance Show StackBuildException where show (Couldn'tFindPkgId name) = - "After installing " <> displayC name <> + "After installing " <> packageNameString name <> ", the package id couldn't be found " <> "(via ghc-pkg describe " <> - displayC name <> "). This shouldn't happen, " <> + packageNameString name <> "). This shouldn't happen, " <> "please report as a bug" show (CompilerVersionMismatch mactual (expected, earch) ghcVariant ghcBuild check mstack resolution) = concat [ case mactual of @@ -179,9 +179,9 @@ instance Show StackBuildException where | Set.null noKnown = [] | otherwise = return $ "The following target packages were not found: " ++ - intercalate ", " (map displayC $ Set.toList noKnown) ++ + intercalate ", " (map packageNameString $ Set.toList noKnown) ++ "\nSee https://docs.haskellstack.org/en/v" - <> displayC stackMinorVersion <> + <> versionString stackMinorVersion <> "/build_command/#target-syntax for details." notInSnapshot' | Map.null notInSnapshot = [] @@ -193,11 +193,11 @@ instance Show StackBuildException where : "but there's no guarantee that they'll build together)." : "" : map - (\(name, version') -> "- " ++ displayC + (\(name, version') -> "- " ++ packageIdentifierString (PackageIdentifier name version')) (Map.toList notInSnapshot) show (TestSuiteFailure ident codes mlogFile bs) = unlines $ concat - [ ["Test suite failure for package " ++ displayC ident] + [ ["Test suite failure for package " ++ packageIdentifierString ident] , flip map (Map.toList codes) $ \(name, mcode) -> concat [ " " , T.unpack name @@ -227,11 +227,11 @@ instance Show StackBuildException where show (ExecutionFailure es) = intercalate "\n\n" $ map show es show (LocalPackageDoesn'tMatchTarget name localV requestedV) = concat [ "Version for local package " - , displayC name + , packageNameString name , " is " - , displayC localV + , versionString localV , ", but you asked for " - , displayC requestedV + , versionString requestedV , " on the command line" ] show (NoSetupHsFound dir) = @@ -247,7 +247,7 @@ instance Show StackBuildException where go :: UnusedFlags -> String go (UFNoPackage src name) = concat [ "- Package '" - , displayC name + , packageNameString name , "' not found" , showFlagSrc src ] @@ -258,18 +258,18 @@ instance Show StackBuildException where , showFlagSrc src , ":\n" , intercalate "\n" - (map (\flag -> " " ++ displayC flag) + (map (\flag -> " " ++ flagNameString flag) (Set.toList flags)) , "\n- Flags defined by package '" ++ name ++ "':\n" , intercalate "\n" - (map (\flag -> " " ++ name ++ ":" ++ displayC flag) + (map (\flag -> " " ++ name ++ ":" ++ flagNameString flag) (Set.toList pkgFlags)) ] - where name = displayC (packageName pkg) + where name = packageNameString (packageName pkg) pkgFlags = packageDefinedFlags pkg go (UFSnapshot name) = concat [ "- Attempted to set flag on snapshot package " - , displayC name + , packageNameString name , ", please add to extra-deps" ] show (TargetParseException [err]) = "Error parsing targets: " ++ T.unpack err @@ -308,7 +308,7 @@ instance Show StackBuildException where show (ConstructPlanFailed msg) = msg show (LocalPackagesPresent locals) = unlines $ "Local packages are not allowed when using the script command. Packages found:" - : map (\ident -> "- " ++ displayC ident) locals + : map (\ident -> "- " ++ packageIdentifierString ident) locals missingExeError :: Bool -> String -> String missingExeError isSimpleBuildType msg = @@ -342,9 +342,9 @@ showBuildError isBuildingSetup exitCode mtaskProvides execName fullArgs logFiles in "\n-- While building " ++ (case (isBuildingSetup, mtaskProvides) of (False, Nothing) -> error "Invariant violated: unexpected case in showBuildError" - (False, Just taskProvides') -> "package " ++ dropQuotes (displayC taskProvides') + (False, Just taskProvides') -> "package " ++ dropQuotes (packageIdentifierString taskProvides') (True, Nothing) -> "simple Setup.hs" - (True, Just taskProvides') -> "custom Setup.hs for package " ++ dropQuotes (displayC taskProvides') + (True, Just taskProvides') -> "custom Setup.hs for package " ++ dropQuotes (packageIdentifierString taskProvides') ) ++ " using:\n " ++ fullCmd ++ "\n" ++ " Process exited with code: " ++ show exitCode ++ @@ -566,7 +566,7 @@ configureOptsDirs bco loc package = concat Nothing -> installRoot docDirSuffix Just dir -> installRoot docDirSuffix dir pkgVerDir = - parseRelDir (displayC (PackageIdentifier (packageName package) + parseRelDir (packageIdentifierString (PackageIdentifier (packageName package) (packageVersion package)) ++ [pathSeparator]) @@ -591,7 +591,7 @@ configureOptsNoDir econfig bco deps isLocal package = concat (if enabled then "" else "-") <> - displayC name) + flagNameString name) (Map.toList flags) , concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) (packageGhcOptions package) , map ("--extra-include-dirs=" ++) (Set.toList (configExtraIncludeDirs config)) @@ -623,16 +623,16 @@ configureOptsNoDir econfig bco deps isLocal package = concat toDepOption1_22 (PackageIdentifier name _) gid = concat [ "--dependency=" - , displayC name + , packageNameString name , "=" , ghcPkgIdString gid ] toDepOption1_18 ident _gid = concat [ "--constraint=" - , displayC name + , packageNameString name , "==" - , displayC version' + , versionString version' ] where PackageIdentifier name version' = ident diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 4ef5755dc1..fbd7ba9e65 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -1140,7 +1140,7 @@ instance Show ConfigException where where go (name, dirs) = unlines $ "" - : (displayC name ++ " used in:") + : (packageNameString name ++ " used in:") : map goLoc dirs goLoc loc = "- " ++ show loc instance Exception ConfigException @@ -1324,7 +1324,7 @@ compilerVersionDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m ( compilerVersionDir = do compilerVersion <- view actualCompilerVersionL parseRelDir $ case compilerVersion of - ACGhc version -> displayC version + ACGhc version -> versionString version ACGhcjs {} -> compilerVersionString compilerVersion -- | Package database for installing dependencies into diff --git a/src/Stack/Types/Docker.hs b/src/Stack/Types/Docker.hs index 595b85c9cb..d87bbc1a23 100644 --- a/src/Stack/Types/Docker.hs +++ b/src/Stack/Types/Docker.hs @@ -278,19 +278,19 @@ instance Show StackDockerException where ,"your configuration file."] show (DockerTooOldException minVersion haveVersion) = concat ["Minimum docker version '" - ,displayC minVersion + ,versionString minVersion ,"' is required by " ,stackProgName ," (you have '" - ,displayC haveVersion + ,versionString haveVersion ,"')."] show (DockerVersionProhibitedException prohibitedVersions haveVersion) = concat ["These Docker versions are incompatible with " ,stackProgName ," (you have '" - ,displayC haveVersion + ,versionString haveVersion ,"'): " - ,intercalate ", " (map displayC prohibitedVersions) + ,intercalate ", " (map versionString prohibitedVersions) ,"."] show (BadDockerVersionException requiredRange haveVersion) = concat ["The version of 'docker' you are using (" @@ -305,23 +305,23 @@ instance Show StackDockerException where concat ["The host's version of '" ,stackProgName ,"' is too old for this Docker image.\nVersion " - ,displayC minVersion + ,versionString minVersion ," is required; you have " - ,displayC hostVersion + ,versionString hostVersion ,"."] show (HostStackTooOldException minVersion Nothing) = concat ["The host's version of '" ,stackProgName ,"' is too old.\nVersion " - ,displayC minVersion + ,versionString minVersion ," is required."] show (ContainerStackTooOldException requiredVersion containerVersion) = concat ["The Docker container's version of '" ,stackProgName ,"' is too old.\nVersion " - ,displayC requiredVersion + ,versionString requiredVersion ," is required; the container has " - ,displayC containerVersion + ,versionString containerVersion ,"."] show CannotDetermineProjectRootException = "Cannot determine project root directory for Docker sandbox." diff --git a/src/Stack/Types/NamedComponent.hs b/src/Stack/Types/NamedComponent.hs index 7cd83531da..3b360f0a12 100644 --- a/src/Stack/Types/NamedComponent.hs +++ b/src/Stack/Types/NamedComponent.hs @@ -41,7 +41,7 @@ renderPkgComponents :: [(PackageName, NamedComponent)] -> Text renderPkgComponents = T.intercalate " " . map renderPkgComponent renderPkgComponent :: (PackageName, NamedComponent) -> Text -renderPkgComponent (pkg, comp) = displayC pkg <> ":" <> renderComponent comp +renderPkgComponent (pkg, comp) = fromString (packageNameString pkg) <> ":" <> renderComponent comp exeComponents :: Set NamedComponent -> Set Text exeComponents = Set.fromList . mapMaybe mExeName . Set.toList diff --git a/src/Stack/Types/Package.hs b/src/Stack/Types/Package.hs index c36cf7d6cc..73656b60bd 100644 --- a/src/Stack/Types/Package.hs +++ b/src/Stack/Types/Package.hs @@ -76,7 +76,7 @@ instance Show PackageException where show (MismatchedCabalIdentifier pir ident) = concat [ "Mismatched package identifier." , "\nFound: " - , displayC ident + , packageIdentifierString ident , "\nExpected: " , T.unpack $ utf8BuilderToText $ display pir ] diff --git a/src/Stack/Unpack.hs b/src/Stack/Unpack.hs index d91bb27d83..4456f14693 100644 --- a/src/Stack/Unpack.hs +++ b/src/Stack/Unpack.hs @@ -44,7 +44,7 @@ unpackPackages mSnapshotDef dest input = do errs -> throwM $ CouldNotParsePackageSelectors errs locs <- Map.fromList <$> mapM (\(pir, ident) -> do - suffix <- parseRelDir $ displayC ident + suffix <- parseRelDir $ packageIdentifierString ident pure (pir, dest suffix) ) (map (\pir@(PackageIdentifierRevision name ver _) -> @@ -73,7 +73,7 @@ unpackPackages mSnapshotDef dest input = do case mver1 of Just _ -> pure mver1 Nothing -> do - updated <- updateHackageIndex $ Just $ "Could not find package " <> displayC name <> ", updating" + updated <- updateHackageIndex $ Just $ "Could not find package " <> fromString (packageNameString name) <> ", updating" case updated of YesUpdateOccurred -> getLatestHackageVersion name YesPreferredVersions NoUpdateOccurred -> pure Nothing @@ -82,11 +82,11 @@ unpackPackages mSnapshotDef dest input = do candidates <- getHackageTypoCorrections name pure $ Left $ concat [ "Could not find package " - , displayC name + , packageNameString name , " on Hackage" , if null candidates then "" - else ". Perhaps you meant: " ++ intercalate ", " (map displayC candidates) + else ". Perhaps you meant: " ++ intercalate ", " (map packageNameString candidates) ] Just pir@(PackageIdentifierRevision _ ver _) -> pure $ Right ( PLIHackage pir Nothing @@ -97,7 +97,7 @@ unpackPackages mSnapshotDef dest input = do toLocSnapshot sd name = go $ concatMap snapshotLocations $ sdSnapshots sd where - go [] = pure $ Left $ "Package does not appear in snapshot: " ++ displayC name + go [] = pure $ Left $ "Package does not appear in snapshot: " ++ packageNameString name go (loc:locs) = do ident@(PackageIdentifier name' _) <- getPackageLocationIdent loc if name == name' diff --git a/src/Stack/Upgrade.hs b/src/Stack/Upgrade.hs index bb385ffc74..905a430141 100644 --- a/src/Stack/Upgrade.hs +++ b/src/Stack/Upgrade.hs @@ -148,9 +148,9 @@ binaryUpgrade (BinaryOpts mplatform force' mver morg mrepo) = do Just downloadVersion -> do prettyInfoL [ flow "Current Stack version:" - , displayC stackVersion <> "," + , fromString (versionString stackVersion) <> "," , flow "available download version:" - , displayC downloadVersion + , fromString (versionString downloadVersion) ] return $ downloadVersion > stackVersion @@ -229,7 +229,7 @@ sourceUpgrade gConfigMonoid mresolver builtHash (SourceOpts gitRepo) = prettyInfoS "Already at latest version, no upgrade required" return Nothing else do - suffix <- parseRelDir $ "stack-" ++ displayC version + suffix <- parseRelDir $ "stack-" ++ versionString version let dir = tmp suffix unpackPackageLocation dir $ PLIHackage pir Nothing pure $ Just dir diff --git a/src/Stack/Upload.hs b/src/Stack/Upload.hs index 5027a700fc..db0e5ca25e 100644 --- a/src/Stack/Upload.hs +++ b/src/Stack/Upload.hs @@ -179,9 +179,9 @@ uploadRevision baseUrl creds ident@(PackageIdentifier name _) cabalFile = do req0 <- parseRequest $ concat [ baseUrl , "package/" - , displayC ident + , packageIdentifierString ident , "/" - , displayC name + , packageNameString name , ".cabal/edit" ] req1 <- formDataBody diff --git a/subs/curator/src/Curator/Snapshot.hs b/subs/curator/src/Curator/Snapshot.hs index 202f0f4634..6b3bf8695b 100644 --- a/subs/curator/src/Curator/Snapshot.hs +++ b/subs/curator/src/Curator/Snapshot.hs @@ -41,19 +41,19 @@ toLoc name pc = case pcSource pc of PSHackage (HackageSource mrange mrequiredLatest revisions) -> do versions <- getHackagePackageVersions NoPreferredVersions name -- don't follow the preferred versions on Hackage, give curators more control - when (Map.null versions) $ error $ "Package not found on Hackage: " ++ displayC name + when (Map.null versions) $ error $ "Package not found on Hackage: " ++ packageNameString name for_ mrequiredLatest $ \required -> case Map.maxViewWithKey versions of - Nothing -> error $ "No versions found for " ++ displayC name + Nothing -> error $ "No versions found for " ++ packageNameString name Just ((version, _), _) | version == required -> pure () | otherwise -> error $ concat [ "For package " - , displayC name + , fromString (packageNameString name) , ", required latest version to be " - , displayC required + , fromString (versionString required) , ", but actual latest is " - , displayC version + , fromString (versionString version) ] let versions' = case mrange of diff --git a/subs/curator/src/Curator/Unpack.hs b/subs/curator/src/Curator/Unpack.hs index 28f68ddbea..19bcc5ed72 100644 --- a/subs/curator/src/Curator/Unpack.hs +++ b/subs/curator/src/Curator/Unpack.hs @@ -29,15 +29,15 @@ unpackSnapshot cons snap root = do PackageIdentifier name version <- getPackageLocationIdent pl pc <- case Map.lookup name $ consPackages cons of - Nothing -> error $ "Package not found in constraints: " ++ displayC name + Nothing -> error $ "Package not found in constraints: " ++ packageNameString name Just pc -> pure pc if pcSkipBuild pc then pure mempty else do let suffixBuilder = - displayC name <> + fromString (packageNameString name) <> "-" <> - displayC version <> + fromString (versionString version) <> "@" <> display sha suffixTmp <- parseRelDir $ T.unpack $ utf8BuilderToText $ suffixBuilder <> ".tmp" @@ -67,7 +67,7 @@ unpackSnapshot cons snap root = do stackYaml <- parseRelFile "stack.yaml" let stackYamlFP = toFilePath $ root stackYaml liftIO $ encodeFile stackYamlFP $ object - [ "resolver" .= ("ghc-" ++ displayC (consGhcVersion cons)) + [ "resolver" .= ("ghc-" ++ versionString (consGhcVersion cons)) , "packages" .= Set.map (\suffix -> toFilePath (unpacked suffix)) suffixes , "flags" .= fmap toCabalStringMap (toCabalStringMap flags) , "curator" .= object diff --git a/subs/pantry/src/Pantry.hs b/subs/pantry/src/Pantry.hs index 15378b054a..ddfe730f9a 100644 --- a/subs/pantry/src/Pantry.hs +++ b/subs/pantry/src/Pantry.hs @@ -96,7 +96,11 @@ module Pantry , nightlySnapshotLocation -- * Cabal helpers - , displayC -- FIXME remove + , packageIdentifierString + , packageNameString + , flagNameString + , versionString + , moduleNameString , CabalString (..) , toCabalStringMap , unCabalStringMap diff --git a/subs/pantry/src/Pantry/Hackage.hs b/subs/pantry/src/Pantry/Hackage.hs index 08a631d142..afdc3d5dff 100644 --- a/subs/pantry/src/Pantry/Hackage.hs +++ b/subs/pantry/src/Pantry/Hackage.hs @@ -381,8 +381,10 @@ getHackageTypoCorrections -> RIO env [PackageName] getHackageTypoCorrections name1 = withStorage $ sinkHackagePackageNames - (\name2 -> damerauLevenshtein (displayC name1) (displayC name2) < 4) + (\name2 -> name1 `distance` name2 < 4) (takeC 10 .| sinkList) + where + distance = damerauLevenshtein `on` (T.pack . packageNameString) -- | Should we pay attention to Hackage's preferred versions? -- @@ -406,7 +408,7 @@ getHackagePackageVersions usePreferred name = withStorage $ do let predicate :: Version -> Map Revision BlobKey -> Bool predicate = fromMaybe (\_ _ -> True) $ do preferredT1 <- mpreferred - preferredT2 <- T.stripPrefix (displayC name) preferredT1 + preferredT2 <- T.stripPrefix (T.pack $ packageNameString name) preferredT1 vr <- Distribution.Text.simpleParse $ T.unpack preferredT2 Just $ \v _ -> withinRange v vr Map.filterWithKey predicate <$> loadHackagePackageVersions name diff --git a/subs/pantry/src/Pantry/Types.hs b/subs/pantry/src/Pantry/Types.hs index 7f4c61079b..17f7805c66 100644 --- a/subs/pantry/src/Pantry/Types.hs +++ b/subs/pantry/src/Pantry/Types.hs @@ -50,7 +50,11 @@ module Pantry.Types , parsePackageName , parseFlagName , parseVersion - , displayC + , packageIdentifierString + , packageNameString + , flagNameString + , versionString + , moduleNameString , OptionalSubdirs (..) , ArchiveLocation (..) , RelFilePath (..) @@ -98,9 +102,9 @@ import qualified Pantry.SHA256 as SHA256 import qualified Distribution.Compat.ReadP as Parse import Distribution.CabalSpecVersion (CabalSpecVersion (..), cabalSpecLatest) import Distribution.Parsec.Common (PError (..), PWarning (..), showPos) -import Distribution.Types.PackageName (PackageName) +import Distribution.Types.PackageName (PackageName, unPackageName) import Distribution.Types.VersionRange (VersionRange) -import Distribution.PackageDescription (FlagName, GenericPackageDescription) +import Distribution.PackageDescription (FlagName, unFlagName, GenericPackageDescription) import Distribution.Types.PackageId (PackageIdentifier (..)) import qualified Distribution.Text import Distribution.ModuleName (ModuleName) @@ -144,7 +148,7 @@ data Package = Package cabalFileName :: PackageName -> SafeFilePath cabalFileName name = - case mkSafeFilePath $ displayC name <> ".cabal" of + case mkSafeFilePath $ T.pack (packageNameString name) <> ".cabal" of Nothing -> error $ "cabalFileName: failed for " ++ show name Just sfp -> sfp @@ -437,7 +441,7 @@ instance FromJSON BlobKey where newtype PackageNameP = PackageNameP { unPackageNameP :: PackageName } instance PersistField PackageNameP where - toPersistValue (PackageNameP pn) = PersistText $ displayC pn + toPersistValue (PackageNameP pn) = PersistText $ T.pack $ packageNameString pn fromPersistValue v = do str <- fromPersistValue v case parsePackageName str of @@ -448,7 +452,7 @@ instance PersistFieldSql PackageNameP where newtype VersionP = VersionP Version instance PersistField VersionP where - toPersistValue (VersionP v) = PersistText $ displayC v + toPersistValue (VersionP v) = PersistText $ T.pack $ versionString v fromPersistValue v = do str <- fromPersistValue v case parseVersion str of @@ -509,7 +513,7 @@ instance Show PackageIdentifierRevision where instance Display PackageIdentifierRevision where display (PackageIdentifierRevision name version cfi) = - displayC name <> "-" <> displayC version <> display cfi + fromString (packageNameString name) <> "-" <> fromString (versionString version) <> display cfi instance ToJSON PackageIdentifierRevision where toJSON = toJSON . utf8BuilderToText . display @@ -648,9 +652,9 @@ instance Display PantryException where Just version | version > cabalSpecLatestVersion -> "\n\nThe cabal file uses the cabal specification version " <> - displayC version <> + fromString (versionString version) <> ", but we only support up to version " <> - displayC cabalSpecLatestVersion <> + fromString (versionString cabalSpecLatestVersion) <> ".\nRecommended action: upgrade your build tool (e.g., `stack upgrade`)." _ -> mempty) display (TreeWithoutCabalFile pl) = "No cabal file found for " <> display pl @@ -662,7 +666,7 @@ instance Display PantryException where fromString (toFilePath fp) <> " does not match the package name it defines.\n" <> "Please rename the file to: " <> - displayC name <> + fromString (packageNameString name) <> ".cabal\n" <> "For more information, see: https://github.com/commercialhaskell/stack/issues/317" display (NoCabalFileFound dir) = @@ -699,7 +703,7 @@ instance Display PantryException where displayShow e display (MismatchedPackageMetadata loc pm mtreeKey foundCabal foundIdent) = "Mismatched package metadata for " <> display loc <> - "\nFound: " <> displayC foundIdent <> " with cabal file " <> + "\nFound: " <> fromString (packageIdentifierString foundIdent) <> " with cabal file " <> display foundCabal <> (case mtreeKey of Nothing -> mempty @@ -718,7 +722,7 @@ instance Display PantryException where display (WrongCabalFileName pl sfp name) = "Wrong cabal file name for package " <> display pl <> "\nCabal file is named " <> display sfp <> - ", but package name is " <> displayC name <> + ", but package name is " <> fromString (packageNameString name) <> "\nFor more information, see:\n - https://github.com/commercialhaskell/stack/issues/317\n -https://github.com/commercialhaskell/stack/issues/895" display (DownloadInvalidSHA256 url Mismatch {..}) = "Mismatched SHA256 hash from " <> display url <> @@ -745,7 +749,8 @@ instance Display PantryException where "Unsupported tar filetype in archive " <> display loc <> " at file " <> fromString fp <> ": " <> displayShow x display (UnsupportedTarball loc e) = "Unsupported tarball from " <> display loc <> ": " <> display e - display (NoHackageCryptographicHash ident) = "Not cryptographic hash found for Hackage package " <> displayC ident + display (NoHackageCryptographicHash ident) = + "Not cryptographic hash found for Hackage package " <> fromString (packageIdentifierString ident) display (FailedToCloneRepo repo) = "Failed to clone repo " <> display repo display (TreeReferencesMissingBlob loc sfp key) = "The package " <> display loc <> @@ -772,8 +777,8 @@ instance Display PantryException where display (MismatchedCabalFileForHackage pir Mismatch{..}) = "When processing cabal file for Hackage package " <> display pir <> ":\nMismatched package identifier." <> - "\nExpected: " <> displayC mismatchExpected <> - "\nActual: " <> displayC mismatchActual + "\nExpected: " <> fromString (packageIdentifierString mismatchExpected) <> + "\nActual: " <> fromString (packageIdentifierString mismatchActual) data FuzzyResults = FRNameNotFound ![PackageName] @@ -786,7 +791,7 @@ displayFuzzy (FRNameNotFound names) = Nothing -> "" Just names' -> "\nPerhaps you meant " <> - orSeparated (NE.map displayC names') <> + orSeparated (NE.map (fromString . packageNameString) names') <> "?" displayFuzzy (FRVersionNotFound pirs) = "\nPossible candidates: " <> @@ -1015,13 +1020,35 @@ parseVersionRange = Distribution.Text.simpleParse parseFlagName :: String -> Maybe FlagName parseFlagName = Distribution.Text.simpleParse --- | Display Cabal types using 'Distribution.Text.Text'. +-- | Render a package name as a 'String'. -- --- FIXME this should be removed and replaced with monomorphic functions for safety. +-- @since 0.1.0.0 +packageNameString :: PackageName -> String +packageNameString = unPackageName + +-- | Render a package identifier as a 'String'. +-- +-- @since 0.1.0.0 +packageIdentifierString :: PackageIdentifier -> String +packageIdentifierString = Distribution.Text.display + +-- | Render a version as a 'String'. +-- +-- @since 0.1.0.0 +versionString :: Version -> String +versionString = Distribution.Text.display + +-- | Render a flag name as a 'String'. +-- +-- @since 0.1.0.0 +flagNameString :: FlagName -> String +flagNameString = unFlagName + +-- | Render a module name as a 'String'. -- -- @since 0.1.0.0 -displayC :: (IsString str, Distribution.Text.Text a) => a -> str -displayC = fromString . Distribution.Text.display +moduleNameString :: ModuleName -> String +moduleNameString = Distribution.Text.display data OptionalSubdirs = OSSubdirs !(NonEmpty Text) @@ -1061,8 +1088,8 @@ instance NFData PackageMetadata instance Display PackageMetadata where display pm = fold $ intersperse ", " $ catMaybes - [ (\name -> "name == " <> displayC name) <$> pmName pm - , (\version -> "version == " <> displayC version) <$> pmVersion pm + [ (\name -> "name == " <> fromString (packageNameString name)) <$> pmName pm + , (\version -> "version == " <> fromString (versionString version)) <$> pmVersion pm , (\tree -> "tree == " <> display tree) <$> pmTreeKey pm , (\cabal -> "cabal file == " <> display cabal) <$> pmCabal pm ] @@ -1284,7 +1311,7 @@ unCabalStringMap = Map.mapKeysMonotonic unCabalString instance Distribution.Text.Text a => ToJSON (CabalString a) where toJSON = toJSON . Distribution.Text.display . unCabalString instance Distribution.Text.Text a => ToJSONKey (CabalString a) where - toJSONKey = toJSONKeyText $ displayC . unCabalString + toJSONKey = toJSONKeyText $ T.pack . Distribution.Text.display . unCabalString instance forall a. IsCabalString a => FromJSON (CabalString a) where parseJSON = withText name $ \t -> @@ -1346,8 +1373,9 @@ data WantedCompiler instance NFData WantedCompiler instance Store WantedCompiler instance Display WantedCompiler where - display (WCGhc vghc) = "ghc-" <> displayC vghc - display (WCGhcjs vghcjs vghc) = "ghcjs-" <> displayC vghcjs <> "_ghc-" <> displayC vghc + display (WCGhc vghc) = "ghc-" <> fromString (versionString vghc) + display (WCGhcjs vghcjs vghc) = + "ghcjs-" <> fromString (versionString vghcjs) <> "_ghc-" <> fromString (versionString vghc) instance ToJSON WantedCompiler where toJSON = toJSON . utf8BuilderToText . display instance FromJSON WantedCompiler where @@ -1607,25 +1635,25 @@ instance Store PackageName where VarSize $ \name -> case size of ConstSize x -> x - VarSize f -> f (displayC name :: String) + VarSize f -> f (packageNameString name) peek = peek >>= maybe (fail "Invalid package name") pure . parsePackageName - poke name = poke (displayC name :: String) + poke name = poke (packageNameString name) instance Store Version where size = VarSize $ \version -> case size of ConstSize x -> x - VarSize f -> f (displayC version :: String) + VarSize f -> f (versionString version) peek = peek >>= maybe (fail "Invalid version") pure . parseVersion - poke version = poke (displayC version :: String) + poke version = poke (versionString version) instance Store FlagName where size = VarSize $ \fname -> case size of ConstSize x -> x - VarSize f -> f (displayC fname :: String) + VarSize f -> f (flagNameString fname) peek = peek >>= maybe (fail "Invalid flag name") pure . parseFlagName - poke fname = poke (displayC fname :: String) + poke fname = poke (flagNameString fname) instance Store ModuleName where size = VarSize $ \mname ->