-
Notifications
You must be signed in to change notification settings - Fork 710
Add support for cabal.project fields to scripts #7997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aebe39a
2910b62
389ee62
a2580fa
f94ff6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# cabal v2-run | ||
Resolving dependencies... | ||
Build profile: -w ghc-<GHCVER> -O2 | ||
In order, the following will be built: | ||
- fake-package-0 (exe:cabal-script-s.hs) (first run) | ||
Configuring executable 'cabal-script-s.hs' for fake-package-0.. | ||
Building executable 'cabal-script-s.hs' for fake-package-0.. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = cabalTest $ do | ||
-- script is called "s.hs" to avoid Windows long path issue in CI | ||
res <- cabal' "v2-run" ["s.hs"] | ||
assertOutputContains "Hello World" res | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env cabal | ||
{- cabal: | ||
build-depends: base | ||
-} | ||
{- project: | ||
optimization: 2 | ||
-} | ||
|
||
main :: IO () | ||
main = putStrLn "Hello World" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
synopsis: Better support for scripts | ||
packages: cabal-install | ||
prs: #7851 #7925 #7938 #7990 | ||
issues: #7842 #7073 #6354 #6149 #5508 | ||
prs: #7851 #7925 #7938 #7990 #7997 | ||
issues: #7842 #7073 #6354 #6149 #5508 #5698 | ||
|
||
description: { | ||
|
||
|
@@ -15,5 +15,7 @@ description: { | |
- The name of the generated script executable has been changed from "script" to | ||
"cabal-script-<your-sanitized-script-name>" for easier process management. | ||
- Reduce the default verbosity of scripts, so that the build output doesn't interfere with the script output. | ||
- Scripts now support a project metadata block that allows them to use options | ||
that would normally be set in a cabal.project file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
a note in docs about that would be enough imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And an issue about adding such validation would be great too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an issue: #8024 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many thanks, a really good recap, maybe it worths to link the issue in the doc note (as list all the problematic fields would be too verbose) |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,13 +436,15 @@ See `the v2-build section <#cabal-v2-build>`__ for the target syntax. | |
|
||
When ``TARGET`` is one of the following: | ||
|
||
- A component target: execute the specified executable, benchmark or test suite | ||
- A component target: execute the specified executable, benchmark or test suite. | ||
|
||
- A package target: | ||
1. If the package has exactly one executable component, it will be selected. | ||
2. If the package has multiple executable components, an error is raised. | ||
3. If the package has exactly one test or benchmark component, it will be selected. | ||
4. Otherwise an issue is raised | ||
4. Otherwise an issue is raised. | ||
|
||
- The path to a script: execute the script at the path. | ||
|
||
- Empty target: Same as package target, implicitly using the package from the current | ||
working directory. | ||
|
@@ -458,28 +460,38 @@ have to separate them with ``--``. | |
|
||
$ cabal v2-run target -- -a -bcd --argument | ||
|
||
``v2-run`` also supports running script files that use a certain format. With | ||
a script that looks like: | ||
``v2-run`` supports running script files that use a certain format. | ||
Scripts look like: | ||
|
||
:: | ||
|
||
#!/usr/bin/env cabal | ||
{- cabal: | ||
build-depends: base ^>= 4.11 | ||
, shelly ^>= 1.8.1 | ||
build-depends: base ^>= 4.14 | ||
, shelly ^>= 1.10 | ||
-} | ||
{- project: | ||
with-compiler: ghc-8.10.7 | ||
-} | ||
|
||
main :: IO () | ||
main = do | ||
... | ||
|
||
It can either be executed like any other script, using ``cabal`` as an | ||
interpreter, or through this command: | ||
Where there cabal metadata block is mandatory and contains fields from a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This interjects the sentences "With a script that looks like: ... It can either be executed like any other script..." and the context is lost before we get to "It can either". Perhaps change the initial sentence to "A script may looks like this:", then your interjection, then "The script can either be executed like any other script...". |
||
package executable block, and the project metadata block is optional and | ||
contains fields that would be in the cabal.project file in a regular project. | ||
|
||
Only some fields are supported in the metadata blocks, and these fields are | ||
currently not validated. See | ||
`#8024 <https://github.com/haskell/cabal/issues/8024>`__ for details. | ||
|
||
A script can either be executed directly using `cabal` as an interpreter or | ||
with the command: | ||
|
||
:: | ||
|
||
$ cabal v2-run path/to/script | ||
$ cabal v2-run path/to/script -- --arg1 # args are passed like this | ||
|
||
The executable is cached under the cabal directory, and can be pre-built with | ||
``cabal v2-build path/to/script`` and the cache can be removed with | ||
|
Uh oh!
There was an error while loading. Please reload this page.