11
2+ {-# LANGUAGE LambdaCase #-}
3+ {-# LANGUAGE NamedFieldPuns #-}
24{-# LANGUAGE OverloadedStrings #-}
35{-# LANGUAGE ScopedTypeVariables #-}
46{-# LANGUAGE TypeApplications #-}
@@ -44,6 +46,7 @@ defaultExecConfig = ExecConfig
4446
4547
4648mkExecConfig :: ()
49+ => HasCallStack
4750 => MonadIO m
4851 => FilePath
4952 -> IO. Sprocket
@@ -65,7 +68,8 @@ mkExecConfig tempBaseAbsPath sprocket networkId = do
6568
6669
6770execCli'
68- :: MonadIO m
71+ :: HasCallStack
72+ => MonadIO m
6973 => ExecConfig
7074 -> [String ]
7175 -> m String
@@ -94,14 +98,16 @@ execCli = GHC.withFrozenCallStack $ execFlex "cardano-cli" "CARDANO_CLI"
9498-- When running outside a nix environment, the `pkgBin` describes the name of the binary
9599-- to launch via cabal exec.
96100execFlex
97- :: String
101+ :: HasCallStack
102+ => String
98103 -> String
99104 -> [String ]
100105 -> RIO env String
101106execFlex = execFlex' defaultExecConfig
102107
103108execFlex'
104109 :: MonadIO m
110+ => HasCallStack
105111 => ExecConfig
106112 -> String
107113 -> String
@@ -215,8 +221,7 @@ exeSuffix = if OS.isWin32 then ".exe" else ""
215221-- executable has been built.
216222-- Throws an exception on failure.
217223binDist
218- :: HasCallStack
219- => MonadIO m
224+ :: (HasCallStack , MonadIO m )
220225 => String
221226 -- ^ Package name
222227 -> String
@@ -233,20 +238,25 @@ binDist pkg binaryEnv = do
233238 <> " \" if you are working with sources. Otherwise define "
234239 <> binaryEnv
235240 <> " and have it point to the executable you want."
236- contents <- liftIOAnnotated $ LBS. readFile planJsonFile
237-
238- case eitherDecode contents of
239- Right plan -> case L. filter matching (plan & installPlan) of
240- (component: _) -> case component & binFile of
241- Just bin -> return $ addExeSuffix (T. unpack bin)
242- Nothing -> error $ " missing \" bin-file\" key in plan component: " <> show component <> " in the plan in: " <> planJsonFile
243- [] -> error $ " Cannot find \" component-name\" key with the value \" exe:" <> pkg <> " \" in the plan in: " <> planJsonFile
244- Left message -> error $ " Cannot decode plan in " <> planJsonFile <> " : " <> message
245- where matching :: Component -> Bool
246- matching component = case componentName component of
247- Just name -> name == " exe:" <> T. pack pkg
248- Nothing -> False
249241
242+ Plan {installPlan} <- eitherDecode <$> liftIOAnnotated (LBS. readFile planJsonFile)
243+ >>= \ case
244+ Left message -> error $ " Cannot decode plan in " <> planJsonFile <> " : " <> message
245+ Right plan -> pure plan
246+
247+ let componentName = " exe:" <> fromString pkg
248+ case findComponent componentName installPlan of
249+ Just Component {binFile= Just binFilePath} -> pure . addExeSuffix $ T. unpack binFilePath
250+ Just component@ Component {binFile= Nothing } ->
251+ error $ " missing \" bin-file\" key in plan component: " <> show component <> " in the plan in: " <> planJsonFile
252+ Nothing ->
253+ error $ " Cannot find \" component-name\" key with the value \" exe:" <> pkg <> " \" in the plan in: " <> planJsonFile
254+ where
255+ findComponent :: Text -> [Component ] -> Maybe Component
256+ findComponent _ [] = Nothing
257+ findComponent needle (c@ Component {componentName, components}: topLevelComponents)
258+ | componentName == Just needle = Just c
259+ | otherwise = findComponent needle topLevelComponents <|> findComponent needle components
250260
251261
252262procNode
@@ -278,7 +288,7 @@ procFlex
278288 -- ^ Captured stdout
279289procFlex = procFlex' defaultExecConfig
280290
281-
291+ -- This will also catch async exceptions as well.
282292liftIOAnnotated :: (HasCallStack , MonadIO m ) => IO a -> m a
283293liftIOAnnotated action = GHC. withFrozenCallStack $
284- liftIO $ action `catch` (\ (e :: SomeException ) -> throwM $ exceptionWithCallStack e)
294+ liftIOAnnotated $ action `catch` (\ (e :: SomeException ) -> throwM $ exceptionWithCallStack e)
0 commit comments