Skip to content

Commit

Permalink
go down another rabbithole turning BS into Text
Browse files Browse the repository at this point in the history
  • Loading branch information
kadoban committed Nov 20, 2015
1 parent 83f2bdc commit 0374267
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Stack/Build/ConstructPlan.hs
Expand Up @@ -180,7 +180,7 @@ constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackag
, combinedMap = combineMap sourceMap installedMap
, toolToPackages = \ (Dependency name _) ->
maybe Map.empty (Map.fromSet (const anyVersion)) $
Map.lookup (S8.pack . packageNameString . fromCabalPackageName $ name) toolMap
Map.lookup (T.pack . packageNameString . fromCabalPackageName $ name) toolMap
, ctxEnvConfig = econfig
, callStack = []
, extraToBuild = extraToBuild0
Expand Down
5 changes: 3 additions & 2 deletions src/Stack/BuildPlan.hs
Expand Up @@ -53,6 +53,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
import Data.Monoid
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Data.Time (Day)
Expand Down Expand Up @@ -283,7 +284,7 @@ addDeps allowMissing compilerVersion toCalc = do
}
name = packageIdentifierName ident
pd = resolvePackageDescription packageConfig gpd
exes = Set.fromList $ map (ExeName . S8.pack . exeName) $ executables pd
exes = Set.fromList $ map (ExeName . T.pack . exeName) $ executables pd
notMe = Set.filter (/= name) . Map.keysSet
return (name, MiniPackageInfo
{ mpiVersion = packageIdentifierVersion ident
Expand Down Expand Up @@ -368,7 +369,7 @@ getDeps mbp isShadowed packages =
type ToolMap = Map ByteString (Set PackageName)

-- | Map from tool name to package providing it
getToolMap :: MiniBuildPlan -> Map ByteString (Set PackageName)
getToolMap :: MiniBuildPlan -> Map Text (Set PackageName)
getToolMap mbp =
Map.unionsWith Set.union

Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Package.hs
Expand Up @@ -58,7 +58,7 @@ import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8, decodeUtf8With, encodeUtf8)
import Data.Text.Encoding (decodeUtf8, decodeUtf8With)
import Data.Text.Encoding.Error (lenientDecode)
import Distribution.Compiler
import Distribution.ModuleName (ModuleName)
Expand Down Expand Up @@ -441,10 +441,10 @@ packageDependencies =
allBuildInfo'

-- | Get all build tool dependencies of the package (buildable targets only).
packageToolDependencies :: PackageDescription -> Map BS.ByteString VersionRange
packageToolDependencies :: PackageDescription -> Map Text VersionRange
packageToolDependencies =
M.fromList .
concatMap (fmap (encodeUtf8 . packageNameText . depName &&& depRange) .
concatMap (fmap (packageNameText . depName &&& depRange) .
buildTools) .
allBuildInfo'

Expand Down
17 changes: 7 additions & 10 deletions src/Stack/Types/BuildPlan.hs
Expand Up @@ -32,8 +32,6 @@ import Data.Aeson (FromJSON (..), ToJSON (..),
object, withObject, withText,
(.!=), (.:), (.:?), (.=))
import Data.Binary.VersionTagged
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as S8
import Data.Hashable (Hashable)
import qualified Data.HashMap.Strict as HashMap
import Data.Map (Map)
Expand All @@ -44,7 +42,6 @@ import Data.Set (Set)
import Data.String (IsString, fromString)
import Data.Text (Text, pack, unpack)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Data.Text.Read (decimal)
import Data.Time (Day)
import qualified Data.Traversable as T
Expand Down Expand Up @@ -248,13 +245,13 @@ newtype Maintainer = Maintainer { unMaintainer :: Text }
deriving (Show, Eq, Ord, Hashable, ToJSON, FromJSON, IsString)

-- | Name of an executable.
newtype ExeName = ExeName { unExeName :: ByteString }
newtype ExeName = ExeName { unExeName :: Text }
deriving (Show, Eq, Ord, Hashable, IsString, Generic, Binary, NFData)
instance HasStructuralInfo ExeName
instance ToJSON ExeName where
toJSON = toJSON . S8.unpack . unExeName
toJSON = toJSON . unExeName
instance FromJSON ExeName where
parseJSON = withText "ExeName" $ return . ExeName . encodeUtf8
parseJSON = withText "ExeName" $ return . ExeName

-- | A simplified package description that tracks:
--
Expand Down Expand Up @@ -363,9 +360,9 @@ parseSnapName t0 =
Nightly <$> readMay (T.unpack t1)

instance ToJSON a => ToJSON (Map ExeName a) where
toJSON = toJSON . Map.mapKeysWith const (S8.unpack . unExeName)
toJSON = toJSON . Map.mapKeysWith const unExeName
instance FromJSON a => FromJSON (Map ExeName a) where
parseJSON = fmap (Map.mapKeysWith const (ExeName . encodeUtf8)) . parseJSON
parseJSON = fmap (Map.mapKeysWith const ExeName) . parseJSON

-- | A simplified version of the 'BuildPlan' + cabal file.
data MiniBuildPlan = MiniBuildPlan
Expand All @@ -383,11 +380,11 @@ data MiniPackageInfo = MiniPackageInfo
{ mpiVersion :: !Version
, mpiFlags :: !(Map FlagName Bool)
, mpiPackageDeps :: !(Set PackageName)
, mpiToolDeps :: !(Set ByteString)
, mpiToolDeps :: !(Set Text)
-- ^ Due to ambiguity in Cabal, it is unclear whether this refers to the
-- executable name, the package name, or something else. We have to guess
-- based on what's available, which is why we store this is an unwrapped
-- 'ByteString'.
-- 'Text'.
, mpiExes :: !(Set ExeName)
-- ^ Executables provided by this package
, mpiHasLibrary :: !Bool
Expand Down

0 comments on commit 0374267

Please sign in to comment.