Skip to content
Snippets Groups Projects
Commit ed4de443 authored by Rufflewind's avatar Rufflewind Committed by thoughtpolice
Browse files

Don't overwrite input file by default

Summary:
If the default filename of the output executable coincides with that of main
source file, throw an error instead of silently clobbering the input file.

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D642

GHC Trac Issues: #9930

(cherry picked from commit 78833ca6)
parent 1d401b43
No related merge requests found
......@@ -427,14 +427,22 @@ guessOutputFile = modifySession $ \env ->
ml_hs_file (ms_location ms)
name = fmap dropExtension mainModuleSrcPath
name_exe = do
#if defined(mingw32_HOST_OS)
-- we must add the .exe extention unconditionally here, otherwise
-- when name has an extension of its own, the .exe extension will
-- not be added by DriverPipeline.exeFileName. See #2248
name_exe = fmap (<.> "exe") name
-- we must add the .exe extention unconditionally here, otherwise
-- when name has an extension of its own, the .exe extension will
-- not be added by DriverPipeline.exeFileName. See #2248
name' <- fmap (<.> "exe") name
#else
name_exe = name
name' <- name
#endif
mainModuleSrcPath' <- mainModuleSrcPath
-- #9930: don't clobber input files (unless they ask for it)
if name' == mainModuleSrcPath'
then throwGhcException . UsageError $
"default output name would overwrite the input file; " ++
"must specify -o explicitly"
else Just name'
in
case outputFile dflags of
Just _ -> env
......
......@@ -13,3 +13,6 @@ T9905fail2:
T9905fail3:
'$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e "import Prelude (+)" # syntax error
T9930fail:
'$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -x hs T9930
main = undefined
......@@ -11,3 +11,6 @@ test('T9905fail2', [exit_code(2), req_interp, ignore_output], run_command,
test('T9905fail3', [exit_code(2), req_interp, ignore_output], run_command,
['$MAKE --no-print-directory -s T9905fail3'])
test('T9930fail', [exit_code(2), ignore_output], run_command,
['$MAKE --no-print-directory -s T9930fail'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment