summaryrefslogtreecommitdiff
path: root/hadrian/src/Hadrian/Builder/Tar.hs
blob: d51e3c7bee30bad6bd7b294d8a7b84a6e6e6d37e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-----------------------------------------------------------------------------
-- |
-- Module     : Hadrian.Builder.Tar
-- Copyright  : (c) Andrey Mokhov 2014-2017
-- License    : MIT (see the file LICENSE)
-- Maintainer : andrey.mokhov@gmail.com
-- Stability  : experimental
--
-- Support for invoking the archiving utility @tar@.
-----------------------------------------------------------------------------
module Hadrian.Builder.Tar (TarMode (..), args) where

import Development.Shake
import Development.Shake.Classes
import GHC.Generics
import Hadrian.Expression

-- | Tar can be used to 'Create' an archive or 'Extract' from it.
data TarMode = Create | Extract deriving (Eq, Generic, Show)

instance Binary   TarMode
instance Hashable TarMode
instance NFData   TarMode

-- | Default command line arguments for invoking the archiving utility @tar@.
args :: (ShakeValue c, ShakeValue b) => TarMode -> Args c b
args Create = mconcat
    [ arg "-c"
    , output "//*.gz"  ? arg "--gzip"
    , output "//*.bz2" ? arg "--bzip2"
    , output "//*.xz"  ? arg "--xz"
    , arg "-f", arg =<< getOutput
    , getInputs ]
args Extract = mconcat
    [ arg "-x"
    , input "*.gz"  ? arg "--gzip"
    , input "*.bz2" ? arg "--bzip2"
    , input "*.xz"  ? arg "--xz"
    , arg "-f", arg =<< getInput
    , arg "-C", arg =<< getOutput ]