diff options
author | roland <rsx@bluewin.ch> | 2018-07-30 21:34:20 +0100 |
---|---|---|
committer | Tamar Christina <tamar@zhox.com> | 2018-07-30 21:37:52 +0100 |
commit | a7c8acda5c7ad99fa983bbd5e59480ab5e633c54 (patch) | |
tree | 3514e0f7eb2e96f2402548632b4a76a4c00a5ce1 | |
parent | 9d388eb83e797fd28e14868009c4786f3f1a8aa6 (diff) | |
download | haskell-a7c8acda5c7ad99fa983bbd5e59480ab5e633c54.tar.gz |
GHC doesn't handle ./ prefixed paths correctly (#12674)
Summary: If a filename starts with a hypen, GHC keeps the prefixed "./" path.
Test Plan: make test TEST=T12674
Reviewers: Phyx, nomeata, bgamari, erikd
Reviewed By: Phyx
Subscribers: rwbarton, thomie, carter
GHC Trac Issues: #12674
Differential Revision: https://phabricator.haskell.org/D5009
-rw-r--r-- | ghc/Main.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/driver/T12674/-T12674.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/driver/T12674/-T12674c.c | 6 | ||||
-rw-r--r-- | testsuite/tests/driver/T12674/T12674.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/driver/T12674/T12674w.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/driver/T12674/all.T | 5 |
6 files changed, 40 insertions, 3 deletions
diff --git a/ghc/Main.hs b/ghc/Main.hs index ea80910afb..03ac60db2d 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -213,9 +213,23 @@ main' postLoadMode dflags0 args flagWarnings = do let -- To simplify the handling of filepaths, we normalise all filepaths right - -- away - e.g., for win32 platforms, backslashes are converted - -- into forward slashes. - normal_fileish_paths = map (normalise . unLoc) fileish_args + -- away. Note the asymmetry of FilePath.normalise: + -- Linux: p/q -> p/q; p\q -> p\q + -- Windows: p/q -> p\q; p\q -> p\q + -- #12674: Filenames starting with a hypen get normalised from ./-foo.hs + -- to -foo.hs. We have to re-prepend the current directory. + normalise_hyp fp + | strt_dot_sl && "-" `isPrefixOf` nfp = cur_dir ++ nfp + | otherwise = nfp + where +#if defined(mingw32_HOST_OS) + strt_dot_sl = "./" `isPrefixOf` fp || ".\\" `isPrefixOf` fp +#else + strt_dot_sl = "./" `isPrefixOf` fp +#endif + cur_dir = '.' : [pathSeparator] + nfp = normalise fp + normal_fileish_paths = map (normalise_hyp . unLoc) fileish_args (srcs, objs) = partition_args normal_fileish_paths [] [] dflags5 = dflags4 { ldInputs = map (FileOption "") objs diff --git a/testsuite/tests/driver/T12674/-T12674.hs b/testsuite/tests/driver/T12674/-T12674.hs new file mode 100644 index 0000000000..11a7c546bd --- /dev/null +++ b/testsuite/tests/driver/T12674/-T12674.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE ForeignFunctionInterface, CPP #-} +import Foreign.C +foreign import ccall unsafe "test" test :: CInt -> IO () + +main :: IO () +-- Use conditional language to test passing a file with a filename +-- starting with a hyphen to the preprocessor. +#if defined(__GLASGOW_HASKELL__) +main = test 3 +#endif diff --git a/testsuite/tests/driver/T12674/-T12674c.c b/testsuite/tests/driver/T12674/-T12674c.c new file mode 100644 index 0000000000..3b38c5879e --- /dev/null +++ b/testsuite/tests/driver/T12674/-T12674c.c @@ -0,0 +1,6 @@ +#include <stdio.h> +void test(int arg +) +{ + printf("Result %i\n", arg ); +} diff --git a/testsuite/tests/driver/T12674/T12674.stdout b/testsuite/tests/driver/T12674/T12674.stdout new file mode 100644 index 0000000000..76239dd5cb --- /dev/null +++ b/testsuite/tests/driver/T12674/T12674.stdout @@ -0,0 +1 @@ +Result 3 diff --git a/testsuite/tests/driver/T12674/T12674w.stdout b/testsuite/tests/driver/T12674/T12674w.stdout new file mode 100644 index 0000000000..76239dd5cb --- /dev/null +++ b/testsuite/tests/driver/T12674/T12674w.stdout @@ -0,0 +1 @@ +Result 3 diff --git a/testsuite/tests/driver/T12674/all.T b/testsuite/tests/driver/T12674/all.T new file mode 100644 index 0000000000..0f9e205c9f --- /dev/null +++ b/testsuite/tests/driver/T12674/all.T @@ -0,0 +1,5 @@ +test('T12674', [extra_files(['-T12674.hs', '-T12674c.c'])], + multi_compile, ['./-T12674.hs', [('././-T12674c.c', '')], '-v0']) +test('T12674w', [extra_files(['-T12674.hs', '-T12674c.c']), + unless(opsys('mingw32'), skip)], + multi_compile, ['.\\\-T12674.hs', [('.\\\.\\\-T12674c.c', '')], '-v0']) |