@@ -22,12 +22,13 @@ import GHC.Conc (getNumProcessors)
22
22
23
23
import Mafia.Bin
24
24
import Mafia.Cabal
25
+ import Mafia.Cache
25
26
import Mafia.Error
26
27
import Mafia.Ghc
27
28
import Mafia.Hoogle
28
29
import Mafia.IO
29
- import Mafia.Init
30
30
import Mafia.Include
31
+ import Mafia.Init
31
32
import Mafia.Install
32
33
import Mafia.Lock
33
34
import Mafia.Makefile
@@ -90,6 +91,8 @@ data MafiaCommand =
90
91
| MafiaWatch [Flag ] [GhciInclude ] File [Argument ]
91
92
| MafiaHoogle [Argument ]
92
93
| MafiaInstall [Constraint ] InstallPackage
94
+ | MafiaExport Profiling [Flag ] Directory
95
+ | MafiaImport Directory
93
96
| MafiaScript Path [Argument ]
94
97
| MafiaExec [Argument ]
95
98
| MafiaCFlags
@@ -148,6 +151,10 @@ run = \case
148
151
mafiaHoogle args
149
152
MafiaInstall constraints ipkg ->
150
153
mafiaInstall ipkg constraints
154
+ MafiaExport p flags dir ->
155
+ mafiaExport p flags dir
156
+ MafiaImport dir ->
157
+ mafiaImport dir
151
158
MafiaScript path args ->
152
159
mafiaScript path args
153
160
MafiaExec args ->
@@ -226,6 +233,12 @@ commands =
226
233
<> " The general usage is as follows: $(mafia install pretty-show)/ppsh" )
227
234
(MafiaInstall <$> many pConstraint <*> pInstallPackage)
228
235
236
+ , command' " export" " Export binary substitutes of the current package's dependencies."
237
+ (MafiaExport <$> pProfiling <*> many pFlag <*> pExportDirectory)
238
+
239
+ , command' " import" " Import binary substitutes from a directory."
240
+ (MafiaImport <$> pImportDirectory)
241
+
229
242
, command' " exec" " Exec the provided command line in the local cabal sandbox."
230
243
(MafiaExec <$> many pCabalArgs)
231
244
@@ -238,6 +251,18 @@ commands =
238
251
<> " developing across multiple source trees at once or loading "
239
252
<> " a not-yet-compiling package."
240
253
254
+ pExportDirectory :: Parser Directory
255
+ pExportDirectory =
256
+ argument textRead $
257
+ metavar " EXPORT_DIRECTORY"
258
+ <> help " The location to write binary substitute tarballs containing the current package's dependencies."
259
+
260
+ pImportDirectory :: Parser Directory
261
+ pImportDirectory =
262
+ argument textRead $
263
+ metavar " IMPORT_DIRECTORY"
264
+ <> help " The location to import binary substitute tarballs from."
265
+
241
266
pProfiling :: Parser Profiling
242
267
pProfiling =
243
268
flag DisableProfiling EnableProfiling $
@@ -529,6 +554,27 @@ mafiaInstall :: InstallPackage -> [Constraint] -> EitherT MafiaError IO ()
529
554
mafiaInstall ipkg constraints = do
530
555
liftIO . T. putStrLn =<< firstT MafiaBinError (installBinary ipkg constraints)
531
556
557
+ mafiaExport :: Profiling -> [Flag ] -> Directory -> EitherT MafiaError IO ()
558
+ mafiaExport p flags dir = do
559
+ initMafia LatestSources p flags
560
+ mkeys <- firstT MafiaInitError readPackageKeys
561
+ case mkeys of
562
+ Nothing ->
563
+ left MafiaNoPackageKeys
564
+ Just keys -> do
565
+ env <- firstT MafiaCacheError getCacheEnv
566
+ for_ keys $ \ key -> do
567
+ result <- firstT MafiaCacheError $ exportPackage env key dir
568
+ liftIO . T. putStrLn $ renderExportResult result
569
+
570
+ mafiaImport :: Directory -> EitherT MafiaError IO ()
571
+ mafiaImport dir = do
572
+ env <- firstT MafiaCacheError getCacheEnv
573
+ keys <- firstT MafiaCacheError $ listPackages env dir
574
+ for_ keys $ \ key -> do
575
+ result <- firstT MafiaCacheError $ importPackage env key dir
576
+ liftIO . T. putStrLn $ renderImportResult result
577
+
532
578
mafiaScript :: File -> [Argument ] -> EitherT MafiaError IO ()
533
579
mafiaScript file args =
534
580
firstT MafiaScriptError $ runScript file args
0 commit comments