Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex D
GHC
Commits
91380819
Commit
91380819
authored
Sep 09, 2006
by
sof@galois.com
Browse files
remove generated files in a 'finally' manner
parent
4f2e93bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/hsc2hs/Main.hs
View file @
91380819
...
...
@@ -24,7 +24,7 @@ import Directory (removeFile,doesFileExist)
import
Monad
(
MonadPlus
(
..
),
liftM
,
liftM2
,
when
)
import
Char
(
isAlpha
,
isAlphaNum
,
isSpace
,
isDigit
,
toUpper
,
intToDigit
,
ord
)
import
List
(
intersperse
,
isSuffixOf
)
import
IO
(
hPutStr
,
hPutStrLn
,
stderr
)
import
IO
(
hPutStr
,
hPutStrLn
,
stderr
,
bracket_
)
#
if
defined
(
mingw32_HOST_OS
)
import
Foreign
...
...
@@ -597,17 +597,17 @@ output flags name toks = do
++
[
cProgName
]
++
[
"-o"
,
oProgName
]
)
r
emove
File
cProgName
finallyR
emove
cProgName
$
do
rawSystemL
(
"linking "
++
oProgName
)
beVerbose
linker
(
[
f
|
LinkFlag
f
<-
flags
]
++
[
oProgName
]
++
[
"-o"
,
progName
]
)
r
emove
File
oProgName
finallyR
emove
oProgName
$
do
rawSystemWithStdOutL
(
"running "
++
execProgName
)
beVerbose
execProgName
[]
outName
r
emove
File
progName
finallyR
emove
progName
$
do
when
needsH
$
writeFile
outHName
$
"#ifndef "
++
includeGuard
++
"
\n
"
++
...
...
@@ -659,6 +659,19 @@ rawSystemWithStdOutL action flg prog args outFile = do
ExitFailure
_
->
die
$
action
++
" failed
\n
command was: "
++
cmdLine
++
"
\n
"
_
->
return
()
-- delay the cleanup of generated files until the end; attempts to
-- get around intermittent failure to delete files which has
-- just been exec'ed by a sub-process (Win32 only.)
finallyRemove
::
FilePath
->
IO
a
->
IO
a
finallyRemove
fp
act
=
bracket_
(
return
fp
)
(
const
$
noisyRemove
fp
)
act
where
noisyRemove
fpath
=
catch
(
removeFile
fpath
)
(
\
e
->
hPutStrLn
stderr
(
"Failed to remove file "
++
fpath
++
"; error= "
++
show
e
))
onlyOne
::
String
->
IO
a
onlyOne
what
=
die
(
"Only one "
++
what
++
" may be specified
\n
"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment