[GHC] #12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths ----------------------------------------+---------------------------- Reporter: rcook | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Keywords: | Operating System: Windows Architecture: Unknown/Multiple | Type of failure: Other Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: ----------------------------------------+---------------------------- Repro steps: * Install Stack on a ''Windows'' development machine. * Create new simple project with `stack new inlinecbug simple`. * Rename `src/Main.hs` to `src/Main.hsc` in the `inlinecbug` project directory. * Build project with `stack build` and run with `stack exec inlinecbug` to verify that hsc2hs works correctly. * Replace content of `src/Main.hsc` with following: {{{#!hs {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} import qualified Language.C.Inline as C C.include "<math.h>" main :: IO () main = do x <- [C.exp| double{ cos(1) } |] print x }}} * In `inlinecbug.cabal` add `inline-c` to the `build-depends` section of `executable inlinecbug`. * Add the line `c-source-files: src/Main.c` to the `executable inlinecbug` section. * Rebuild with `stack build`. Build will fail with a linker error referring to a undefined reference to an `inline_c_main...` function. List the files in the root directory of the project and you'll see that inline-c has generated a file with the name `srcMain.c`: i.e. the backslashes in the Windows path have been removed. Building under Linux generates the C output file with the correct, expected path of `src/Main.c` and the program will compile, link and run as expected. See also: https://github.com/fpco/inline-c/issues/50 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths ----------------------------+---------------------------------------- Reporter: rcook | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------+---------------------------------------- Comment (by rcook): See comment from "awson" at: https://github.com/fpco/inline-c/issues/50#issuecomment-241212544: The culprit is `{-# LINE ... #-}` pragmas in the files generated by hsc2hs. hsc2hs on Windows emits paths with non-escaped backslashes in it: {{{#!hs {-# LINE 1 "src\Language\C\Clang\Internal\FFI.hsc" #-} }}} I don't know how GHC's `LINE` pragma behavior is specified, but this is at least inconsistent with how Windows C compilers operate. GCC emits line directives with forward slashes in paths and Visual C emits escaped backslashes. Thus I mostly inclined to treat this as a bug in hsc2hs (easily fixable). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rcook): * testcase: => /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): It seems that you have a patch Richard? Could you possibly submit it to phabricator for review if it fixes the issue you are facing? Thank you for the reproduction steps but they are too involved to be really useful to find the issue. A reproduction should ideally be one invocation of `ghc` rather than relying on lots of external tools and libraries like stack. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2477 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * status: new => patch * differential: => Phab:D2477 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2477 Wiki Page: | Phab:D2478 -------------------------------------+------------------------------------- Changes (by rcook): * differential: Phab:D2477 => Phab:D2477 Phab:D2478 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2477 Wiki Page: | Phab:D2478 -------------------------------------+------------------------------------- Comment (by rcook): Phab:D2477 adds a test case under `testsuite/tess/hsc2hs`. Phab:D2478 is a fix for the bug located under `utils/hsc2hs`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2477 Wiki Page: | Phab:D2478 -------------------------------------+------------------------------------- Description changed by rcook: @@ -25,1 +25,1 @@ - * Add the line `c-source-files: src/Main.c` to the `executable inlinecbug` + * Add the line `c-sources: src/Main.c` to the `executable inlinecbug` New description: Repro steps: * Install Stack on a ''Windows'' development machine. * Create new simple project with `stack new inlinecbug simple`. * Rename `src/Main.hs` to `src/Main.hsc` in the `inlinecbug` project directory. * Build project with `stack build` and run with `stack exec inlinecbug` to verify that hsc2hs works correctly. * Replace content of `src/Main.hsc` with following: {{{#!hs {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} import qualified Language.C.Inline as C C.include "<math.h>" main :: IO () main = do x <- [C.exp| double{ cos(1) } |] print x }}} * In `inlinecbug.cabal` add `inline-c` to the `build-depends` section of `executable inlinecbug`. * Add the line `c-sources: src/Main.c` to the `executable inlinecbug` section. * Rebuild with `stack build`. Build will fail with a linker error referring to a undefined reference to an `inline_c_main...` function. List the files in the root directory of the project and you'll see that inline-c has generated a file with the name `srcMain.c`: i.e. the backslashes in the Windows path have been removed. Building under Linux generates the C output file with the correct, expected path of `src/Main.c` and the program will compile, link and run as expected. See also: https://github.com/fpco/inline-c/issues/50 -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rcook): * differential: Phab:D2477 Phab:D2478 => Phab:D2478 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rcook): @mpickering: Here's a more compact repro case: {{{#!hs $ cat T12504/path/to/T12504.hsc module Main (main) where main :: IO () main = putStrLn "hello world" $ '/c/src/ghc/inplace/bin/hsc2hs.exe' T12504/path/to/T12504.hsc $ cat T12504/path/to/T12504.hs {-# LINE 1 "T12504\path\to\T12504.hsc" #-} module Main (main) where {-# LINE 2 "T12504\path\to\T12504.hsc" #-} main :: IO () main = putStrLn "hello world" }}} Notice that the backslashes in the paths are not escaped properly. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"2ee1db60ab29258fa9f8ab820f778bd0bb7f87a4/ghc" 2ee1db60/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="2ee1db60ab29258fa9f8ab820f778bd0bb7f87a4" Fixes #12504: Double-escape paths used to build call to hsc_line In outHsLine, paths passed to construct invocations of hsc_line must be escaped twice in order to generate a properly escaped string literal that will end up in the eventual LINE pragma emitted by this code. This is especially important on Windows paths, where backslashes would otherwise be treated as C escape sequences and result in the incorrect Windows paths. Adds test case to verify that hsc2hs properly escapes file paths in LINE pragmas Updates the hsc2hs submodule. See https://ghc.haskell.org/trac/ghc/ticket/12504 Reviewers: erikd, hvr, austin, bgamari, Phyx Reviewed By: erikd, Phyx Subscribers: thomie, Phyx, mpickering Differential Revision: https://phabricator.haskell.org/D2478 GHC Trac Issues: #12504 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => merge * milestone: => 8.0.2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-8.0` as 76286af5c621f032c4afab1f26b992e8ffa7f84d. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rcook): Will hsc2cs's version number need to be bumped? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths -------------------------------------+------------------------------------- Reporter: rcook | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Wiki Page: | Phab:D2537 -------------------------------------+------------------------------------- Changes (by Phyx-): * differential: Phab:D2478 => Phab:D2478 Phab:D2537 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths ----------------------------+--------------------------------------------- Reporter: rcook | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: Unknown/Multiple Type of failure: Other | Test Case: T12504 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Phab:D2537 Wiki Page: | ----------------------------+--------------------------------------------- Changes (by Phyx-): * testcase: /testsuite/tests/hsc2hs/T12504/path/to/T12504.hsc => T12504 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12504: Windows: Using hsc2hs in combination with inline-c generates the .c files with invalid paths ----------------------------+--------------------------------------------- Reporter: rcook | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: hsc2hs | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: Unknown/Multiple Type of failure: Other | Test Case: T12504 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2478 Phab:D2537 Wiki Page: | ----------------------------+--------------------------------------------- Comment (by Tamar Christina <tamar@…>): In [changeset:"8bd3d417e67e5e938dd5bfc640c3efbb683ee309/ghc" 8bd3d417/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="8bd3d417e67e5e938dd5bfc640c3efbb683ee309" Fix failing test T12504 Summary: Test T12504 does it's checking in the Makefile using grep but still specified an stdout. the stdout has the old output and would always fail. Since the stdout isn't needed, let's not check it. Test Plan: make test TEST=T12504 Reviewers: bgamari, austin, erikd, rcook Reviewed By: rcook Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2537 GHC Trac Issues: #12504 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12504#comment:16> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC