summaryrefslogtreecommitdiff
path: root/ghc/Main.hs
diff options
context:
space:
mode:
authorroland <rsx@bluewin.ch>2018-07-30 21:34:20 +0100
committerTamar Christina <tamar@zhox.com>2018-07-30 21:37:52 +0100
commita7c8acda5c7ad99fa983bbd5e59480ab5e633c54 (patch)
tree3514e0f7eb2e96f2402548632b4a76a4c00a5ce1 /ghc/Main.hs
parent9d388eb83e797fd28e14868009c4786f3f1a8aa6 (diff)
downloadhaskell-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
Diffstat (limited to 'ghc/Main.hs')
-rw-r--r--ghc/Main.hs20
1 files changed, 17 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