Skip to content

Commit 6118fd9

Browse files
authored
Merge pull request #7047 from phadej/source-repo-command
Add post-checkout-command
2 parents 695e95f + 4ed7261 commit 6118fd9

File tree

15 files changed

+76
-34
lines changed

15 files changed

+76
-34
lines changed

Cabal/src/Distribution/Compat/Prelude.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Distribution.Compat.Prelude (
7171
partition,
7272

7373
-- * Data.List.NonEmpty
74-
NonEmpty((:|)), foldl1, foldr1,
74+
NonEmpty((:|)), nonEmpty, foldl1, foldr1,
7575
head, tail, last, init,
7676

7777
-- * Data.Foldable
@@ -187,7 +187,7 @@ import Data.Function (on)
187187
import Data.Functor.Identity (Identity (..))
188188
import Data.Int (Int16, Int32, Int64, Int8)
189189
import Data.List (intercalate, intersperse, isPrefixOf, isSuffixOf, nub, nubBy, partition, sort, sortBy, unfoldr)
190-
import Data.List.NonEmpty (NonEmpty ((:|)), head, init, last, tail)
190+
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty, head, init, last, tail)
191191
import Data.Map (Map)
192192
import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, listToMaybe, mapMaybe, maybeToList)
193193
import Data.Ord (comparing)

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ import qualified Distribution.Simple.HaskellSuite as HaskellSuite
103103

104104
import Control.Exception
105105
( try )
106-
import Data.List.NonEmpty ( nonEmpty )
107106
import Distribution.Utils.Structured ( structuredDecodeOrFailIO, structuredEncode )
108107
import Distribution.Compat.Directory ( listDirectory )
109108
import Data.ByteString.Lazy ( ByteString )

Cabal/src/Distribution/Simple/SrcDist.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ allSourcesBuildInfo verbosity rip cwd bi pps modules = do
450450
-- file may show up in multiple paths due to a conditional;
451451
-- we need to package all of them. See #367.
452452
in findAllFilesCwdWithExtension cwd suffixes searchDirs file
453-
>>= nonEmpty (notFound module_) return
453+
>>= nonEmpty' (notFound module_) return
454454
| module_ <- modules ++ otherModules bi ]
455455
bootFiles <- sequenceA
456456
[ let file = ModuleName.toFilePath module_
@@ -462,8 +462,10 @@ allSourcesBuildInfo verbosity rip cwd bi pps modules = do
462462
cmmSources bi ++ asmSources bi ++ jsSources bi
463463

464464
where
465-
nonEmpty x _ [] = x
466-
nonEmpty _ f xs = f xs
465+
nonEmpty' :: b -> ([a] -> b) -> [a] -> b
466+
nonEmpty' x _ [] = x
467+
nonEmpty' _ f xs = f xs
468+
467469
suffixes = ppSuffixes pps ++ ["hs", "lhs", "hsig", "lhsig"]
468470

469471
notFound :: ModuleName -> IO [FilePath]

Cabal/src/Distribution/Types/VersionInterval.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ insertInterval :: VersionInterval -> VersionIntervals -> VersionIntervals
142142
insertInterval i is = unionVersionIntervals (VersionIntervals [i]) is
143143

144144
validInterval :: (LowerBound, UpperBound) -> Bool
145-
validInterval i@(l, u) = validLower l && validUpper u && nonEmpty i
145+
validInterval i@(l, u) = validLower l && validUpper u && nonEmptyVI i
146146
where
147147
validLower (LowerBound v _) = validVersion v
148148
validUpper NoUpperBound = True
149149
validUpper (UpperBound v _) = validVersion v
150150

151151
-- Check an interval is non-empty
152152
--
153-
nonEmpty :: VersionInterval -> Bool
154-
nonEmpty (_, NoUpperBound ) = True
155-
nonEmpty (LowerBound l lb, UpperBound u ub) =
153+
nonEmptyVI :: VersionInterval -> Bool
154+
nonEmptyVI (_, NoUpperBound ) = True
155+
nonEmptyVI (LowerBound l lb, UpperBound u ub) =
156156
(l < u) || (l == u && lb == InclusiveBound && ub == InclusiveBound)
157157

158158
-- Check an upper bound does not intersect, or even touch a lower bound:

cabal-install/src/Distribution/Client/List.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Distribution.Client.FetchUtils
6767
import Data.Bits ((.|.))
6868
import Data.List
6969
( maximumBy )
70-
import Data.List.NonEmpty (groupBy, nonEmpty)
70+
import Data.List.NonEmpty (groupBy)
7171
import qualified Data.List as L
7272
import Data.Maybe
7373
( fromJust )

cabal-install/src/Distribution/Client/ProjectConfig.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ import Distribution.Simple.InstallDirs
116116
( PathTemplate, fromPathTemplate
117117
, toPathTemplate, substPathTemplate, initialPathTemplateEnv )
118118
import Distribution.Simple.Utils
119-
( die', warn, notice, info, createDirectoryIfMissingVerbose )
119+
( die', warn, notice, info, createDirectoryIfMissingVerbose, rawSystemIOWithEnv )
120120
import Distribution.Client.Utils
121121
( determineNumJobs )
122122
import Distribution.Utils.NubList
@@ -1172,7 +1172,12 @@ syncAndReadSourcePackagesRemoteRepos verbosity
11721172
syncSourceRepos verbosity vcs
11731173
[ (repo, repoPath)
11741174
| (repo, _, repoPath) <- repoGroupWithPaths ]
1175-
-- TODO phadej 2020-06-18 add post-sync script
1175+
1176+
-- Run post-checkout-command if it is specified
1177+
for_ repoGroupWithPaths $ \(repo, _, repoPath) ->
1178+
for_ (nonEmpty (srpCommand repo)) $ \(cmd :| args) -> liftIO $ do
1179+
exitCode <- rawSystemIOWithEnv verbosity cmd args (Just repoPath) Nothing Nothing Nothing Nothing
1180+
unless (exitCode /= ExitSuccess) $ exitWith exitCode
11761181

11771182
-- But for reading we go through each 'SourceRepo' including its subdir
11781183
-- value and have to know which path each one ended up in.

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,9 @@ legacyPackageConfigFieldDescrs =
12241224

12251225
legacyPackageConfigFGSectionDescrs
12261226
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
1227-
, c (Identity RepoType), c (List NoCommaFSep FilePathNT String)
1227+
, c (Identity RepoType)
1228+
, c (List NoCommaFSep FilePathNT String)
1229+
, c (NonEmpty' NoCommaFSep Token String)
12281230
)
12291231
=> [FGSectionDescr g LegacyProjectConfig]
12301232
legacyPackageConfigFGSectionDescrs =
@@ -1253,7 +1255,9 @@ legacyPackageConfigSectionDescrs =
12531255

12541256
packageRepoSectionDescr
12551257
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
1256-
, c (Identity RepoType), c (List NoCommaFSep FilePathNT String)
1258+
, c (Identity RepoType)
1259+
, c (List NoCommaFSep FilePathNT String)
1260+
, c (NonEmpty' NoCommaFSep Token String)
12571261
)
12581262
=> FGSectionDescr g LegacyProjectConfig
12591263
packageRepoSectionDescr = FGSectionDescr

cabal-install/src/Distribution/Client/Types/SourceRepo.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data SourceRepositoryPackage f = SourceRepositoryPackage
3232
, srpTag :: !(Maybe String)
3333
, srpBranch :: !(Maybe String)
3434
, srpSubdir :: !(f FilePath)
35+
, srpCommand :: ![String]
3536
}
3637
deriving (Generic)
3738

@@ -88,6 +89,10 @@ srpSubdirLens :: Lens (SourceRepositoryPackage f) (SourceRepositoryPackage g) (f
8889
srpSubdirLens f s = fmap (\x -> s { srpSubdir = x }) (f (srpSubdir s))
8990
{-# INLINE srpSubdirLens #-}
9091

92+
srpCommandLensNE :: Lens' (SourceRepositoryPackage f) (Maybe (NonEmpty String))
93+
srpCommandLensNE f s = fmap (\x -> s { srpCommand = maybe [] toList x }) (f (nonEmpty (srpCommand s)))
94+
{-# INLINE srpCommandLensNE #-}
95+
9196
-------------------------------------------------------------------------------
9297
-- Parser & PPrinter
9398
-------------------------------------------------------------------------------
@@ -96,6 +101,7 @@ sourceRepositoryPackageGrammar
96101
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
97102
, c (Identity RepoType)
98103
, c (List NoCommaFSep FilePathNT String)
104+
, c (NonEmpty' NoCommaFSep Token String)
99105
)
100106
=> g SourceRepoList SourceRepoList
101107
sourceRepositoryPackageGrammar = SourceRepositoryPackage
@@ -104,5 +110,8 @@ sourceRepositoryPackageGrammar = SourceRepositoryPackage
104110
<*> optionalFieldAla "tag" Token srpTagLens
105111
<*> optionalFieldAla "branch" Token srpBranchLens
106112
<*> monoidalFieldAla "subdir" (alaList' NoCommaFSep FilePathNT) srpSubdirLens -- note: NoCommaFSep is somewhat important for roundtrip, as "." is there...
113+
<*> fmap (maybe [] toList) pcc
114+
where
115+
pcc = optionalFieldAla "post-checkout-command" (alaNonEmpty' NoCommaFSep Token) srpCommandLensNE
107116
{-# SPECIALIZE sourceRepositoryPackageGrammar :: ParsecFieldGrammar' SourceRepoList #-}
108117
{-# SPECIALIZE sourceRepositoryPackageGrammar :: PrettyFieldGrammar' SourceRepoList #-}

cabal-install/src/Distribution/Client/VCS.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ validatePDSourceRepo repo = do
127127
, srpTag = PD.repoTag repo
128128
, srpBranch = PD.repoBranch repo
129129
, srpSubdir = PD.repoSubdir repo
130+
, srpCommand = mempty
130131
}
131132
where
132133
a ?! e = maybe (Left e) Right a

cabal-install/tests/UnitTests/Distribution/Client/Get.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ testUnsupportedRepoType = do
106106
, srpTag = Nothing
107107
, srpBranch = Nothing
108108
, srpSubdir = Proxy
109+
, srpCommand = []
109110
}
110111
repotype = OtherRepoType "baz"
111112

@@ -184,6 +185,7 @@ testGitFetchFailed =
184185
, srpTag = Nothing
185186
, srpBranch = Nothing
186187
, srpSubdir = Proxy
188+
, srpCommand = []
187189
}
188190
pkgrepos = [(pkgidfoo, [repo])]
189191
e1 <- assertException $

0 commit comments

Comments
 (0)