@@ -12,7 +12,7 @@ import Distribution.Client.ProjectConfig
12
12
( ProjectConfig (.. )
13
13
, projectConfigWithSolverRepoContext )
14
14
import Distribution.Client.Types
15
- ( Repo (.. ), RemoteRepo (.. ), maybeRepoRemote )
15
+ ( Repo (.. ), RemoteRepo (.. ), isRepoRemote )
16
16
import Distribution.Client.HttpUtils
17
17
( DownloadResult (.. ) )
18
18
import Distribution.Client.FetchUtils
@@ -25,17 +25,19 @@ import Distribution.Client.Setup
25
25
import Distribution.Simple.Setup
26
26
( HaddockFlags , fromFlagOrDefault , fromFlag )
27
27
import Distribution.Simple.Utils
28
- ( die' , notice , wrapText , writeFileAtomic , noticeNoWrap )
28
+ ( die' , notice , wrapText , writeFileAtomic , noticeNoWrap , intercalate )
29
29
import Distribution.Verbosity
30
30
( Verbosity , normal , lessVerbose )
31
31
import Distribution.Client.IndexUtils.Timestamp
32
32
import Distribution.Client.IndexUtils
33
33
( updateRepoIndexCache , Index (.. ), writeIndexTimestamp
34
34
, currentIndexTimestamp )
35
35
import Distribution.Text
36
- ( display )
36
+ ( Text (.. ), display , simpleParse )
37
+
38
+ import qualified Distribution.Compat.ReadP as ReadP
39
+ import qualified Text.PrettyPrint as Disp
37
40
38
- import Data.Maybe (mapMaybe )
39
41
import Control.Monad (unless , when )
40
42
import qualified Data.ByteString.Lazy as BS
41
43
import Distribution.Client.GZipUtils (maybeDecompress )
@@ -69,33 +71,66 @@ updateCommand = Client.installCommand {
69
71
++ " is very much appreciated.\n "
70
72
}
71
73
74
+ data UpdateRequest = UpdateRequest
75
+ { updateRequestRepoName :: String
76
+ , updateRequestRepoState :: IndexState
77
+ } deriving (Show )
78
+
79
+ instance Text UpdateRequest where
80
+ disp (UpdateRequest n s) = Disp. text n Disp. <> Disp. char ' @' Disp. <> disp s
81
+ parse = parseWithState ReadP. +++ parseHEAD
82
+ where parseWithState = do
83
+ name <- ReadP. many1 (ReadP. satisfy (\ c -> c /= ' @' ))
84
+ _ <- ReadP. char ' @'
85
+ state <- parse
86
+ return (UpdateRequest name state)
87
+ parseHEAD = do
88
+ name <- ReadP. manyTill (ReadP. satisfy (\ c -> c /= ' @' )) ReadP. eof
89
+ return (UpdateRequest name IndexStateHead )
90
+
72
91
updateAction :: (ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags )
73
92
-> [String ] -> GlobalFlags -> IO ()
74
93
updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
75
94
extraArgs globalFlags = do
76
- unless (null extraArgs) $
77
- die' verbosity $ " 'update' doesn't take any extra arguments: " ++ unwords extraArgs
78
95
79
96
ProjectBaseContext {
80
97
projectConfig
81
98
} <- establishProjectBaseContext verbosity cliConfig
82
99
83
100
projectConfigWithSolverRepoContext verbosity (projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
84
101
$ \ repoCtxt -> do
85
- let repos = repoContextRepos repoCtxt
86
- remoteRepos = mapMaybe maybeRepoRemote repos
102
+ let repos = filter isRepoRemote $ repoContextRepos repoCtxt
103
+ repoName = remoteRepoName . repoRemote
104
+ parseArg :: String -> IO UpdateRequest
105
+ parseArg s = case simpleParse s of
106
+ Just r -> pure r
107
+ Nothing -> die' verbosity $ " 'new-update' unable to parse repo: \" " ++ s ++ " \" "
108
+ updateRepoRequests <- mapM parseArg extraArgs
109
+
110
+ unless (null updateRepoRequests) $ do
111
+ let remoteRepoNames = map repoName repos
112
+ unknownRepos = [r | (UpdateRequest r _) <- updateRepoRequests
113
+ , not (r `elem` remoteRepoNames)]
114
+ unless (null unknownRepos) $
115
+ die' verbosity $ " 'new-update' repo(s): \" " ++ intercalate " \" , \" " unknownRepos
116
+ ++ " \" can not be found in known remote repo(s): " ++ intercalate " , " remoteRepoNames
117
+
118
+ let reposToUpdate = case updateRepoRequests of
119
+ [] -> repos
120
+ updateRequests -> let repoNames = map updateRequestRepoName updateRequests
121
+ in filter (\ r-> repoName r `elem` repoNames) repos
87
122
88
- case remoteRepos of
123
+ case reposToUpdate of
89
124
[] -> return ()
90
125
[remoteRepo] ->
91
126
notice verbosity $ " Downloading the latest package list from "
92
- ++ remoteRepoName remoteRepo
127
+ ++ repoName remoteRepo
93
128
_ -> notice verbosity . unlines
94
129
$ " Downloading the latest package lists from: "
95
- : map ((" - " ++ ) . remoteRepoName) remoteRepos
96
- jobCtrl <- newParallelJobControl (length repos )
97
- mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) repos
98
- mapM_ (\ _ -> collectJob jobCtrl) repos
130
+ : map ((" - " ++ ) . repoName) repos
131
+ jobCtrl <- newParallelJobControl (length reposToUpdate )
132
+ mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) reposToUpdate
133
+ mapM_ (\ _ -> collectJob jobCtrl) reposToUpdate
99
134
100
135
where
101
136
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
@@ -140,4 +175,5 @@ updateRepo verbosity updateFlags repoCtxt repo = do
140
175
when (current_ts /= nullTimestamp) $
141
176
noticeNoWrap verbosity $
142
177
" To revert to previous state run:\n " ++
143
- " cabal update --index-state='" ++ display current_ts ++ " '\n "
178
+ " cabal new-update '" ++ remoteRepoName (repoRemote repo) ++ " @" ++ display current_ts ++ " '\n "
179
+
0 commit comments