Fix ghcup-gen validation for global tools
This commit is contained in:
parent
687a1d0c88
commit
7b050e9fe2
@ -69,13 +69,15 @@ tarballFilterP = option readm $
|
|||||||
long "tarball-filter" <> short 'u' <> metavar "<tool>-<version>" <> value def
|
long "tarball-filter" <> short 'u' <> metavar "<tool>-<version>" <> value def
|
||||||
<> help "Only check certain tarballs (format: <tool>-<version>)"
|
<> help "Only check certain tarballs (format: <tool>-<version>)"
|
||||||
where
|
where
|
||||||
def = TarballFilter Nothing (makeRegex ("" :: String))
|
def = TarballFilter (Right Nothing) (makeRegex ("" :: String))
|
||||||
readm = do
|
readm = do
|
||||||
s <- str
|
s <- str
|
||||||
case span (/= '-') s of
|
case span (/= '-') s of
|
||||||
(_, []) -> fail "invalid format, missing '-' after the tool name"
|
(_, []) -> fail "invalid format, missing '-' after the tool name"
|
||||||
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
||||||
pure (TarballFilter $ Just tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
pure (TarballFilter $ Right $ Just tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
||||||
|
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
||||||
|
pure (TarballFilter $ Left tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
||||||
_ -> fail "invalid tool"
|
_ -> fail "invalid tool"
|
||||||
low = fmap toLower
|
low = fmap toLower
|
||||||
|
|
||||||
@ -105,23 +107,18 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
_ <- customExecParser (prefs showHelpOnError) (info (opts <**> helper) idm)
|
_ <- customExecParser (prefs showHelpOnError) (info (opts <**> helper) idm)
|
||||||
>>= \Options {..} -> case optCommand of
|
>>= \Options {..} -> case optCommand of
|
||||||
ValidateYAML vopts -> case vopts of
|
ValidateYAML vopts -> withValidateYamlOpts vopts validate
|
||||||
ValidateYAMLOpts { vInput = Nothing } ->
|
ValidateTarballs vopts tarballFilter -> withValidateYamlOpts vopts (validateTarballs tarballFilter)
|
||||||
B.getContents >>= valAndExit validate
|
|
||||||
ValidateYAMLOpts { vInput = Just StdInput } ->
|
|
||||||
B.getContents >>= valAndExit validate
|
|
||||||
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
|
||||||
B.readFile file >>= valAndExit validate
|
|
||||||
ValidateTarballs vopts tarballFilter -> case vopts of
|
|
||||||
ValidateYAMLOpts { vInput = Nothing } ->
|
|
||||||
B.getContents >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
ValidateYAMLOpts { vInput = Just StdInput } ->
|
|
||||||
B.getContents >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
|
||||||
B.readFile file >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
where
|
where
|
||||||
|
withValidateYamlOpts vopts f = case vopts of
|
||||||
|
ValidateYAMLOpts { vInput = Nothing } ->
|
||||||
|
B.getContents >>= valAndExit f
|
||||||
|
ValidateYAMLOpts { vInput = Just StdInput } ->
|
||||||
|
B.getContents >>= valAndExit f
|
||||||
|
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
||||||
|
B.readFile file >>= valAndExit f
|
||||||
valAndExit f contents = do
|
valAndExit f contents = do
|
||||||
(GHCupInfo _ av gt) <- case Y.decodeEither' contents of
|
(GHCupInfo _ av gt) <- case Y.decodeEither' contents of
|
||||||
Right r -> pure r
|
Right r -> pure r
|
||||||
|
@ -184,7 +184,7 @@ validate dls _ = do
|
|||||||
isBase _ = False
|
isBase _ = False
|
||||||
|
|
||||||
data TarballFilter = TarballFilter
|
data TarballFilter = TarballFilter
|
||||||
{ tfTool :: Maybe Tool
|
{ tfTool :: Either GlobalTool (Maybe Tool)
|
||||||
, tfVersion :: Regex
|
, tfVersion :: Regex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,17 +201,16 @@ validateTarballs :: ( Monad m
|
|||||||
-> GHCupDownloads
|
-> GHCupDownloads
|
||||||
-> M.Map GlobalTool DownloadInfo
|
-> M.Map GlobalTool DownloadInfo
|
||||||
-> m ExitCode
|
-> m ExitCode
|
||||||
validateTarballs (TarballFilter tool versionRegex) dls gt = do
|
validateTarballs (TarballFilter etool versionRegex) dls gt = do
|
||||||
ref <- liftIO $ newIORef 0
|
ref <- liftIO $ newIORef 0
|
||||||
|
|
||||||
flip runReaderT ref $ do
|
flip runReaderT ref $ do
|
||||||
-- download/verify all tarballs
|
-- download/verify all tarballs
|
||||||
let dlis = nubOrd $ dls ^.. each %& indices (maybe (const True) (==) tool) %> each %& indices (matchTest versionRegex . T.unpack . prettyVer) % (viSourceDL % _Just `summing` viArch % each % each % each)
|
let dlis = either (const []) (\tool -> nubOrd $ dls ^.. each %& indices (maybe (const True) (==) tool) %> each %& indices (matchTest versionRegex . T.unpack . prettyVer) % (viSourceDL % _Just `summing` viArch % each % each % each)) etool
|
||||||
when (null dlis) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
|
||||||
|
|
||||||
let gdlis = nubOrd $ gt ^.. each
|
let gdlis = nubOrd $ gt ^.. each
|
||||||
|
let allDls = dlis ++ gdlis
|
||||||
forM_ (dlis ++ gdlis) downloadAll
|
when (null allDls) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
||||||
|
forM_ allDls downloadAll
|
||||||
|
|
||||||
-- exit
|
-- exit
|
||||||
e <- liftIO $ readIORef ref
|
e <- liftIO $ readIORef ref
|
||||||
@ -254,18 +253,21 @@ validateTarballs (TarballFilter tool versionRegex) dls gt = do
|
|||||||
#endif
|
#endif
|
||||||
]
|
]
|
||||||
$ do
|
$ do
|
||||||
case tool of
|
case etool of
|
||||||
Just GHCup -> do
|
Right (Just GHCup) -> do
|
||||||
let fn = "ghcup"
|
tmpUnpack <- lift mkGhcupTmpDir
|
||||||
p <- liftE $ download (settings appstate) dli (cacheDir dirs) (Just fn)
|
_ <- liftE $ download (settings appstate) dli tmpUnpack Nothing
|
||||||
liftE $ checkDigest (settings appstate) dli p
|
|
||||||
pure Nothing
|
pure Nothing
|
||||||
_ -> do
|
Right _ -> do
|
||||||
p <- liftE $ downloadCached (settings appstate) dirs dli Nothing
|
p <- liftE $ downloadCached (settings appstate) dirs dli Nothing
|
||||||
fmap (Just . head . splitDirectories . head)
|
fmap (Just . head . splitDirectories . head)
|
||||||
. liftE
|
. liftE
|
||||||
. getArchiveFiles
|
. getArchiveFiles
|
||||||
$ p
|
$ p
|
||||||
|
Left ShimGen -> do
|
||||||
|
tmpUnpack <- lift mkGhcupTmpDir
|
||||||
|
_ <- liftE $ download (settings appstate) dli tmpUnpack Nothing
|
||||||
|
pure Nothing
|
||||||
case r of
|
case r of
|
||||||
VRight (Just basePath) -> do
|
VRight (Just basePath) -> do
|
||||||
case _dlSubdir dli of
|
case _dlSubdir dli of
|
||||||
|
Loading…
Reference in New Issue
Block a user