mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-09-11 18:05:56 +03:00
core: add System.Nix.OutputName
This commit is contained in:
parent
b8294ffb74
commit
2f73cd9aef
@ -65,6 +65,7 @@ library
|
||||
, System.Nix.Fingerprint
|
||||
, System.Nix.Hash
|
||||
, System.Nix.Hash.Truncation
|
||||
, System.Nix.OutputName
|
||||
, System.Nix.Signature
|
||||
, System.Nix.Store.Types
|
||||
, System.Nix.StorePath
|
||||
|
@ -13,17 +13,19 @@ module System.Nix.DerivedPath (
|
||||
import GHC.Generics (Generic)
|
||||
import Data.Set (Set)
|
||||
import Data.Text (Text)
|
||||
import System.Nix.StorePath (StoreDir(..), StorePath, StorePathName, InvalidNameError, InvalidPathError)
|
||||
import System.Nix.OutputName (OutputName, InvalidNameError)
|
||||
import System.Nix.StorePath (StoreDir(..), StorePath, InvalidPathError)
|
||||
|
||||
import qualified Data.Bifunctor
|
||||
import qualified Data.ByteString.Char8
|
||||
import qualified Data.Set
|
||||
import qualified Data.Text
|
||||
import qualified System.Nix.OutputName
|
||||
import qualified System.Nix.StorePath
|
||||
|
||||
data OutputsSpec =
|
||||
OutputsSpec_All
|
||||
| OutputsSpec_Names (Set StorePathName)
|
||||
| OutputsSpec_Names (Set OutputName)
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
||||
data DerivedPath =
|
||||
@ -45,7 +47,7 @@ parseOutputsSpec t
|
||||
names <- mapM
|
||||
( Data.Bifunctor.first
|
||||
ParseOutputsError_InvalidName
|
||||
. System.Nix.StorePath.mkStorePathName
|
||||
. System.Nix.OutputName.mkOutputName
|
||||
)
|
||||
(Data.Text.splitOn "," t)
|
||||
if null names
|
||||
@ -56,7 +58,11 @@ outputsSpecToText :: OutputsSpec -> Text
|
||||
outputsSpecToText = \case
|
||||
OutputsSpec_All -> "*"
|
||||
OutputsSpec_Names ns ->
|
||||
Data.Text.intercalate "," (fmap System.Nix.StorePath.unStorePathName (Data.Set.toList ns))
|
||||
Data.Text.intercalate
|
||||
","
|
||||
(fmap System.Nix.OutputName.unOutputName
|
||||
(Data.Set.toList ns)
|
||||
)
|
||||
|
||||
parseDerivedPath
|
||||
:: StoreDir
|
||||
|
29
hnix-store-core/src/System/Nix/OutputName.hs
Normal file
29
hnix-store-core/src/System/Nix/OutputName.hs
Normal file
@ -0,0 +1,29 @@
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-|
|
||||
Description : Derived path output names
|
||||
-}
|
||||
|
||||
module System.Nix.OutputName
|
||||
( OutputName(..)
|
||||
, mkOutputName
|
||||
-- * Re-exports
|
||||
, System.Nix.StorePath.InvalidNameError(..)
|
||||
, System.Nix.StorePath.parseNameText
|
||||
) where
|
||||
|
||||
import Data.Hashable (Hashable)
|
||||
import Data.Text (Text)
|
||||
import GHC.Generics (Generic)
|
||||
import System.Nix.StorePath (InvalidNameError)
|
||||
|
||||
import qualified System.Nix.StorePath
|
||||
|
||||
-- | Name of the derived path output
|
||||
-- Typically used for "dev", "doc" sub-outputs
|
||||
newtype OutputName = OutputName
|
||||
{ -- | Extract the contents of the name.
|
||||
unOutputName :: Text
|
||||
} deriving (Eq, Generic, Hashable, Ord, Show)
|
||||
|
||||
mkOutputName :: Text -> Either InvalidNameError OutputName
|
||||
mkOutputName = fmap OutputName . System.Nix.StorePath.parseNameText
|
@ -46,6 +46,7 @@ library
|
||||
, System.Nix.Arbitrary.Derivation
|
||||
, System.Nix.Arbitrary.DerivedPath
|
||||
, System.Nix.Arbitrary.Hash
|
||||
, System.Nix.Arbitrary.OutputName
|
||||
, System.Nix.Arbitrary.Signature
|
||||
, System.Nix.Arbitrary.Store.Types
|
||||
, System.Nix.Arbitrary.StorePath
|
||||
|
@ -11,6 +11,7 @@ import System.Nix.Arbitrary.ContentAddress ()
|
||||
import System.Nix.Arbitrary.Derivation ()
|
||||
import System.Nix.Arbitrary.DerivedPath ()
|
||||
import System.Nix.Arbitrary.Hash ()
|
||||
import System.Nix.Arbitrary.OutputName ()
|
||||
import System.Nix.Arbitrary.Signature ()
|
||||
import System.Nix.Arbitrary.Store.Types ()
|
||||
import System.Nix.Arbitrary.StorePath ()
|
||||
|
@ -6,6 +6,7 @@ module System.Nix.Arbitrary.DerivedPath where
|
||||
import qualified Data.Set
|
||||
import Test.QuickCheck (Arbitrary(..), oneof)
|
||||
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
|
||||
import System.Nix.Arbitrary.OutputName ()
|
||||
import System.Nix.Arbitrary.StorePath ()
|
||||
import System.Nix.DerivedPath (DerivedPath, OutputsSpec(..))
|
||||
|
||||
|
19
hnix-store-tests/src/System/Nix/Arbitrary/OutputName.hs
Normal file
19
hnix-store-tests/src/System/Nix/Arbitrary/OutputName.hs
Normal file
@ -0,0 +1,19 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# OPTIONS_GHC -Wno-orphans #-}
|
||||
module System.Nix.Arbitrary.OutputName where
|
||||
|
||||
import System.Nix.OutputName (OutputName)
|
||||
import qualified Data.Text
|
||||
import qualified System.Nix.OutputName
|
||||
|
||||
import Test.QuickCheck (Arbitrary(arbitrary), elements, listOf)
|
||||
|
||||
instance Arbitrary OutputName where
|
||||
arbitrary =
|
||||
either (error . show) id
|
||||
. System.Nix.OutputName.mkOutputName
|
||||
. Data.Text.pack <$> ((:) <$> s1 <*> listOf sn)
|
||||
where
|
||||
alphanum = ['a' .. 'z'] <> ['A' .. 'Z'] <> ['0' .. '9']
|
||||
s1 = elements $ alphanum <> "+-_?="
|
||||
sn = elements $ alphanum <> "+-._?="
|
Loading…
Reference in New Issue
Block a user