Skip to content

Commit 2a1959a

Browse files
committed
Fix #5305 Extend stack script --extra-dep to any immutable extra-dep
1 parent 0ba1cef commit 2a1959a

12 files changed

+74
-18
lines changed

Diff for: ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Behavior changes:
1313
Other enhancements:
1414

1515
* Bump to Hpack 0.38.1.
16+
* The `--extra-dep` option of Stack's `script` command now accepts a YAML value
17+
specifying any immutable extra-dep. Previously only an extra-dep in the
18+
package index that could be specified by a YAML string (for example,
19+
`acme-missiles-0.3@rev:0`) was accepted.
1620

1721
Bug fixes:
1822

Diff for: doc/commands/script_command.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
stack script [--package PACKAGE] FILE
77
[-- ARGUMENT(S) (e.g. stack script X.hs -- argument(s) to program).]
88
[--compile | --optimize] [--[no-]use-root] [--ghc-options OPTIONS]
9-
[--extra-dep PACKAGE-VERSION] [--no-run]
9+
[--extra-dep EXTRA-DEP] [--no-run]
1010
~~~
1111

1212
The `stack script` command either runs a specified Haskell source file (using
@@ -52,9 +52,20 @@ For example:
5252
stack script --snapshot lts-23.14 MyScript.hs
5353
~~~
5454

55-
A package version can be added to the snapshot on the command line with the
55+
An immutable extra-dep can be added to the snapshot on the command line with the
5656
`--extra-dep` option (which can be specified multiple times).
5757

58+
An extra-dep is specified using a valid YAML value. For further information, see
59+
the [package location](../topics/package_location.md) documentation. Examples
60+
are:
61+
62+
* `--extra-dep acme-missiles-0.3@rev:0`
63+
* `--extra-dep '{git: [email protected]:yesodweb/wai, commit: '2f8a8e1b771829f4a8a77c0111352ce45a14c30f', subdirs: [auto-update, wai]}`
64+
* `--extra-dep acme-missiles-0.3.tar.gz`
65+
66+
Relative paths to local archive files are assumed to be relative to the
67+
directory in which the script file is located.
68+
5869
GHC boot packages that have been 'replaced' (see further below) can be specified
5970
as an `--extra-dep`.
6071

Diff for: doc/topics/scripts.md

+20
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ stack script --snapshot lts-23.14 -- MyScript.hs arg1 arg2 +RTS -s -RTS
139139
where `+RTS -s -RTS` are some of GHC's
140140
[runtime system (RTS) options](https://downloads.haskell.org/~ghc/latest/docs/users_guide/runtime_control.html).
141141

142+
Arguments that include spaces can be quoted using double quotation marks.
143+
142144
## Just-in-time compilation
143145

144146
As with using [`stack script`](../commands/script_command.md) at the command
@@ -169,6 +171,24 @@ options, or by providing a comma or space separated list. For example:
169171
-}
170172
~~~
171173

174+
## Using extra-deps
175+
176+
As with using [`stack script`](../commands/script_command.md) at the command
177+
line, you can also specify one or more extra-deps using a valid YAML value for
178+
each. For example:
179+
180+
~~~haskell
181+
#!/usr/bin/env stack
182+
{- stack script
183+
--snapshot lts-23.14
184+
--extra-dep acme-missiles-0.3@rev:0
185+
--extra-dep "{git: [email protected]:yesodweb/wai, commit: '2f8a8e1b771829f4a8a77c0111352ce45a14c30f', subdirs: [auto-update, wai]}"
186+
-}
187+
~~~
188+
189+
Relative paths to local archive files are assumed to be relative to the
190+
directory in which the script file is located.
191+
172192
## Stack configuration for scripts
173193

174194
When using the [`stack script`](../commands/script_command.md) command, as when

Diff for: package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ dependencies:
9999
- neat-interpolation
100100
- open-browser
101101
- optparse-applicative >= 0.18.1.0
102-
- pantry >= 0.10.0
102+
- pantry >= 0.10.1
103103
- path >= 0.9.5
104104
- path-io
105105
# In order for Cabal (the tool) to build Stack, it needs to be told of the

Diff for: src/Stack/Config.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ withBuildConfig inner = do
874874
where
875875
getEmptyProject ::
876876
Maybe RawSnapshotLocation
877-
-> [PackageIdentifierRevision]
877+
-> [RawPackageLocationImmutable]
878878
-> RIO Config Project
879879
getEmptyProject mSnapshot extraDeps = do
880880
snapshot <- case mSnapshot of
@@ -895,7 +895,7 @@ withBuildConfig inner = do
895895
pure Project
896896
{ userMsg = Nothing
897897
, packages = []
898-
, extraDeps = map (RPLImmutable . flip RPLIHackage Nothing) extraDeps
898+
, extraDeps = map RPLImmutable extraDeps
899899
, flagsByPkg = mempty
900900
, snapshot
901901
, compiler = Nothing

Diff for: src/Stack/Options/ScriptParser.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ scriptOptsParser = ScriptOpts
5858
))
5959
<*> many (option extraDepRead
6060
( long "extra-dep"
61-
<> metavar "PACKAGE-VERSION"
62-
<> help "Extra dependencies to be added to the snapshot."
61+
<> metavar "EXTRA-DEP"
62+
<> help "An immutable extra dependency to be added to the snapshot \
63+
\(can be specified multiple times)."
6364
))
6465
<*> ( flag' NoRun
6566
( long "no-run"
@@ -69,4 +70,4 @@ scriptOptsParser = ScriptOpts
6970
)
7071
where
7172
extraDepRead = eitherReader $
72-
mapLeft show . parsePackageIdentifierRevision . fromString
73+
mapLeft show . parseRawPackageLocationImmutables . fromString

Diff for: src/Stack/Script.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Stack.Script
1616
import Data.ByteString.Builder ( toLazyByteString )
1717
import qualified Data.ByteString.Char8 as S8
1818
import qualified Data.Conduit.List as CL
19+
import qualified Data.List.NonEmpty as NE
1920
import Data.List.Split ( splitWhen )
2021
import qualified Data.Map.Strict as Map
2122
import qualified Data.Set as Set
@@ -127,10 +128,9 @@ data ScriptOpts = ScriptOpts
127128
, compile :: !ScriptExecute
128129
, useRoot :: !Bool
129130
, ghcOptions :: ![String]
130-
, scriptExtraDeps :: ![PackageIdentifierRevision]
131+
, scriptExtraDeps :: ![Unresolved (NonEmpty RawPackageLocationImmutable)]
131132
, shouldRun :: !ShouldRun
132133
}
133-
deriving Show
134134

