Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 40238d5

Browse files
committed
[GH-313] Test together launcher/updater.
1 parent 8abae42 commit 40238d5

File tree

6 files changed

+78
-49
lines changed

6 files changed

+78
-49
lines changed

cardano-launcher/app/Main.hs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ import Cardano.Shell.Configuration (ConfigurationOptions (..),
2424
getWPath, getWargs,
2525
setWorkingDirectory)
2626
import Cardano.Shell.Launcher (LoggingDependencies (..), TLSError,
27-
TLSPath (..), WalletMode (..),
28-
generateTlsCertificates,
29-
runWalletProcess, walletRunnerProcess)
30-
import Cardano.Shell.Update.Lib (RemoveArchiveAfterInstall (..),
31-
UpdaterData (..),
32-
runDefaultUpdateProcess, runUpdater)
27+
TLSPath (..), generateTlsCertificates,
28+
runLauncher, walletRunnerProcess)
29+
import Cardano.Shell.Update.Lib (UpdaterData (..),
30+
runDefaultUpdateProcess)
3331
import Control.Exception.Safe (throwM)
3432
import Data.Text.Lazy.Builder (fromString, fromText)
3533

@@ -75,8 +73,7 @@ main = do
7573
Trace.logError baseTrace $ "Working directory does not exist: " <> toS workingDir
7674
throwM . WorkingDirectoryDoesNotExist $ workingDir
7775

78-
-- Really no clue what to put there and how will the wallet work.
79-
-- These will be refactored in the future
76+
-- Configuration from the launcher options.
8077
let configurationOptions :: ConfigurationOptions
8178
configurationOptions = loConfiguration launcherOptions
8279

@@ -89,11 +86,12 @@ main = do
8986
let updaterData :: UpdaterData
9087
updaterData = getUpdaterData launcherOptions
9188

89+
9290
-- where to generate the certificates
9391
let mTlsPath :: Maybe TLSPath
9492
mTlsPath = TLSPath <$> loTlsPath launcherOptions
9593

96-
94+
-- If the path doesn't exist, then TLS has been disabled!
9795
case mTlsPath of
9896
Just tlsPath -> do
9997
-- | If we need to, we first check if there are certificates so we don't have
@@ -112,26 +110,17 @@ main = do
112110
Right _ -> return ()
113111
Nothing -> pure () -- TLS generation has been disabled
114112

115-
-- In the case the user wants to avoid installing the update now, we
116-
-- run the update (if there is one) when we have it downloaded.
117-
void $ runUpdater
118-
RemoveArchiveAfterInstall
119-
runDefaultUpdateProcess
120-
loggingDependencies
121-
updaterData
122-
123-
-- You still want to run the wallet even if the update fails
124-
exitCode <- runWalletProcess
113+
-- Finally, run the launcher once everything is set up!
114+
exitCode <- runLauncher
125115
loggingDependencies
126-
WalletModeNormal
116+
-- WalletPath -> WalletArguments -> IO ExitCode
117+
walletRunnerProcess
127118
walletPath
128119
walletArgs
129-
walletRunnerProcess
120+
-- FilePath -> [String] -> IO ExitCode
121+
runDefaultUpdateProcess
130122
updaterData
131123

132-
Trace.logNotice baseTrace $
133-
"Shutting down cardano-launcher with exitcode: " <> show exitCode
134-
135124
-- Exit the program with exit code.
136125
exitWith exitCode
137126

cardano-launcher/cardano-launcher.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ library
4848
, cardano-sl-x509
4949
, safe-exceptions
5050
, x509-validation
51+
, logict
5152

5253
if os(windows)
5354
build-depends: Win32

cardano-launcher/src/Cardano/Shell/Configuration.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
33

