diff options
author | Phil Ruffwind <rf@rufflewind.com> | 2015-02-09 13:39:12 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2015-02-09 23:59:38 -0600 |
commit | 78833ca6305f0875add94351592e141c032cd088 (patch) | |
tree | 5a7bab929b55b3a8ba3312d7c6ff3be8629f413d | |
parent | 5d5abdca31cdb4db5303999778fa25c4a1371084 (diff) | |
download | haskell-78833ca6305f0875add94351592e141c032cd088.tar.gz |
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
-rw-r--r-- | compiler/main/GhcMake.hs | 18 | ||||
-rw-r--r-- | testsuite/tests/ghc-e/should_fail/Makefile | 3 | ||||
-rw-r--r-- | testsuite/tests/ghc-e/should_fail/T9930 | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-e/should_fail/all.T | 3 |
4 files changed, 20 insertions, 5 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs index a698f50c74..f9e61a5ac5 100644 --- a/compiler/main/GhcMake.hs +++ b/compiler/main/GhcMake.hs @@ -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 diff --git a/testsuite/tests/ghc-e/should_fail/Makefile b/testsuite/tests/ghc-e/should_fail/Makefile index c0cebcd546..9aa7c07fa5 100644 --- a/testsuite/tests/ghc-e/should_fail/Makefile +++ b/testsuite/tests/ghc-e/should_fail/Makefile @@ -19,3 +19,6 @@ ghc-e-fail1: ghc-e-fail2: '$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e "type A = A" + +T9930fail: + '$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -x hs T9930 diff --git a/testsuite/tests/ghc-e/should_fail/T9930 b/testsuite/tests/ghc-e/should_fail/T9930 new file mode 100644 index 0000000000..45846a99dd --- /dev/null +++ b/testsuite/tests/ghc-e/should_fail/T9930 @@ -0,0 +1 @@ +main = undefined diff --git a/testsuite/tests/ghc-e/should_fail/all.T b/testsuite/tests/ghc-e/should_fail/all.T index bfd4a8a0f1..8e080e95c9 100644 --- a/testsuite/tests/ghc-e/should_fail/all.T +++ b/testsuite/tests/ghc-e/should_fail/all.T @@ -17,3 +17,6 @@ test('ghc-e-fail1', [exit_code(2), req_interp, ignore_output], run_command, test('ghc-e-fail2', [exit_code(2), req_interp, ignore_output], run_command, ['$MAKE --no-print-directory -s ghc-e-fail2']) + +test('T9930fail', [exit_code(2), ignore_output], run_command, + ['$MAKE --no-print-directory -s T9930fail']) |