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

Brittany strips shebangs #192

Closed
pbrisbin opened this issue Oct 18, 2018 · 8 comments
Closed

Brittany strips shebangs #192

pbrisbin opened this issue Oct 18, 2018 · 8 comments
Labels

Comments

@pbrisbin
Copy link

% brittany --version
brittany version 0.11.0.0
Copyright (C) 2016-2018 Lennart Spitzner
There is NO WARRANTY, to the extent permitted by law.

Example

/tmp/script

#!/usr/bin/env stack
{- stack script --resolver lts -}
module Main where

import AnotherModule
import Data.Text

main :: IO ()
main = undefined

Expected

% brittany /tmp/script
#!/usr/bin/env stack
{- stack script --resolver lts -}
module Main where

import AnotherModule
import Data.Text

main :: IO ()
main = undefined

(Shebang preserved.)

Actual

% brittany /tmp/script

{- stack script --resolver lts -}
module Main where

import AnotherModule
import Data.Text

main :: IO ()
main = undefined

(The shebang was stripped.)


This makes brittany unusable for so-called "Stack Scripts", which are becoming quite popular.

@tfausak
Copy link
Collaborator

tfausak commented Jun 18, 2019

I think this is related to #92. I tried using both STDIN and a file; both worked. Can you try again and reopen this if it's still a problem? Thanks!

@tfausak tfausak closed this as completed Jun 18, 2019
@pbrisbin
Copy link
Author

pbrisbin commented Apr 10, 2020

I think this has regressed, specifically on usage with a file:

% stack exec brittany -- --version
brittany version 0.12.0.0
Copyright (C) 2016-2018 Lennart Spitzner
There is NO WARRANTY, to the extent permitted by law.
% stack exec brittany < ./scripts/hello
#!/usr/bin/env stack
-- stack script --resolver lts-15.4
-- vim: ft=haskell
module Main
  ( main
  )
where

main :: IO ()
main = putStrLn "Hello"
% stack exec brittany ./scripts/hello

-- stack script --resolver lts-15.4
-- vim: ft=haskell
module Main
  ( main
  )
where

main :: IO ()
main = putStrLn "Hello"

Can we re-open?

@tfausak tfausak reopened this Apr 10, 2020
@tfausak tfausak added the bug label Apr 10, 2020
@tfausak
Copy link
Collaborator

tfausak commented Jul 21, 2020

Seems like this has been fixed again:

# cat issue-192.hs 
#! /usr/bin/env stack
-- stack --resolver lts-16.0 script
main = pure ()

# brittany issue-192.hs 
#! /usr/bin/env stack
-- stack --resolver lts-16.0 script
main = pure ()

# brittany --version
brittany version 0.12.1.1
Copyright (C) 2016-2019 Lennart Spitzner
Copyright (C) 2019 PRODA LTD
There is NO WARRANTY, to the extent permitted by law.

@tfausak tfausak closed this as completed Jul 21, 2020
@pbrisbin
Copy link
Author

Nice, thanks!

@pbrisbin
Copy link
Author

👋 It's me again... This bug seems to still occur, but only if you invoke it with a certain kind of path.

% cat issue-192.hs
#!/usr/bin/env stack
-- stack --resolver lts-16.0 script
main = pure ()
% stack exec brittany -- --version
brittany version 0.12.1.1
Copyright (C) 2016-2019 Lennart Spitzner
Copyright (C) 2019 PRODA LTD
There is NO WARRANTY, to the extent permitted by law.
% stack exec brittany -- issue-192.hs
#!/usr/bin/env stack
-- stack --resolver lts-16.0 script
main = pure ()
% stack exec brittany -- ./issue-192.hs

-- stack --resolver lts-16.0 script#!/usr/bin/env stack

main = pure ()

So, issue-192.hs works, but ./issue-192.hs doesn't work.

The bug also triggers on absolute paths or relative paths outside the current directory, but only if you ./ prefix them as well.

% stack exec brittany -- x/issue-192.hs
#!/usr/bin/env stack
-- stack --resolver lts-16.0 script
main = pure ()
% stack exec brittany -- ./x/issue-192.hs

-- stack --resolver lts-16.0 script#!/usr/bin/env stack

main = pure ()
% stack exec brittany -- ../../brittany-repro/issue-192.hs

-- stack --resolver lts-16.0 script#!/usr/bin/env stack

main = pure ()

🤷

My editor plugin (ALE in vim) uses an absolute path to a tempfile, which is why the bug bites me so frequently.

@tfausak
Copy link
Collaborator

tfausak commented Aug 28, 2020

Oh dear. That's super weird.

@pbrisbin
Copy link
Author

pbrisbin commented Sep 13, 2020

FYI, this seems to be the root cause: alanz/ghc-exactprint#92 I got bit in HLint too (via apply-refact, via ghc-exact-print, which I believe Brittany uses as well).

@tfausak
Copy link
Collaborator

tfausak commented Nov 29, 2021

This has been fixed.

@tfausak tfausak closed this as completed Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants