4
4
{-# LANGUAGE RecordWildCards #-}
5
5
{-# LANGUAGE TupleSections #-}
6
6
{-# LANGUAGE ViewPatterns #-}
7
- module Distribution.Client.CmdSdist ( sdistCommand , sdistAction , packageToSdist ) where
7
+ module Distribution.Client.CmdSdist ( sdistCommand , sdistAction , packageToSdist , OutputFormat ( .. ), ArchiveFormat ( .. ) ) where
8
8
9
9
import Distribution.Client.CmdErrorMessages
10
10
( Plural (.. ), renderComponentKind )
@@ -101,10 +101,14 @@ sdistCommand = CommandUI
101
101
" Set the name of the cabal.project file to search for in parent directories"
102
102
sdistProjectFile (\ pf flags -> flags { sdistProjectFile = pf })
103
103
(reqArg " FILE" (succeedReadE Flag ) flagToList)
104
- , option [] [" list-only" ]
104
+ , option [' l ' ] [" list-only" ]
105
105
" Just list the sources, do not make a tarball"
106
106
sdistListSources (\ v flags -> flags { sdistListSources = v })
107
107
trueArg
108
+ , option [' z' ] [" null-sep" ]
109
+ " Separate the source files with NUL bytes rather than newlines."
110
+ sdistNulSeparated (\ v flags -> flags { sdistNulSeparated = v })
111
+ trueArg
108
112
, option [] [" archive-format" ]
109
113
" Choose what type of archive to create. No effect if given with '--list-only'"
110
114
sdistArchiveFormat (\ v flags -> flags { sdistArchiveFormat = v })
@@ -127,6 +131,7 @@ data SdistFlags = SdistFlags
127
131
, sdistDistDir :: Flag FilePath
128
132
, sdistProjectFile :: Flag FilePath
129
133
, sdistListSources :: Flag Bool
134
+ , sdistNulSeparated :: Flag Bool
130
135
, sdistArchiveFormat :: Flag ArchiveFormat
131
136
, sdistOutputPath :: Flag FilePath
132
137
}
@@ -137,6 +142,7 @@ defaultSdistFlags = SdistFlags
137
142
, sdistDistDir = mempty
138
143
, sdistProjectFile = mempty
139
144
, sdistListSources = toFlag False
145
+ , sditNulSeparated = toFlag False
140
146
, sdistArchiveFormat = toFlag TargzFormat
141
147
, sdistOutputPath = mempty
142
148
}
@@ -150,6 +156,7 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
150
156
mProjectFile = flagToMaybe sdistProjectFile
151
157
globalConfig = globalConfigFile globalFlags
152
158
listSources = fromFlagOrDefault False sdistListSources
159
+ nulSeparated = fromFlagOrDefault False sdistNulSeparated
153
160
archiveFormat = fromFlagOrDefault TargzFormat sdistArchiveFormat
154
161
mOutputPath = flagToMaybe sdistOutputPath
155
162
@@ -169,14 +176,19 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
169
176
Nothing -> return Nothing
170
177
171
178
let
172
- ext = case archiveFormat of
173
- TargzFormat -> " tar.gz"
174
- ZipFormat -> " zip"
175
-
179
+ format =
180
+ if | listSources, nulSeparated -> SourceList ' \n '
181
+ | listSources -> SourceList '\ 0 '
182
+ | otherwise -> Archive archiveFormat
183
+
184
+ ext = case format of
185
+ SourceList _ -> " list"
186
+ Archive TargzFormat -> " tar.gz"
187
+ Archive ZipFormat -> " zip"
188
+
176
189
outputPath pkg = case mOutputPath' of
177
190
Just path
178
191
| path == " -" -> " -"
179
- | listSources -> path </> prettyShow (packageId pkg) <.> " list"
180
192
| otherwise -> path </> prettyShow (packageId pkg) <.> ext
181
193
Nothing
182
194
| listSources -> " -"
@@ -187,15 +199,20 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
187
199
case reifyTargetSelectors localPkgs targetSelectors of
188
200
Left errs -> die' verbosity . unlines . fmap renderTargetProblem $ errs
189
201
Right pkgs
190
- | length pkgs > 1 , Just " -" <- mOutputPath' ->
202
+ | length pkgs > 1 , not listSources, Just " -" <- mOutputPath' ->
191
203
die' verbosity " Can't write multiple tarballs to standard output!"
192
- | otherwise -> mapM_ (\ pkg -> packageToSdist verbosity listSources archiveFormat (outputPath pkg) pkg) pkgs
204
+ | otherwise ->
205
+ mapM_ (\ pkg -> packageToSdist verbosity format (outputPath pkg) pkg) pkgs
193
206
194
207
data IsExec = Exec | NoExec
195
208
deriving (Show , Eq )
196
209
197
- packageToSdist :: Verbosity -> Bool -> ArchiveFormat -> FilePath -> UnresolvedSourcePackage -> IO ()
198
- packageToSdist verbosity listSources archiveFormat outputFile pkg = do
210
+ data OutputFormat = SourceList Char
211
+ | Archive ArchiveFormat
212
+ deriving (Show , Eq )
213
+
214
+ packageToSdist :: Verbosity -> OutputFormat -> FilePath -> UnresolvedSourcePackage -> IO ()
215
+ packageToSdist verbosity format outputFile pkg = do
199
216
dir <- case packageSource pkg of
200
217
LocalUnpackedPackage path -> return path
201
218
_ -> die' verbosity " The impossible happened: a local package isn't local"
@@ -208,10 +225,10 @@ packageToSdist verbosity listSources archiveFormat outputFile pkg = do
208
225
let write = if outputFile == " -" then BSL. putStr else BSL. writeFile outputFile
209
226
files = nub . sortOn snd $ nonexec ++ exec
210
227
211
- if
212
- | listSources -> do
228
+ case format of
229
+ SourceList nulSep -> do
213
230
notice verbosity $ " File manifest for package " ++ prettyShow (packageId pkg) ++ " :\n "
214
- write (BSL. pack . unlines . fmap snd $ files)
231
+ write (BSL. pack . ( ++ [nulSep]) . intercalate nulSep . fmap snd $ files)
215
232
| archiveFormat == TargzFormat -> do
216
233
let entriesM :: StateT (Set. Set FilePath ) (WriterT [Tar. Entry ] IO ) ()
217
234
entriesM = forM_ files $ \ (perm, file) -> do
0 commit comments