Skip to content

Commit c5f9933

Browse files
sheafMikolaj
authored andcommitted
Introduce SetupHooks
This commit introduces a new build-type, Hooks. A package using this build type should provide a SetupHooks.hs module which exports a value `setupHooks :: SetupHooks`. This is intended to replace the Custom setup type. This allows Cabal to have finer-grained information about the build, instead of having an opaque Setup executable to invoke. Tests include: - error when returning an invalid component diff in a per-component pre-configure hook - error when declaring pre-build rules whose dependency graph contains cycles - error when we cannot find a dependency of a pre-build rule - warning when there are pre-build rules that are declared but never demanded - correctness tests for SetupHooks, e.g. that pre-build rules are run in dependency order (see the `SetupHooksRuleOrdering` test)
1 parent b2a62b9 commit c5f9933

File tree

114 files changed

+4054
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+4054
-729
lines changed

Cabal-described/src/Distribution/Described.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ instance Described BenchmarkType where
355355
describe _ = "exitcode-stdio-1.0"
356356

357357
instance Described BuildType where
358-
describe _ = REUnion ["Simple","Configure","Custom","Make","Default"]
358+
describe _ = REUnion ["Simple","Configure","Custom","Hooks","Make","Default"]
359359

360360
instance Described CompilerFlavor where
361361
describe _ = REUnion

Cabal-hooks/Cabal-hooks.cabal

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cabal-version: 2.2
2+
name: Cabal-hooks
3+
version: 0.1
4+
copyright: 2023, Cabal Development Team
5+
license: BSD-3-Clause
6+
license-file: LICENSE
7+
author: Cabal Development Team <[email protected]>
8+
maintainer: [email protected]
9+
homepage: http://www.haskell.org/cabal/
10+
bug-reports: https://github.com/haskell/cabal/issues
11+
synopsis: API for the Hooks build-type
12+
description:
13+
User-facing API for the Hooks build-type.
14+
category: Distribution
15+
build-type: Simple
16+
17+
extra-source-files:
18+
readme.md changelog.md
19+
20+
source-repository head
21+
type: git
22+
location: https://github.com/haskell/cabal/
23+
subdir: Cabal-hooks
24+
25+
library
26+
default-language: Haskell2010
27+
hs-source-dirs: src
28+
29+
build-depends:
30+
Cabal-syntax >= 3.11 && < 3.13,
31+
Cabal >= 3.11 && < 3.13,
32+
base >= 4.9 && < 5,
33+
containers >= 0.5.0.0 && < 0.8,
34+
filepath >= 1.3.0.1 && < 1.5,
35+
transformers >= 0.5.6.0 && < 0.7
36+
37+
ghc-options: -Wall -fno-ignore-asserts -fwarn-tabs -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates
38+
39+
exposed-modules:
40+
Distribution.Simple.SetupHooks
41+
42+
other-extensions:
43+
BangPatterns
44+
CPP
45+
DefaultSignatures
46+
DeriveDataTypeable
47+
DeriveFoldable
48+
DeriveFunctor
49+
DeriveGeneric
50+
DeriveTraversable
51+
ExistentialQuantification
52+
FlexibleContexts
53+
FlexibleInstances
54+
GeneralizedNewtypeDeriving
55+
ImplicitParams
56+
KindSignatures
57+
LambdaCase
58+
NondecreasingIndentation
59+
OverloadedStrings
60+
PatternSynonyms
61+
RankNTypes
62+
RecordWildCards
63+
ScopedTypeVariables
64+
StandaloneDeriving
65+
Trustworthy
66+
TypeFamilies
67+
TypeOperators
68+
TypeSynonymInstances
69+
UndecidableInstances

Cabal-hooks/LICENSE

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Copyright (c) 2003-2023, Cabal Development Team.
2+
See the AUTHORS file for the full list of copyright holders.
3+
4+
See */LICENSE for the copyright holders of the subcomponents.
5+
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are
10+
met:
11+
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
15+
* Redistributions in binary form must reproduce the above
16+
copyright notice, this list of conditions and the following
17+
disclaimer in the documentation and/or other materials provided
18+
with the distribution.
19+
20+
* Neither the name of Isaac Jones nor the names of other
21+
contributors may be used to endorse or promote products derived
22+
from this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Cabal-hooks/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog for `Cabal-hooks`
2+
3+
## 0.1 – December 2023
4+
5+
* Initial release of the `Hooks` API.
6+

Cabal-hooks/readme.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# `Cabal-hooks`
2+
3+
This library provides an API for the `Cabal` `Hooks` build type.
4+
5+
## What is the `Hooks` build type?
6+
7+
The `Hooks` build type is a new `Cabal` build type that is scheduled to
8+
replace the `Custom` build type, providing better integration with
9+
the rest of the Haskell ecosystem.
10+
11+
The original specification for the `Hooks` build type can be found in
12+
the associated [Haskell Foundation Tech Proposal](https://github.com/haskellfoundation/tech-proposals/pull/60).
13+
14+
These *setup hooks* allow package authors to customise the configuration and
15+
building of a package by providing certain hooks that get folded into the
16+
general package configuration and building logic within `Cabal`.
17+
18+
## Defining a package with custom hooks
19+
20+
To use the `Hooks` build type, you will need to
21+
22+
* Update your `.cabal` file by:
23+
24+
- using `cabal-version >= 3.14`,
25+
- declaring `build-type: Hooks`,
26+
- declaring a `custom-setup` stanza, with a `setup-depends`
27+
field which includes a dependency on `Cabal-hooks`.
28+
29+
* Define a Haskell module `SetupHooks`, which must be placed
30+
at the root of your project and must define a value
31+
`setupHooks :: SetupHooks`.
32+
33+
That is, your `.cabal` file should contain the following
34+
35+
```cabal
36+
-- my-package.cabal
37+
cabal-version: 3.14
38+
name: my-package
39+
build-type: Hooks
40+
41+
custom-setup
42+
setup-depends:
43+
Cabal-hooks >= 0.1 && < 0.2
44+
```
45+
46+
and your `SetupHooks.hs` file should look like:
47+
48+
```haskell
49+
-- SetupHooks.hs
50+
module SetupHooks ( setupHooks ) where
51+
52+
-- Cabal-hooks
53+
import Distribution.Simple.SetupHooks
54+
55+
setupHooks :: SetupHooks
56+
setupHooks = ...
57+
-- use the API provided by 'Distribution.Simple.SetupHooks'
58+
-- to define the hooks relevant to your package
59+
```
60+
61+
## Using the API
62+
63+
The [Haddock documentation](https://hackage.haskell.org/package/Cabal-hooks)
64+
should help you get started using this library's API.

0 commit comments

Comments
 (0)