6
6
{-# LANGUAGE ViewPatterns #-}
7
7
module Distribution.Client.CmdSdist
8
8
( sdistCommand , sdistAction , packageToSdist
9
- , SdistFlags (.. ), defaultSdistFlags
10
9
, OutputFormat (.. )) where
11
10
12
11
import Prelude ()
@@ -20,7 +19,7 @@ import Distribution.Client.TargetSelector
20
19
( TargetSelector (.. ), ComponentKind
21
20
, readTargetSelectors , reportTargetSelectorProblems )
22
21
import Distribution.Client.Setup
23
- ( GlobalFlags (.. ) )
22
+ ( GlobalFlags (.. ), InstallFlags ( installProjectFileName ) )
24
23
import Distribution.Solver.Types.SourcePackage
25
24
( SourcePackage (.. ) )
26
25
import Distribution.Client.Types
@@ -29,7 +28,11 @@ import Distribution.Client.DistDirLayout
29
28
( DistDirLayout (.. ), ProjectRoot (.. ) )
30
29
import Distribution.Client.ProjectConfig
31
30
( ProjectConfig , withProjectOrGlobalConfigIgn , commandLineFlagsToProjectConfig , projectConfigConfigFile , projectConfigShared )
31
+ import Distribution.Client.ProjectFlags
32
+ ( ProjectFlags (.. ), defaultProjectFlags , projectFlagsOptions )
32
33
34
+ import Distribution.Compat.Lens
35
+ ( _1 , _2 )
33
36
import Distribution.Package
34
37
( Package (packageId ) )
35
38
import Distribution.PackageDescription.Configuration
@@ -39,7 +42,7 @@ import Distribution.Pretty
39
42
import Distribution.ReadE
40
43
( succeedReadE )
41
44
import Distribution.Simple.Command
42
- ( CommandUI (.. ), option , reqArg )
45
+ ( CommandUI (.. ), OptionField , option , reqArg , liftOptionL , ShowOrParseArgs )
43
46
import Distribution.Simple.PreProcess
44
47
( knownSuffixHandlers )
45
48
import Distribution.Simple.Setup
@@ -78,7 +81,11 @@ import System.Directory
78
81
import System.FilePath
79
82
( (</>) , (<.>) , makeRelative , normalise , takeDirectory )
80
83
81
- sdistCommand :: CommandUI SdistFlags
84
+ -------------------------------------------------------------------------------
85
+ -- Command
86
+ -------------------------------------------------------------------------------
87
+
88
+ sdistCommand :: CommandUI (ProjectFlags , SdistFlags )
82
89
sdistCommand = CommandUI
83
90
{ commandName = " v2-sdist"
84
91
, commandSynopsis = " Generate a source distribution file (.tar.gz)."
@@ -87,41 +94,19 @@ sdistCommand = CommandUI
87
94
, commandDescription = Just $ \ _ -> wrapText
88
95
" Generates tarballs of project packages suitable for upload to Hackage."
89
96
, commandNotes = Nothing
90
- , commandDefaultFlags = defaultSdistFlags
97
+ , commandDefaultFlags = (defaultProjectFlags, defaultSdistFlags)
91
98
, commandOptions = \ showOrParseArgs ->
92
- [ optionVerbosity
93
- sdistVerbosity (\ v flags -> flags { sdistVerbosity = v })
94
- , optionDistPref
95
- sdistDistDir (\ dd flags -> flags { sdistDistDir = dd })
96
- showOrParseArgs
97
- , option [] [" project-file" ]
98
- " Set the name of the cabal.project file to search for in parent directories"
99
- sdistProjectFile (\ pf flags -> flags { sdistProjectFile = pf })
100
- (reqArg " FILE" (succeedReadE Flag ) flagToList)
101
- , option [' z' ] [" ignore-project" ]
102
- " Ignore local project configuration"
103
- sdistIgnoreProject (\ v flags -> flags { sdistIgnoreProject = v })
104
- trueArg
105
- , option [' l' ] [" list-only" ]
106
- " Just list the sources, do not make a tarball"
107
- sdistListSources (\ v flags -> flags { sdistListSources = v })
108
- trueArg
109
- , option [] [" null-sep" ]
110
- " Separate the source files with NUL bytes rather than newlines."
111
- sdistNulSeparated (\ v flags -> flags { sdistNulSeparated = v })
112
- trueArg
113
- , option [' o' ] [" output-directory" , " outputdir" ]
114
- " Choose the output directory of this command. '-' sends all output to stdout"
115
- sdistOutputPath (\ o flags -> flags { sdistOutputPath = o })
116
- (reqArg " PATH" (succeedReadE Flag ) flagToList)
117
- ]
99
+ map (liftOptionL _1) projectFlagsOptions ++
100
+ map (liftOptionL _2) (sdistOptions showOrParseArgs)
118
101
}
119
102
103
+ -------------------------------------------------------------------------------
104
+ -- Flags
105
+ -------------------------------------------------------------------------------
106
+
120
107
data SdistFlags = SdistFlags
121
108
{ sdistVerbosity :: Flag Verbosity
122
109
, sdistDistDir :: Flag FilePath
123
- , sdistProjectFile :: Flag FilePath
124
- , sdistIgnoreProject :: Flag Bool
125
110
, sdistListSources :: Flag Bool
126
111
, sdistNulSeparated :: Flag Bool
127
112
, sdistOutputPath :: Flag FilePath
@@ -131,17 +116,38 @@ defaultSdistFlags :: SdistFlags
131
116
defaultSdistFlags = SdistFlags
132
117
{ sdistVerbosity = toFlag normal
133
118
, sdistDistDir = mempty
134
- , sdistProjectFile = mempty
135
- , sdistIgnoreProject = toFlag False
136
119
, sdistListSources = toFlag False
137
120
, sdistNulSeparated = toFlag False
138
121
, sdistOutputPath = mempty
139
122
}
140
123
141
- --
142
-
143
- sdistAction :: SdistFlags -> [String ] -> GlobalFlags -> IO ()
144
- sdistAction SdistFlags {.. } targetStrings globalFlags = do
124
+ sdistOptions :: ShowOrParseArgs -> [OptionField SdistFlags ]
125
+ sdistOptions showOrParseArgs =
126
+ [ optionVerbosity
127
+ sdistVerbosity (\ v flags -> flags { sdistVerbosity = v })
128
+ , optionDistPref
129
+ sdistDistDir (\ dd flags -> flags { sdistDistDir = dd })
130
+ showOrParseArgs
131
+ , option [' l' ] [" list-only" ]
132
+ " Just list the sources, do not make a tarball"
133
+ sdistListSources (\ v flags -> flags { sdistListSources = v })
134
+ trueArg
135
+ , option [] [" null-sep" ]
136
+ " Separate the source files with NUL bytes rather than newlines."
137
+ sdistNulSeparated (\ v flags -> flags { sdistNulSeparated = v })
138
+ trueArg
139
+ , option [' o' ] [" output-directory" , " outputdir" ]
140
+ " Choose the output directory of this command. '-' sends all output to stdout"
141
+ sdistOutputPath (\ o flags -> flags { sdistOutputPath = o })
142
+ (reqArg " PATH" (succeedReadE Flag ) flagToList)
143
+ ]
144
+
145
+ -------------------------------------------------------------------------------
146
+ -- Action
147
+ -------------------------------------------------------------------------------
148
+
149
+ sdistAction :: (ProjectFlags , SdistFlags ) -> [String ] -> GlobalFlags -> IO ()
150
+ sdistAction (ProjectFlags {.. }, SdistFlags {.. }) targetStrings globalFlags = do
145
151
(baseCtx, distDirLayout) <- withProjectOrGlobalConfigIgn ignoreProject verbosity globalConfigFlag withProject withoutProject
146
152
147
153
let localPkgs = localPackages baseCtx
@@ -191,14 +197,14 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
191
197
listSources = fromFlagOrDefault False sdistListSources
192
198
nulSeparated = fromFlagOrDefault False sdistNulSeparated
193
199
mOutputPath = flagToMaybe sdistOutputPath
194
- ignoreProject = fromFlagOrDefault False sdistIgnoreProject
200
+ ignoreProject = fromFlagOrDefault False flagIgnoreProject
195
201
196
202
prjConfig :: ProjectConfig
197
203
prjConfig = commandLineFlagsToProjectConfig
198
204
globalFlags
199
205
mempty { configVerbosity = sdistVerbosity, configDistPref = sdistDistDir }
200
206
mempty
201
- mempty
207
+ mempty { installProjectFileName = flagProjectFileName }
202
208
mempty
203
209
mempty
204
210
mempty
0 commit comments