44
module Cardano.Shell.Configuration
5-
( WalletArguments(..)
6-
, WalletPath(..)
7-
, LauncherOptions(..)
8-
, ConfigurationOptions(..)
5+
( WalletArguments (..)
6+
, WalletPath (..)
7+
, LauncherOptions (..)
8+
, ConfigurationOptions (..)
99
-- * Getters
1010
, getUpdaterData
1111
, getWargs
@@ -42,14 +42,14 @@ newtype WalletPath = WalletPath
4242
-- Todo: Add haddock comment for each field
4343
-- | Launcher options
4444
data LauncherOptions = LauncherOptions
45-
{ loConfiguration :: !ConfigurationOptions
46-
, loTlsPath :: !(Maybe FilePath)
47-
, loUpdaterPath :: !FilePath
48-
, loUpdaterArgs :: ![Text]
49-
, loUpdateArchive :: !FilePath
50-
, loWalletPath :: !FilePath
51-
, loWalletArgs :: ![Text]
52-
, loWorkingDirectory :: !FilePath
45+
{ loConfiguration :: !ConfigurationOptions
46+
, loTlsPath :: !(Maybe FilePath)
47+
, loUpdaterPath :: !FilePath
48+
, loUpdaterArgs :: ![Text]
49+
, loUpdateArchive :: !FilePath
50+
, loWalletPath :: !FilePath
51+
, loWalletArgs :: ![Text]
52+
, loWorkingDirectory :: !FilePath
5353
-- On WIN it should set this directory as current.
5454
} deriving (Show, Generic)
5555

cardano-launcher/src/Cardano/Shell/Launcher.hs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Cardano.Shell.Launcher
99
, walletRunnerProcess
1010
, LoggingDependencies (..)
1111
-- * Functions
12+
, runLauncher
1213
, runWalletProcess
1314
-- * Critical exports (testing)
1415
, DaedalusExitCode (..)
@@ -34,8 +35,8 @@ import Cardano.Shell.Configuration (ConfigurationOptions (..),
3435
WalletPath (..))
3536
import Cardano.Shell.Types (LoggingDependencies (..))
3637
import Cardano.Shell.Update.Lib (RemoveArchiveAfterInstall (..),
37-
UpdaterData (..),
38-
runDefaultUpdateProcess, runUpdater)
38+
RunUpdateFunc, UpdaterData (..),
39+
runUpdater)
3940
import Cardano.X509.Configuration (ConfigurationKey (..),
4041
DirConfiguration (..), certChecks,
4142
certFilename, certOutDir,
@@ -167,9 +168,17 @@ runWalletProcess
167168
-> WalletPath
168169
-> WalletArguments
169170
-> WalletRunner
171+
-> RunUpdateFunc
170172
-> UpdaterData
171173
-> IO ExitCode
172-
runWalletProcess logDep walletMode walletPath walletArguments walletRunner updaterData = do
174+
runWalletProcess
175+
logDep
176+
walletMode
177+
walletPath
178+
walletArguments
179+
walletRunner
180+
runUpdateFunc
181+
updaterData = do
173182

174183
-- Parametrized by @WalletMode@ so we can change it on restart depending
175184
-- on the Daedalus exit code.
@@ -180,6 +189,7 @@ runWalletProcess logDep walletMode walletPath walletArguments walletRunner updat
180189
walletPath
181190
walletArguments
182191
walletRunner
192+
runUpdateFunc
183193
updaterData
184194

185195
-- Additional arguments we need to pass if it's a SAFE mode.
@@ -225,7 +235,7 @@ runWalletProcess logDep walletMode walletPath walletArguments walletRunner updat
225235
-- We separate the description of the computation, from the computation itself.
226236
-- There are other ways of doing this, of course.
227237
isoFrom <$> handleDaedalusExitCode
228-
(UpdateRunner $ runUpdater RemoveArchiveAfterInstall runDefaultUpdateProcess logDep updaterData)
238+
(UpdateRunner $ runUpdater logDep RemoveArchiveAfterInstall runUpdateFunc updaterData)
229239
(RestartRunner restart)
230240
exitCode
231241

@@ -259,6 +269,35 @@ newtype TLSPath = TLSPath { getTLSFilePath :: FilePath }
259269
-- Functions
260270
--------------------------------------------------------------------------------
261271

272+
-- | The function that runs the launcher once everything is set up!
273+
runLauncher
274+
:: LoggingDependencies
275+
-> WalletRunner
276+
-> WalletPath
277+
-> WalletArguments
278+
-> RunUpdateFunc
279+
-> UpdaterData
280+
-> IO ExitCode
281+
runLauncher loggingDependencies walletRunner walletPath walletArgs runUpdateFunc updaterData = do
282+
283+
-- In the case the user wants to avoid installing the update now, we
284+
-- run the update (if there is one) when we have it downloaded.
285+
void $ runUpdater
286+
loggingDependencies
287+
RemoveArchiveAfterInstall
288+
runUpdateFunc
289+
updaterData
290+
291+
-- You still want to run the wallet even if the update fails
292+
runWalletProcess
293+
loggingDependencies
294+
WalletModeNormal
295+
walletPath
296+
walletArgs
297+
walletRunner
298+
runUpdateFunc
299+
updaterData
300+
262301
-- | Generation of the TLS certificates.
263302
-- This just covers the generation of the TLS certificates and nothing else.
264303
generateTlsCertificates

cardano-launcher/src/Cardano/Shell/Update/Lib.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module Cardano.Shell.Update.Lib
99
( UpdaterData (..)
10-
, RunCmdFunc
10+
, RunUpdateFunc
1111
, runUpdater
1212
, runDefaultUpdateProcess
1313
-- * Intepretable language
@@ -84,7 +84,7 @@ runDefaultUpdateProcess path args =
8484
$ \_in _out _err ph -> waitForProcess ph
8585

8686
-- The function for executing the update.
87-
type RunCmdFunc = FilePath -> [String] -> IO ExitCode
87+
type RunUpdateFunc = FilePath -> [String] -> IO ExitCode
8888

8989
-- | A flag for the existence of the updater file.
9090
data UpdaterExists
@@ -128,7 +128,7 @@ isUpdaterRunOnUnix (UnixRunUpdate _ _) = True
128128
isUpdaterRunOnUnix _ = False
129129

130130
-- | Interpret the small language into the "real" semantics.
131-
evaluateUpdaterCmdExitCode :: RunCmdFunc -> UpdaterCommand -> IO ExitCode
131+
evaluateUpdaterCmdExitCode :: RunUpdateFunc -> UpdaterCommand -> IO ExitCode
132132
evaluateUpdaterCmdExitCode runCommand = \case
133133
-- The update needs to be run on Windows.
134134
WindowsRunUpdate updaterPath args -> do
@@ -162,12 +162,12 @@ evaluateUpdaterCmdLogging loggingDep = \case
162162
-- first have to generate a @.bat@ file which will act as a script.
163163
-- After it being generated, you run that script.
164164
runUpdater
165-
:: RemoveArchiveAfterInstall
166-
-> RunCmdFunc
167-
-> LoggingDependencies
165+
:: LoggingDependencies
166+
-> RemoveArchiveAfterInstall
167+
-> RunUpdateFunc
168168
-> UpdaterData
169169
-> IO ExitCode
170-
runUpdater removeArchive runCommand loggingDep updaterData = do
170+
runUpdater loggingDep removeArchive runCommand updaterData = do
171171

172172
-- The update installation.
173173
let archivePath = udArchivePath updaterData

cardano-launcher/test/UpdaterSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ updaterSpec :: Spec
2424
updaterSpec = describe "Update system" $ do
2525
it "should be successful" $ monadicIO $ do
2626
exitCode <- run $ runUpdater
27+
nullLogging
2728
DoNotRemoveArchiveAfterInstall
2829
runDefaultUpdateProcess
29-
nullLogging
3030
testUpdaterData
3131

3232
run . putTextLn . show $ exitCode
3333
assert $ exitCode == ExitSuccess
3434

3535
prop "should return expected error" $ \(exitNum :: ExitNum) -> monadicIO $ do
3636
exitCode <- run $ runUpdater
37+
nullLogging
3738
DoNotRemoveArchiveAfterInstall
3839
(testRunCmd exitNum)
39-
nullLogging
4040
testUpdaterData
4141

4242
assert $ exitCode == (ExitFailure . getExitNum $ exitNum)

0 commit comments

Comments
 (0)