summaryrefslogtreecommitdiff
path: root/hadrian/src/Hadrian/Builder/Tar.hs
blob: 1d8f5025a5b7bd75a0f4cd620dfc8ad0e8e19f2c (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
41
42
43
-----------------------------------------------------------------------------
-- |
-- 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
import Oracles.Setting

-- | 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"
    , windowsHost ? arg "--force-local"
    , input "*.gz"  ? arg "--gzip"
    , input "*.bz2" ? arg "--bzip2"
    , input "*.xz"  ? arg "--xz"
    , arg "-f", arg =<< getInput
    , arg "-C", arg =<< getOutput ]