135135
-- | Run a Stack Script
136136
scriptCmd :: ScriptOpts -> RIO Runner ()
@@ -149,16 +149,20 @@ scriptCmd opts = do
149149

150150
file <- resolveFile' opts.file
151151
let scriptFile = filename file
152+
scriptRoot = parent file
152153

153154
isNoRunCompile <- fromFirstFalse . (.noRunCompile) <$>
154155
view (globalOptsL . to (.configMonoid))
155156

157+
resolvedExtraDeps <-
158+
mapM (resolvePaths (Just scriptRoot)) opts.scriptExtraDeps
156159
let scriptDir = parent file
160+
extraDeps = concatMap NE.toList resolvedExtraDeps
157161
modifyGO go = go
158162
{ configMonoid = go.configMonoid
159163
{ ConfigMonoid.installGHC = FirstTrue $ Just True
160164
}
161-
, stackYaml = SYLNoProject opts.scriptExtraDeps
165+
, stackYaml = SYLNoProject extraDeps
162166
}
163167
(shouldRun, shouldCompile) = if isNoRunCompile
164168
then (NoRun, SECompile)

Diff for: src/Stack/Types/ProjectConfig.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data ProjectConfig a
1616
| PCGlobalProject
1717
-- ^ No project was found when using 'SYLDefault'. Instead, use
1818
-- the implicit global.
19-
| PCNoProject ![PackageIdentifierRevision]
19+
| PCNoProject ![RawPackageLocationImmutable]
2020
-- ^ Use a no project run. This comes from 'SYLNoProject'.
2121

