Skip to content

Commit 01b4f43

Browse files
authored
Merge pull request #3249 from commercialhaskell/extensible-snapshots
Extensible snapshots
2 parents e0a9bbb + d7c6cdc commit 01b4f43

Some content is hidden

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

92 files changed

+3869
-3330
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Release notes:
66

77
Major changes:
88

9+
* Complete overhaul of how snapshots are defined, the `packages` and
10+
`extra-deps` fields, and a number of related items. For full
11+
details, please see
12+
[the writeup on these changes](https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots). [PR #3249](https://github.com/commercialhaskell/stack/pull/3249),
13+
see the PR description for a number of related issues.
14+
915
Behavior changes:
1016

1117
* `stack profile` and `stack trace` now add their extra RTS arguments for

doc/custom_snapshot.md

Lines changed: 40 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,59 @@
11
# Custom Snapshots
22

3-
Custom snapshots allow you to create your own snapshots, which provide a list of
4-
specific hackage packages to use, along with flags and ghc-options. The
5-
definition of a basic snapshot looks like the following:
3+
Custom snapshots were totally reworked with the extensible snapshots
4+
overhaul in Stack 1.6.0, see
5+
[the writeup](https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots)
6+
and
7+
[PR #3249](https://github.com/commercialhaskell/stack/pull/3249)). This
8+
documentation covers the new syntax only.
9+
10+
Custom snapshots allow you to create your own snapshots, which provide
11+
a list of packages to use, along with flags, ghc-options, and a few
12+
other settings. Custom snapshots may extend any other snapshot that
13+
can be specified in a `resolver` field. The packages specified follow
14+
the syntax of `extra-deps` in the `stack.yaml` file, with one
15+
exception: to ensure reproducibility of snapshots, local directories
16+
are not allowed for custom snapshots (as they are expected to change
17+
regularly).
618

719
```yaml
8-
resolver: ghc-8.0
20+
resolver: lts-8.21 # Inherits GHC version and package set
21+
compiler: ghc-8.0.1 # Overwrites GHC version in the resolver, optional
922

23+
name: my-snapshot # User-friendly name
24+
25+
# Additional packages, follows extra-deps syntax
1026
packages:
11-
- unordered-containers-0.2.7.1
12-
- hashable-1.2.4.0
13-
- text-1.2.2.1
27+
- unordered-containers-0.2.7.1
28+
- hashable-1.2.4.0
29+
- text-1.2.2.1
1430

31+
# Override flags, can also override flags in the parent snapshot
1532
flags:
1633
unordered-containers:
1734
debug: true
35+
36+
# Packages from the parent snapshot to ignore
37+
drop-packages:
38+
- wai-extra
39+
40+
# Packages which should be hidden (affects script command's import
41+
# parser
42+
hidden:
43+
wai: true
44+
warp: false
45+
46+
# Set GHC options for specific packages
47+
ghc-options:
48+
warp:
49+
- -O2
1850
```
1951
2052
If you put this in a `snapshot.yaml` file in the same directory as your project,
2153
you can now use the custom snapshot like this:
2254

2355
```yaml
24-
resolver:
25-
name: simple-snapshot # Human readable name for the snapshot
26-
location: simple-snapshot.yaml
56+
resolver: snapshot.yaml
2757
```
2858

2959
This is an example of a custom snapshot stored in the filesystem. They are
@@ -38,24 +68,6 @@ For efficiency, URLs are treated differently. If I uploaded the snapshot to
3868
`https://domain.org/snapshot-1.yaml`, it is expected to be immutable. If you
3969
change that file, then you lose any reproducibility guarantees.
4070

41-
## Extending snapshots
42-
43-
The example custom snapshot above uses a compiler resolver, and so has few
44-
packages. We can also extend existing snapshots, by using the usual
45-
[resolver setting found in stack configurations](yaml_configuration.md#resolver).
46-
All possible resolver choices are valid, so this means that custom snapshots can
47-
even extend other custom snapshots.
48-
49-
Lets say that we want to use `lts-7.1`, but use a different version of `text`
50-
than the one it comes with, `1.2.2.1`. To downgrade it to `1.2.2.0`, we need a
51-
custom snapshot file with the following:
52-
53-
```yaml
54-
resolver: lts-7.1
55-
packages:
56-
- text-1.2.2.0
57-
```
58-
5971
### Overriding the compiler
6072

6173
The following snapshot specification will be identical to `lts-7.1`, but instead
@@ -117,57 +129,3 @@ ghc-options:
117129
text:
118130
developer: true
119131
```
120-
121-
## YAML format
122-
123-
In summary, the YAML format of custom snapshots has the following fields which
124-
are directly related to the same fields in the
125-
[build configuration format](yaml_configuration.md):
126-
127-
* `resolver`, which specifies which snapshot to extend. It takes the same values
128-
as the [`resolver` field in stack.yaml](yaml_configuration.md#resolver).
129-
130-
* `compiler`, which specifies or overrides the selection of compiler. If
131-
`resolver` is absent, then a specification of `compiler` is required. Its
132-
semantics are the same as the
133-
[`compiler` field in stack.yaml](yaml_configuration.md#compiler).
134-
135-
Some fields look similar, but behave differently:
136-
137-
* `flags` specifies which cabal flags to use with each package. In order to
138-
specify a flag for a package, it *must* be listed in the `packages` list.
139-
140-
* `ghc-options`, which specifies which cabal flags to use with each package. In
141-
order to specify ghc-options for a package, it *must* be listed in the
142-
`packages` list. The `*` member of the map specifies flags that apply to every
143-
package in the `packages` list.
144-
145-
There are two fields which work differently than in the build configuration
146-
format:
147-
148-
* `packages`, which specifies a list of hackage package versions. Note that
149-
when a package version is overridden, no `flags` or `ghc-options` are taken
150-
from the snapshot that is being extended. If you want the same options as the
151-
snapshot being extended, they must be re-specified.
152-
153-
* `drop-packages`, which specifies a list of packages to drop from the snapshot
154-
being overridden.
155-
156-
## Future enhancements
157-
158-
We plan to enhance extensible snapshots in several ways in the future. See
159-
[issue #1265, about "implicit snapshots"](https://github.com/commercialhaskell/stack/issues/1265).
160-
In summary, in the future:
161-
162-
1) It will be possible to use a specific git repository + commit hash in the
163-
`packages` list, like in regular stack.yaml configuration. Currently, custom
164-
snapshots only work with packages on hackage.
165-
166-
2) `stack.yaml` configurations will implicitly create a snapshot. This means
167-
that the non-local packages will get shared between your projects, so there is
168-
less redundant compilation!
169-
170-
3) `flags` and `ghc-options` for packages which are not listed in `packages` are
171-
silently ignored. See
172-
[#2654](https://github.com/commercialhaskell/stack/issues/2654) for the current
173-
status of this.

0 commit comments

Comments
 (0)