Skip to content

Commit a1e0f57

Browse files
committed
Fix #5305 Extend stack script --extra-dep to any immutable extra-dep
1 parent e4b026e commit a1e0f57

File tree

12 files changed

+59
-27
lines changed

12 files changed

+59
-27
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
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

doc/commands/script_command.md

Lines changed: 11 additions & 8 deletions
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,19 +52,22 @@ For example:
5252
stack script --snapshot lts-23.14 MyScript.hs
5353
~~~
5454

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

58-
Such an extra-dep can be specified using a valid YAML string value. For further
59-
information, see the [package location](../topics/package_location.md)
60-
documentation. Examples are:
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:
6161

6262
~~~text
63-
--extra-dep acme-missiles-0.3
6463
--extra-dep acme-missiles-0.3@rev:0
65-
--extra-dep acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1,613
64+
--extra-dep '{git: git@github.com:yesodweb/wai, commit: '2f8a8e1b771829f4a8a77c0111352ce45a14c30f', subdirs: [auto-update, wai]}
65+
--extra-dep acme-missiles-0.3.tar.gz
6666
~~~
6767

68+
Relative paths to local archive files are assumed to be relative to the
69+
directory in which the script file is located.
70+
6871
GHC boot packages that have been 'replaced' (see further below) can be specified
6972
as an `--extra-dep`.
7073

doc/topics/scripts.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,21 @@ options, or by providing a comma or space separated list. For example:
174174
## Using extra-deps
175175

176176
As with using [`stack script`](../commands/script_command.md) at the command
177-
line, you can also specify one or more extra-deps from the package index using a
178-
valid YAML string for each. For example:
177+
line, you can also specify one or more extra-deps using a valid YAML value for
178+
each. For example:
179179

180180
~~~haskell
181181
#!/usr/bin/env stack
182182
{- stack script
183183
--snapshot lts-23.14
184-
--extra-dep acme-missile-0.3@rev:0
184+
--extra-dep acme-missiles-0.3@rev:0
185+
--extra-dep "{git: git@github.com:yesodweb/wai, commit: '2f8a8e1b771829f4a8a77c0111352ce45a14c30f', subdirs: [auto-update, wai]}"
185186
-}
186187
~~~
187188

189+
Relative paths to local archive files are assumed to be relative to the
190+
directory in which the script file is located.
191+
188192
## Stack configuration for scripts
189193

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

package.yaml

Lines changed: 1 addition & 1 deletion
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

src/Stack/Config.hs

Lines changed: 2 additions & 2 deletions
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

src/Stack/Options/ScriptParser.hs

Lines changed: 4 additions & 3 deletions
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

src/Stack/Script.hs

Lines changed: 7 additions & 3 deletions
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)

src/Stack/Types/ProjectConfig.hs

Lines changed: 1 addition & 1 deletion
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

src/Stack/Types/StackYamlLoc.hs

Lines changed: 1 addition & 1 deletion
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

stack.cabal

Lines changed: 5 additions & 5 deletions
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

0 commit comments

Comments
 (0)