2222
-- | Yields 'True' only if the project configuration information is for the

Diff for: src/Stack/Types/StackYamlLoc.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data StackYamlLoc
1313
-- ^ Use the standard parent-directory-checking logic
1414
| SYLOverride !(Path Abs File)
1515
-- ^ Use a specific stack.yaml file provided
16-
| SYLNoProject ![PackageIdentifierRevision]
16+
| SYLNoProject ![RawPackageLocationImmutable]
1717
-- ^ Do not load up a project, just user configuration. Include
1818
-- the given extra dependencies with the snapshot.
1919
| SYLGlobalProject

Diff for: stack.cabal

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22

3-
-- This file has been generated from package.yaml by hpack version 0.38.0.
3+
-- This file has been generated from package.yaml by hpack version 0.38.1.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -439,7 +439,7 @@ library
439439
, neat-interpolation
440440
, open-browser
441441
, optparse-applicative >=0.18.1.0
442-
, pantry >=0.10.0
442+
, pantry >=0.10.1
443443
, path >=0.9.5
444444
, path-io
445445
, persistent >=2.14.0.0 && <2.15
@@ -562,7 +562,7 @@ executable stack
562562
, neat-interpolation
563563
, open-browser
564564
, optparse-applicative >=0.18.1.0
565-
, pantry >=0.10.0
565+
, pantry >=0.10.1
566566
, path >=0.9.5
567567
, path-io
568568
, persistent >=2.14.0.0 && <2.15
@@ -666,7 +666,7 @@ executable stack-integration-test
666666
, open-browser
667667
, optparse-applicative >=0.18.1.0
668668
, optparse-generic
669-
, pantry >=0.10.0
669+
, pantry >=0.10.1
670670
, path >=0.9.5
671671
, path-io
672672
, persistent >=2.14.0.0 && <2.15
@@ -783,7 +783,7 @@ test-suite stack-unit-test
783783
, neat-interpolation
784784
, open-browser
785785
, optparse-applicative >=0.18.1.0
786-
, pantry >=0.10.0
786+
, pantry >=0.10.1
787787
, path >=0.9.5
788788
, path-io
789789
, persistent >=2.14.0.0 && <2.15

Diff for: stack.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ snapshot: lts-23.14 # GHC 9.8.4
33
extra-deps:
44
# lts-23.14 provides hpack-0.37.0
55
- hpack-0.38.1
6+
# lts-23.14 provides pantry-0.10.0. See:
7+
# https://github.com/commercialhaskell/pantry/pull/142
8+
# This is temporary until pantry-0.10.1 is released.
9+
- git: https://github.com/commercialhaskell/pantry.git
10+
commit: d0d05e2b950189d2db023313e3edd1610a873dd5
611

712
docker:
813
enable: false

Diff for: stack.yaml.lock

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ packages:
1111
size: 3798
1212
original:
1313
hackage: hpack-0.38.1
14+
- completed:
15+
commit: d0d05e2b950189d2db023313e3edd1610a873dd5
16+
git: https://github.com/commercialhaskell/pantry.git
17+
name: pantry
18+
pantry-tree:
19+
sha256: 71c0a8d8999fc4dff290dc0dc2f2afc23b5a72a9996dc4988413920e3fc2f34d
20+
size: 3698
21+
version: 0.10.1
22+
original:
23+
commit: d0d05e2b950189d2db023313e3edd1610a873dd5
24+
git: https://github.com/commercialhaskell/pantry.git
1425
snapshots:
1526
- completed:
1627
sha256: 1964d439d2a152be4238053f3f997a09fb348391984daab86d724975ef9a423f

0 commit comments

Comments
 (0)