@@ -41,7 +41,8 @@ module Distribution.Client.Config (
41
41
userConfigUpdate ,
42
42
createDefaultConfigFile ,
43
43
44
- remoteRepoFields
44
+ remoteRepoFields ,
45
+ postProcessRepo ,
45
46
) where
46
47
47
48
import Language.Haskell.Extension ( Language (Haskell2010 ) )
@@ -50,7 +51,7 @@ import Distribution.Deprecated.ViewAsFieldDescr
50
51
( viewAsFieldDescr )
51
52
52
53
import Distribution.Client.Types
53
- ( RemoteRepo (.. ), Username (.. ), Password (.. ), emptyRemoteRepo
54
+ ( RemoteRepo (.. ), LocalRepo ( .. ), Username (.. ), Password (.. ), emptyRemoteRepo
54
55
, AllowOlder (.. ), AllowNewer (.. ), RelaxDeps (.. ), isRelaxDeps
55
56
)
56
57
import Distribution.Client.BuildReports.Types
@@ -64,7 +65,7 @@ import Distribution.Client.Setup
64
65
, InstallFlags (.. ), installOptions , defaultInstallFlags
65
66
, UploadFlags (.. ), uploadCommand
66
67
, ReportFlags (.. ), reportCommand
67
- , showRepo , parseRepo , readRepo )
68
+ , showRemoteRepo , parseRemoteRepo , readRemoteRepo )
68
69
import Distribution.Client.CmdInstall.ClientInstallFlags
69
70
( ClientInstallFlags (.. ), defaultClientInstallFlags
70
71
, clientInstallOptions )
@@ -92,7 +93,7 @@ import Distribution.Deprecated.ParseUtils
92
93
, locatedErrorMsg , showPWarning
93
94
, readFields , warning , lineNo
94
95
, simpleField , listField , spaceListField
95
- , parseFilePathQ , parseOptCommaList , parseTokenQ )
96
+ , parseFilePathQ , parseOptCommaList , parseTokenQ , syntaxError )
96
97
import Distribution.Client.ParseUtils
97
98
( parseFields , ppFields , ppSection )
98
99
import Distribution.Client.HttpUtils
@@ -252,6 +253,7 @@ instance Semigroup SavedConfig where
252
253
globalRemoteRepos = lastNonEmptyNL globalRemoteRepos,
253
254
globalCacheDir = combine globalCacheDir,
254
255
globalLocalRepos = lastNonEmptyNL globalLocalRepos,
256
+ globalLocalNoIndexRepos = lastNonEmptyNL globalLocalNoIndexRepos,
255
257
globalLogsDir = combine globalLogsDir,
256
258
globalWorldFile = combine globalWorldFile,
257
259
globalRequireSandbox = combine globalRequireSandbox,
@@ -1034,7 +1036,7 @@ deprecatedFieldDescriptions :: [FieldDescr SavedConfig]
1034
1036
deprecatedFieldDescriptions =
1035
1037
[ liftGlobalFlag $
1036
1038
listField " repos"
1037
- (Disp. text . showRepo) parseRepo
1039
+ (Disp. text . showRemoteRepo) parseRemoteRepo
1038
1040
(fromNubList . globalRemoteRepos)
1039
1041
(\ rs cfg -> cfg { globalRemoteRepos = toNubList rs })
1040
1042
, liftGlobalFlag $
@@ -1117,19 +1119,25 @@ parseConfig src initial = \str -> do
1117
1119
let init0 = savedInitFlags config
1118
1120
user0 = savedUserInstallDirs config
1119
1121
global0 = savedGlobalInstallDirs config
1120
- (remoteRepoSections0, haddockFlags, initFlags, user, global, paths, args) <-
1122
+ (remoteRepoSections0, localRepoSections0, haddockFlags, initFlags, user, global, paths, args) <-
1121
1123
foldM parseSections
1122
- ([] , savedHaddockFlags config, init0, user0, global0, [] , [] )
1124
+ ([] , [] , savedHaddockFlags config, init0, user0, global0, [] , [] )
1123
1125
knownSections
1124
1126
1125
1127
let remoteRepoSections =
1126
1128
reverse
1127
1129
. nubBy ((==) `on` remoteRepoName)
1128
1130
$ remoteRepoSections0
1129
1131
1132
+ let localRepoSections =
1133
+ reverse
1134
+ . nubBy ((==) `on` localRepoName)
1135
+ $ localRepoSections0
1136
+
1130
1137
return . fixConfigMultilines $ config {
1131
1138
savedGlobalFlags = (savedGlobalFlags config) {
1132
1139
globalRemoteRepos = toNubList remoteRepoSections,
1140
+ globalLocalNoIndexRepos = toNubList localRepoSections,
1133
1141
-- the global extra prog path comes from the configure flag prog path
1134
1142
globalProgPathExtra = configProgramPathExtra (savedConfigureFlags config)
1135
1143
},
@@ -1185,68 +1193,92 @@ parseConfig src initial = \str -> do
1185
1193
parse = parseFields (configFieldDescriptions src
1186
1194
++ deprecatedFieldDescriptions) initial
1187
1195
1188
- parseSections (rs, h, i, u, g, p, a)
1189
- (ParseUtils. Section _ " repository" name fs) = do
1196
+ parseSections (rs, ls, h, i, u, g, p, a)
1197
+ (ParseUtils. Section lineno " repository" name fs) = do
1190
1198
r' <- parseFields remoteRepoFields (emptyRemoteRepo name) fs
1191
- when (remoteRepoKeyThreshold r' > length (remoteRepoRootKeys r')) $
1192
- warning $ " 'key-threshold' for repository " ++ show (remoteRepoName r')
1193
- ++ " higher than number of keys"
1194
- when (not (null (remoteRepoRootKeys r'))
1195
- && remoteRepoSecure r' /= Just True ) $
1196
- warning $ " 'root-keys' for repository " ++ show (remoteRepoName r')
1197
- ++ " non-empty, but 'secure' not set to True."
1198
- return (r': rs, h, i, u, g, p, a)
1199
-
1200
- parseSections (rs, h, i, u, g, p, a)
1199
+ r'' <- postProcessRepo lineno name r'
1200
+ case r'' of
1201
+ Left local -> return (rs, local: ls, h, i, u, g, p, a)
1202
+ Right remote -> return (remote: rs, ls, h, i, u, g, p, a)
1203
+
1204
+ parseSections (rs, ls, h, i, u, g, p, a)
1201
1205
(ParseUtils. F lno " remote-repo" raw) = do
1202
- let mr' = readRepo raw
1206
+ let mr' = readRemoteRepo raw
1203
1207
r' <- maybe (ParseFailed $ NoParse " remote-repo" lno) return mr'
1204
- return (r': rs, h, i, u, g, p, a)
1208
+ return (r': rs, ls, h, i, u, g, p, a)
1205
1209
1206
- parseSections accum@ (rs, h, i, u, g, p, a)
1210
+ parseSections accum@ (rs, ls, h, i, u, g, p, a)
1207
1211
(ParseUtils. Section _ " haddock" name fs)
1208
1212
| name == " " = do h' <- parseFields haddockFlagsFields h fs
1209
- return (rs, h', i, u, g, p, a)
1213
+ return (rs, ls, h', i, u, g, p, a)
1210
1214
| otherwise = do
1211
1215
warning " The 'haddock' section should be unnamed"
1212
1216
return accum
1213
1217
1214
- parseSections accum@ (rs, h, i, u, g, p, a)
1218
+ parseSections accum@ (rs, ls, h, i, u, g, p, a)
1215
1219
(ParseUtils. Section _ " init" name fs)
1216
1220
| name == " " = do i' <- parseFields initFlagsFields i fs
1217
- return (rs, h, i', u, g, p, a)
1221
+ return (rs, ls, h, i', u, g, p, a)
1218
1222
| otherwise = do
1219
1223
warning " The 'init' section should be unnamed"
1220
1224
return accum
1221
1225
1222
- parseSections accum@ (rs, h, i, u, g, p, a)
1226
+ parseSections accum@ (rs, ls, h, i, u, g, p, a)
1223
1227
(ParseUtils. Section _ " install-dirs" name fs)
1224
1228
| name' == " user" = do u' <- parseFields installDirsFields u fs
1225
- return (rs, h, i, u', g, p, a)
1229
+ return (rs, ls, h, i, u', g, p, a)
1226
1230
| name' == " global" = do g' <- parseFields installDirsFields g fs
1227
- return (rs, h, i, u, g', p, a)
1231
+ return (rs, ls, h, i, u, g', p, a)
1228
1232
| otherwise = do
1229
1233
warning " The 'install-paths' section should be for 'user' or 'global'"
1230
1234
return accum
1231
1235
where name' = lowercase name
1232
- parseSections accum@ (rs, h, i, u, g, p, a)
1236
+ parseSections accum@ (rs, ls, h, i, u, g, p, a)
1233
1237
(ParseUtils. Section _ " program-locations" name fs)
1234
1238
| name == " " = do p' <- parseFields withProgramsFields p fs
1235
- return (rs, h, i, u, g, p', a)
1239
+ return (rs, ls, h, i, u, g, p', a)
1236
1240
| otherwise = do
1237
1241
warning " The 'program-locations' section should be unnamed"
1238
1242
return accum
1239
- parseSections accum@ (rs, h, i, u, g, p, a)
1243
+ parseSections accum@ (rs, ls, h, i, u, g, p, a)
1240
1244
(ParseUtils. Section _ " program-default-options" name fs)
1241
1245
| name == " " = do a' <- parseFields withProgramOptionsFields a fs
1242
- return (rs, h, i, u, g, p, a')
1246
+ return (rs, ls, h, i, u, g, p, a')
1243
1247
| otherwise = do
1244
1248
warning " The 'program-default-options' section should be unnamed"
1245
1249
return accum
1246
1250
parseSections accum f = do
1247
1251
warning $ " Unrecognized stanza on line " ++ show (lineNo f)
1248
1252
return accum
1249
1253
1254
+ postProcessRepo :: Int -> String -> RemoteRepo -> ParseResult (Either LocalRepo RemoteRepo )
1255
+ postProcessRepo lineno reponame repo0 = do
1256
+ when (null reponame) $
1257
+ syntaxError lineno $ " a 'repository' section requires the "
1258
+ ++ " repository name as an argument"
1259
+
1260
+ case uriScheme (remoteRepoURI repo0) of
1261
+ -- TODO: check that there are no authority, query or fragment
1262
+ -- Note: the trailing colon is important
1263
+ " file+noindex:" -> do
1264
+ let uri = remoteRepoURI repo0
1265
+ return $ Left $ LocalRepo reponame (uriPath uri) (uriFragment uri == " #shared-cache" )
1266
+
1267
+ _ -> do
1268
+ let repo = repo0 { remoteRepoName = reponame }
1269
+
1270
+ when (remoteRepoKeyThreshold repo > length (remoteRepoRootKeys repo)) $
1271
+ warning $ " 'key-threshold' for repository "
1272
+ ++ show (remoteRepoName repo)
1273
+ ++ " higher than number of keys"
1274
+
1275
+ when (not (null (remoteRepoRootKeys repo)) && remoteRepoSecure repo /= Just True ) $
1276
+ warning $ " 'root-keys' for repository "
1277
+ ++ show (remoteRepoName repo)
1278
+ ++ " non-empty, but 'secure' not set to True."
1279
+
1280
+ return $ Right repo
1281
+
1250
1282
showConfig :: SavedConfig -> String
1251
1283
showConfig = showConfigWithComments mempty
1252
1284
@@ -1297,7 +1329,7 @@ installDirsFields = map viewAsFieldDescr installDirsOptions
1297
1329
1298
1330
ppRemoteRepoSection :: RemoteRepo -> RemoteRepo -> Doc
1299
1331
ppRemoteRepoSection def vals = ppSection " repository" (remoteRepoName vals)
1300
- remoteRepoFields (Just def) vals
1332
+ remoteRepoFields (Just def) vals
1301
1333
1302
1334
remoteRepoFields :: [FieldDescr RemoteRepo ]
1303
1335
remoteRepoFields =
0 commit comments