Skip to content

Commit

Permalink
Add post-checkout-command
Browse files Browse the repository at this point in the history
- Resolve haskell#6684:
- Resolve haskell#6813: Update (and correct) source-repository-package documentation
  • Loading branch information
phadej committed Sep 9, 2020
1 parent 784a43a commit 28057b5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 18 deletions.
9 changes: 7 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import Distribution.Simple.InstallDirs
( PathTemplate, fromPathTemplate
, toPathTemplate, substPathTemplate, initialPathTemplateEnv )
import Distribution.Simple.Utils
( die', warn, notice, info, createDirectoryIfMissingVerbose )
( die', warn, notice, info, createDirectoryIfMissingVerbose, rawSystemIOWithEnv )
import Distribution.Client.Utils
( determineNumJobs )
import Distribution.Utils.NubList
Expand Down Expand Up @@ -1172,7 +1172,12 @@ syncAndReadSourcePackagesRemoteRepos verbosity
syncSourceRepos verbosity vcs
[ (repo, repoPath)
| (repo, _, repoPath) <- repoGroupWithPaths ]
-- TODO phadej 2020-06-18 add post-sync script

-- Run post-checkout-command if it is specified
for_ repoGroupWithPaths $ \(repo, _, repoPath) ->
for_ (srpCommand repo) $ \(cmd :| args) -> liftIO $ do
exitCode <- rawSystemIOWithEnv verbosity cmd args (Just repoPath) Nothing Nothing Nothing Nothing
unless (exitCode /= ExitSuccess) $ exitWith exitCode

-- But for reading we go through each 'SourceRepo' including its subdir
-- value and have to know which path each one ended up in.
Expand Down
8 changes: 6 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,9 @@ legacyPackageConfigFieldDescrs =

legacyPackageConfigFGSectionDescrs
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
, c (Identity RepoType), c (List NoCommaFSep FilePathNT String)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
)
=> [FGSectionDescr g LegacyProjectConfig]
legacyPackageConfigFGSectionDescrs =
Expand Down Expand Up @@ -1253,7 +1255,9 @@ legacyPackageConfigSectionDescrs =

packageRepoSectionDescr
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
, c (Identity RepoType), c (List NoCommaFSep FilePathNT String)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
)
=> FGSectionDescr g LegacyProjectConfig
packageRepoSectionDescr = FGSectionDescr
Expand Down
17 changes: 12 additions & 5 deletions cabal-install/src/Distribution/Client/Types/SourceRepo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data SourceRepositoryPackage f = SourceRepositoryPackage
, srpTag :: !(Maybe String)
, srpBranch :: !(Maybe String)
, srpSubdir :: !(f FilePath)
, srpCommand :: !(Maybe (NonEmpty String))
}
deriving (Generic)

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

srpCommandLens :: Lens' (SourceRepositoryPackage f) (Maybe (NonEmpty String))
srpCommandLens f s = fmap (\x -> s { srpCommand = x }) (f (srpCommand s))
{-# INLINE srpCommandLens #-}

-------------------------------------------------------------------------------
-- Parser & PPrinter
-------------------------------------------------------------------------------
Expand All @@ -96,13 +101,15 @@ sourceRepositoryPackageGrammar
:: ( FieldGrammar c g, Applicative (g SourceRepoList)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
)
=> g SourceRepoList SourceRepoList
sourceRepositoryPackageGrammar = SourceRepositoryPackage
<$> uniqueField "type" srpTypeLens
<*> uniqueFieldAla "location" Token srpLocationLens
<*> optionalFieldAla "tag" Token srpTagLens
<*> optionalFieldAla "branch" Token srpBranchLens
<*> monoidalFieldAla "subdir" (alaList' NoCommaFSep FilePathNT) srpSubdirLens -- note: NoCommaFSep is somewhat important for roundtrip, as "." is there...
<$> uniqueField "type" srpTypeLens
<*> uniqueFieldAla "location" Token srpLocationLens
<*> optionalFieldAla "tag" Token srpTagLens
<*> optionalFieldAla "branch" Token srpBranchLens
<*> monoidalFieldAla "subdir" (alaList' NoCommaFSep FilePathNT) srpSubdirLens -- note: NoCommaFSep is somewhat important for roundtrip, as "." is there...
<*> optionalFieldAla "post-checkout-command" (alaNonEmpty' NoCommaFSep Token) srpCommandLens
{-# SPECIALIZE sourceRepositoryPackageGrammar :: ParsecFieldGrammar' SourceRepoList #-}
{-# SPECIALIZE sourceRepositoryPackageGrammar :: PrettyFieldGrammar' SourceRepoList #-}
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/VCS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ validatePDSourceRepo repo = do
, srpTag = PD.repoTag repo
, srpBranch = PD.repoBranch repo
, srpSubdir = PD.repoSubdir repo
, srpCommand = mempty
}
where
a ?! e = maybe (Left e) Right a
Expand Down
3 changes: 2 additions & 1 deletion changelog.d/documentation
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
synopsis: Documentation improvements
prs: #6971
prs: #6971 #7047
issues: #6813

description: {

Expand Down
3 changes: 3 additions & 0 deletions changelog.d/issue-6664-pre-sdist-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
synopsis: Add post-checkout-command to source-package-repository
issues: #6664
prs: #7047
32 changes: 24 additions & 8 deletions doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,7 @@ Specifying Packages from Remote Version Control Locations

Starting with Cabal 2.4, there is now a stanza
``source-repository-package`` for specifying packages from an external
version control which supports the following fields:

- :pkg-field:`source-repository:type`
- :pkg-field:`source-repository:location`
- :pkg-field:`source-repository:tag`
- :pkg-field:`source-repository:subdir`

A simple example is shown below:
version control.

.. code-block:: cabal
Expand All @@ -171,6 +164,29 @@ A simple example is shown below:
tag: 3d274c14ca3077c3a081ba7ad57c5182da65c8c1
subdir: cborg
source-repository-package
type: git
location: https://github.com/haskell/network.git
tag: e76fdc753e660dfa615af6c8b6a2ad9ddf6afe70
post-checkout-command: autoreconf -i
cabal-install 3.4 sdists the ``source-repository-package`` repositories and uses resulting tarballs as project packages.
This allows sharing of packages across different projects.

.. cfg-field:: type: VCS kind

.. cfg-field:: location: VCS location (usually URL)

.. cfg-field:: type: VCS tag

.. cfg-field:: subdir: subdirectory list

Use one or more subdirectories of the repository.

.. cfg-field:: post-checkout-command: command

Run command in the checked out repository, prior sdisting.

Global configuration options
----------------------------

Expand Down

0 comments on commit 28057b5

Please sign in to comment.