d51e3c7bee30bad6bd7b294d8a7b84a6e6e6d37e
[ghc.git] / hadrian / src / Hadrian / Builder / Tar.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : Hadrian.Builder.Tar
4 -- Copyright : (c) Andrey Mokhov 2014-2017
5 -- License : MIT (see the file LICENSE)
6 -- Maintainer : andrey.mokhov@gmail.com
7 -- Stability : experimental
8 --
9 -- Support for invoking the archiving utility @tar@.
10 -----------------------------------------------------------------------------
11 module Hadrian.Builder.Tar (TarMode (..), args) where
12
13 import Development.Shake
14 import Development.Shake.Classes
15 import GHC.Generics
16 import Hadrian.Expression
17
18 -- | Tar can be used to 'Create' an archive or 'Extract' from it.
19 data TarMode = Create | Extract deriving (Eq, Generic, Show)
20
21 instance Binary TarMode
22 instance Hashable TarMode
23 instance NFData TarMode
24
25 -- | Default command line arguments for invoking the archiving utility @tar@.
26 args :: (ShakeValue c, ShakeValue b) => TarMode -> Args c b
27 args Create = mconcat
28 [ arg "-c"
29 , output "//*.gz" ? arg "--gzip"
30 , output "//*.bz2" ? arg "--bzip2"
31 , output "//*.xz" ? arg "--xz"
32 , arg "-f", arg =<< getOutput
33 , getInputs ]
34 args Extract = mconcat
35 [ arg "-x"
36 , input "*.gz" ? arg "--gzip"
37 , input "*.bz2" ? arg "--bzip2"
38 , input "*.xz" ? arg "--xz"
39 , arg "-f", arg =<< getInput
40 , arg "-C", arg =<< getOutput ]