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

on Windows, include paths with spaces not properly passed to c2hs #309

Closed
bos opened this issue May 24, 2012 · 4 comments
Closed

on Windows, include paths with spaces not properly passed to c2hs #309

bos opened this issue May 24, 2012 · 4 comments

Comments

@bos
Copy link
Contributor

bos commented May 24, 2012

(Imported from Trac #316, reported by jwlato on 2008-08-01)

On windows, path names with spaces aren't passed to build tools properly. In a new project, with a source file Test.chs

and a cabal file with (boilerplate excluded)

  exposed-modules: Test
  build-tools:     c2hs
  include-dirs:    "C:\Program Files\include"
then attempting "runhaskell Setup.lhs build -v" indicates that the following is executed:
c:Program FilesHaskellbinc2hs.exe --include=distbuild --cppopts=-D__GLASGOW_HASKELL__=608 --cppopts=-IC:Program Filesinclude
    --output-dir=distbuild --output=Test.hs Test.chs
This command fails because c2hs interprets Files\include as a filename to process. The -IC:\Program Files ... should be quoted to preserve the space in the path.

I have attached a test.cabal and Test.chs file that demonstrate the problem.

@bos
Copy link
Contributor Author

bos commented May 24, 2012

(Imported comment by jwlato on 2008-08-01)

cabal file

@bos
Copy link
Contributor Author

bos commented May 24, 2012

(Imported comment by @dcoutts on 2008-08-01)

Ok, it turns out to be a c2hs bug, not a Cabal bug. It's not clear from the build -v output that we're doing it right, but actually we are! :-) If you run with -v3 then Cabal logs how it's calling external programs using unambiguous Haskell Show syntax: //(formatted for clarity)//

("/usr/bin/c2hs"
,["--include=dist/build"
 ,"--cppopts=-D__GLASGOW_HASKELL__=608"
 ,"--cppopts=-IC:\Program Files\include"
 ,"--output-dir=dist/build"
 ,"--output=Test.hs"
 ,"./Test.chs"
 ]
)
The point is, we are passing "--cppopts=-IC:\Program Files\include" as a single argument to c2hs. There's no shell getting in between so that's the actual argument we pass. No escaping is necessary.

The problem is that c2hs is not nearly so careful. It calls cpp like so:

let cmd  = unwords [cpp, cppOpts, newHeaderFile,
                    ">" ++ preprocFile]
    exitCode <\- system cmd
That is, it's using the system function. This goes via the system shell so has problems with spaces and escaping.

The solution is for us to fix c2hs to use rawSystem as Cabal does. Actually since c2hs needs to capture the output of the command it'll have to use System.Process.runProcess.

@bos
Copy link
Contributor Author

bos commented May 24, 2012

(Imported comment by @dcoutts on 2008-08-01)

This should be fixed in c2hs-0.16.0, the above test case should be tried again.

http://hackage.haskell.org/trac/c2hs/ticket/11

@bos
Copy link
Contributor Author

bos commented May 24, 2012

(Imported comment by @dcoutts on 2009-01-24)

Seems to work now when using c2hs-0.16.0.

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

No branches or pull requests

1 participant