Skip to content

Commit 3c0ed2d

Browse files
committed
Add post-checkout-command
- Resolve #6684: - Resolve #6813: Update (and correct) source-repository-package documentation
1 parent 784a43a commit 3c0ed2d

File tree

12 files changed

+74
-31
lines changed

12 files changed

+74
-31
lines changed

cabal-install/cabal-install.cabal.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ Test-Suite unit-tests
403403
tasty-hunit >= 0.10,
404404
tasty-quickcheck,
405405
tree-diff,
406-
QuickCheck >= 2.14 && <2.15
406+
QuickCheck >= 2.14 && <2.15,
407+
quickcheck-instances >=0.3.24
407408

408409
-- Tests to run with a limited stack and heap size
409410
--

cabal-install/cabal-install.cabal.zinza

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ Test-Suite unit-tests
466466
tasty-hunit >= 0.10,
467467
tasty-quickcheck,
468468
tree-diff,
469-
QuickCheck >= 2.14 && <2.15
469+
QuickCheck >= 2.14 && <2.15,
470+
quickcheck-instances >=0.3.24
470471

471472
-- Tests to run with a limited stack and heap size
472473
--

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_ (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: 12 additions & 5 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 :: !(Maybe (NonEmpty 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+
srpCommandLens :: Lens' (SourceRepositoryPackage f) (Maybe (NonEmpty String))
93+
srpCommandLens f s = fmap (\x -> s { srpCommand = x }) (f (srpCommand s))
94+
{-# INLINE srpCommandLens #-}
95+
9196
-------------------------------------------------------------------------------
9297
-- Parser & PPrinter
9398
-------------------------------------------------------------------------------
@@ -96,13 +101,15 @@ 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
102-
<$> uniqueField "type" srpTypeLens
103-
<*> uniqueFieldAla "location" Token srpLocationLens
104-
<*> optionalFieldAla "tag" Token srpTagLens
105-
<*> optionalFieldAla "branch" Token srpBranchLens
106-
<*> monoidalFieldAla "subdir" (alaList' NoCommaFSep FilePathNT) srpSubdirLens -- note: NoCommaFSep is somewhat important for roundtrip, as "." is there...
108+
<$> uniqueField "type" srpTypeLens
109+
<*> uniqueFieldAla "location" Token srpLocationLens
110+
<*> optionalFieldAla "tag" Token srpTagLens
111+
<*> optionalFieldAla "branch" Token srpBranchLens
112+
<*> monoidalFieldAla "subdir" (alaList' NoCommaFSep FilePathNT) srpSubdirLens -- note: NoCommaFSep is somewhat important for roundtrip, as "." is there...
113+
<*> optionalFieldAla "post-checkout-command" (alaNonEmpty' NoCommaFSep Token) srpCommandLens
107114
{-# SPECIALIZE sourceRepositoryPackageGrammar :: ParsecFieldGrammar' SourceRepoList #-}
108115
{-# 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 = Nothing
109110
}
110111
repotype = OtherRepoType "baz"
111112

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

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Control.Applicative
1616
#endif
1717
import Data.Map (Map)
1818
import qualified Data.Map as Map
19+
import Data.List.NonEmpty (nonEmpty)
1920
import Data.List (isPrefixOf, intercalate, (\\))
2021
import Network.URI (URI)
2122

@@ -54,6 +55,7 @@ import Data.TreeDiff.Class
5455
import Data.TreeDiff.QuickCheck
5556
import Test.Tasty
5657
import Test.Tasty.QuickCheck
58+
import Test.QuickCheck.Instances ()
5759

5860
tests :: [TestTree]
5961
tests =
@@ -735,17 +737,15 @@ instance f ~ [] => Arbitrary (SourceRepositoryPackage f) where
735737
<*> (fmap getShortToken <$> arbitrary)
736738
<*> (fmap getShortToken <$> arbitrary)
737739
<*> (fmap getShortToken <$> shortListOf 3 arbitrary)
738-
739-
shrink (SourceRepositoryPackage x1 x2 x3 x4 x5) =
740-
[ SourceRepositoryPackage
741-
x1'
742-
(getShortToken x2')
743-
(fmap getShortToken x3')
744-
(fmap getShortToken x4')
745-
(fmap getShortToken x5')
746-
| (x1', x2', x3', x4', x5') <- shrink
747-
(x1, ShortToken x2, fmap ShortToken x3, fmap ShortToken x4, fmap ShortToken x5)
748-
]
740+
<*> (nonEmpty . fmap getShortToken <$> shortListOf 3 arbitrary)
741+
742+
shrink SourceRepositoryPackage {..} = runShrinker $ pure SourceRepositoryPackage
743+
<*> shrinker srpType
744+
<*> shrinkerAla ShortToken srpLocation
745+
<*> shrinkerAla (fmap ShortToken) srpTag
746+
<*> shrinkerAla (fmap ShortToken) srpBranch
747+
<*> shrinkerAla (fmap ShortToken) srpSubdir
748+
<*> shrinkerAla (fmap (fmap ShortToken)) srpCommand
749749

750750
instance Arbitrary RemoteRepo where
751751
arbitrary =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ prop_cloneRepo vcs mkVCSTestDriver repoRecipe =
215215
, srpTag = Just tagname
216216
, srpBranch = Nothing
217217
, srpSubdir = []
218+
, srpCommand = Nothing
218219
}
219220
verbosity = silent
220221

@@ -315,6 +316,7 @@ pickSyncTargetSets repoType repoState srcRepoPath dstReposPath =
315316
, srpTag = Just tag
316317
, srpBranch = Nothing
317318
, srpSubdir = Proxy
319+
, srpCommand = Nothing
318320
}
319321
(tag, workingState) = Map.elemAt tagIdx (allTags repoState)
320322
(tagIdx, prng') = randomR (0, Map.size (allTags repoState) - 1) prng

changelog.d/documentation

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
synopsis: Documentation improvements
2-
prs: #6971
2+
prs: #6971 #7047
3+
issues: #6813
34

45
description: {
56

0 commit comments

Comments
 (0)