Skip to content
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

Add support to only compile script using stack shebang #5755

Closed
brandonchinn178 opened this issue May 18, 2022 · 3 comments
Closed

Add support to only compile script using stack shebang #5755

brandonchinn178 opened this issue May 18, 2022 · 3 comments

Comments

@brandonchinn178
Copy link

brandonchinn178 commented May 18, 2022

I have a file

#!/usr/bin/env stack
{- stack script --resolver ... --package ... -}

and running ./Script.hs or stack Script.hs works as expected. But I would like to have a CI job checking that Script.hs builds (but not runs). I do see stack script has a --no-run flag, but it seems like I would have to copy the entire stack script command to do so:

stack script --compile --no-run Script.hs --resolver ... --package ...

Doing stack Script.hs --no-run or stack script Script.hs --no-run would fail; the first would pass --no-run as an argument to Script.hs, and the second would fail with "script requires --resolver".

The most straightforward way I see here is to add a STACK_INTERPRETER_NO_RUN=true env var that will add the --no-run flag to stack script and the appropriate flags to stack runghc.

@brandonchinn178 brandonchinn178 changed the title Add support to only compile script using script interpreter Add support to only compile script using stack shebang May 18, 2022
@mpilgrem
Copy link
Member

The current online help explains:

With the release of Stack 1.4.0, there is a new command, script, which will automatically:

  • Install GHC and libraries if missing
  • Require that all packages used be explicitly stated on the command line

This ensures that your scripts are independent of any prior deployment specific configuration, and are reliable by using exactly the same version of all packages every time it runs so that the script does not break by accidentally using incompatible package versions.

Rather than an environment variable, how about an additional flag for stack script that specifies that the script interepter options comment is to be used and not ignored (something like --use-options-comment) (disabled by default)?

@mpilgrem
Copy link
Member

I thought further about this. I have a potential pull request that does the following: if new global flag --force-script-no-run-compile is enabled (disabled by default) it forces the options --no-run --compile on stack script.

So, for example, if you have a script Script.hs:

{- stack script
   --resolver lts-19.9
   --package acme-missiles
-}
import Acme.Missiles (launchMissiles)

main :: IO ()
main = launchMissiles

If you use:

 stack --force-script-no-run-compile Script.hs

then that gets translated (by stack, behind the scenes) into:

stack --force-script-no-run-compile script --resolver lts-19.9 --package acme-missiles -- Script.hs

which is then forced (by my pull request) to be the equivalent of having asked for:

stack script --resolver lts-19.9 --package acme-missiles --no-run --compile -- Script.hs

mpilgrem added a commit to mpilgrem/stack that referenced this issue May 30, 2022
Adds a `--force-script-no-run-compile` flag (disabled by default) that forces the `--no-run` and `--compile` options with `stack script`.

This enables a command like `stack --force-script-no-run-compile Script.hs` to behave like `stack script ... --no-run --compile -- Script.hs` but without having to list all the other arguments in the stack interpreter options comment (represented by `...`) on the command line.
mpilgrem added a commit to mpilgrem/stack that referenced this issue May 31, 2022
Adds a `--force-script-no-run-compile` flag (disabled by default) that forces the `--no-run` and `--compile` options with `stack script`.

This enables a command like `stack --force-script-no-run-compile Script.hs` to behave like `stack script ... --no-run --compile -- Script.hs` but without having to list all the other arguments in the stack interpreter options comment (represented by `...`) on the command line.

Also adds an explanation to the online documentation.
mpilgrem added a commit that referenced this issue Jun 11, 2022
Fix #5755 Add --script-no-run-compile flag
@mpilgrem
Copy link
Member

The option - now named --script-no-run-compile - has been added to the current source code for stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants