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 shell and dependency-shell attributes to bios cradle type #188

Merged
merged 2 commits into from
Jun 8, 2020

Conversation

hyperfekt
Copy link
Contributor

@hyperfekt hyperfekt commented May 21, 2020

This changes readProcessWithOutputFile to take a createProcess datatype instead of a program with arguments so the bios cradle type can pass in a shell command.
I tried to avoid additional imports. Please feel free to make changes as you see fit, ask questions or give feedback.

Fixes #158.

@hyperfekt hyperfekt force-pushed the shell branch 3 times, most recently from c5f90f3 to 47f17ef Compare May 21, 2020 18:43
@fendor fendor requested review from fendor, mpickering and jneira and removed request for fendor May 21, 2020 18:47
@fendor
Copy link
Collaborator

fendor commented May 21, 2020

Awesome!
I am interested on how well this works on windows. If this works on windows, can we maybe get a test for windows as well?

@hyperfekt
Copy link
Contributor Author

hyperfekt commented May 21, 2020

The project test I added is intended to work on Windows, too, but I have no way to actually run it.

EDIT: Looks like Windows CI succeeded.

@jneira
Copy link
Member

jneira commented May 21, 2020

Hi! first of all, great work, the pr looks good but not sure if the test case is correct: in windows shells you have to refer to en vars with %HIE_BIOS_OUTPUT%, not $HIE_BIOS_OUTPUT.
So i am not sure if the test had to be succesful in windows.
Consider the shell session:

PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> dir -name
A.hs
B.hs
hie.yaml
PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> hie-bios debug .\A.hs    
Root directory:      D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell
Component directory: D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell
GHC options:
System libraries:    D:\bin\stack\x86_64-windows\ghc-8.8.3\lib
Config Location:     D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell\hie.yaml
Cradle:              Cradle {cradleRootDir = "D:\\dev\\ws\\haskell\\hie-bios\\tests\\projects\\simple-bios-shell", cradleOptsProg = CradleAction: Bios}
Dependencies:
PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> dir -name
$HIE_BIOS_OUTPUT
A.hs
B.hs
hie.yaml
PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> cat `$HIE_BIOS_OUTPUT
"-Wall"  
"A"  
"B"

Simply changing to the correct dos syntax make it work (well the double quotes are a litle bit weird but whatever) , so the code is correct:

PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> cat .\hie.yaml
cradle:
  bios: {shell: 'echo "-Wall" >> %HIE_BIOS_OUTPUT% && echo "A" >> %HIE_BIOS_OUTPUT% && echo "B" >> %HIE_BIOS_OUTPUT%' }      
PS D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell> hie-bios debug .\A.hs   
Root directory:      D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell
Component directory: D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell
GHC options:         ""-Wall"  " ""A"  " ""B" "
System libraries:    D:\bin\stack\x86_64-windows\ghc-8.8.3\lib
Config Location:     D:\dev\ws\haskell\hie-bios\tests\projects\simple-bios-shell\hie.yaml
Cradle:              Cradle {cradleRootDir = "D:\\dev\\ws\\haskell\\hie-bios\\tests\\projects\\simple-bios-shell", cradleOptsProg = CradleAction: Bios}
Dependencies:

But i am a liitle bit worried by the fact that the test should have failed

@jneira
Copy link
Member

jneira commented May 21, 2020

And it shows one of the shortcomings of the cradle: in general, you will need one version for each type of shell you want to support.
But it is not related with the pr 😄

@hyperfekt
Copy link
Contributor Author

This little trick should allow using both Windows-specific and POSIX commands in one command string. I have no idea why the test was passing though or even what exactly its conditions are, since I just blindly adapted it from the others. Maybe the project tests aren't really as thorough as thought?

@jneira
Copy link
Member

jneira commented May 25, 2020

@hyperfekt i think those tests dont check the compiler args returned by the cradle, only that loading the cradle returns CradleSuccess (maybe @fendor could confirm that):

https://github.com/mpickering/hie-bios/blob/6ab59efaa40438c96dc49549d4ea5e6a86e0aedf/tests/BiosTests.hs#L101-L110

In that case i would not worry much about.

, Just (String biosDepsProgram) <- Map.lookup "dependency-program" x
= return $ Bios (T.unpack biosProgram) (Just (T.unpack biosDepsProgram))
, Just biosCallable <- exclusive (stringTypeFromMap Program "program") (stringTypeFromMap Command "shell")
, Just biosDepsCallable <- exclusive (stringTypeFromMap Program "dependency-program") (stringTypeFromMap Command "dependency-shell")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like here you could have program and dependency-shell which I suppose is acceptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was intentional. I didn't see a good reason to disallow it, and I added a test and documentation explicitly for this kind of mixing.

src/HIE/Bios/Cradle.hs Outdated Show resolved Hide resolved
@mpickering
Copy link
Collaborator

Thanks, very nice patch. Just a couple of comments.

This allows passing additional arguments or redirecting a program's
output to collect flags without needing to add a script to the project.
To accomplish that, it utilizes the process package's support for
executing shell commands by passing the CreateProcess data structure
used by it to readProcessWithOutputFile instead of an executable
name and arguments.
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you, nice patch!

@fendor fendor merged commit 293baaf into haskell:master Jun 8, 2020
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

Successfully merging this pull request may close these issues.

Support arguments to bios process
4 participants