Skip to content
Browse files

In case of an 'undefined reference to main' error, conclude that the …

…user only meant to compile, not link or run.
  • Loading branch information...
1 parent a183a18 commit c5f7eb8d6c22fcbf4f45232edc296ff7f59a11b8 @Eelis committed Jan 28, 2012
Showing with 12 additions and 3 deletions.
  1. +5 −3 src/EvalCxx.hsc
  2. +7 −0 src/Gcc.hs
View
8 src/EvalCxx.hsc
@@ -82,7 +82,7 @@ import System.Posix.User
(getGroupEntryForName, getUserEntryForName, setGroupID, setUserID, groupID, userID)
import System.Posix
(Signal, sigALRM, sigSTOP, sigTRAP, sigKILL, sigSEGV, sigILL, createPipe, setFdOption, executeFile, raiseSignal, ProcessID, openFd, defaultFileFlags, forkProcess, dupTo, stdError, stdOutput, scheduleAlarm, OpenMode(..), exitImmediately, FdOption(..), Resource(..), ResourceLimit(..), ResourceLimits(..), setResourceLimit)
-import Gcc (Stage(..))
+import Gcc (Stage(..), isMainMissingDiagnostic)
import CompileConfig
#ifdef __x86_64__
@@ -250,8 +250,10 @@ evaluate cfg req = do
runStage :: StageMaybe (IO EvaluationResult) → IO EvaluationResult
runStage stage act = do
cr capture_restricted (path stage) (argv stage) (env stage) (resources stage)
- case act of
- Just a | cr == CaptureResult (Exited ExitSuccess) "", stage /= stageOfInterest req a
+ case cr of
+ CaptureResult (Exited (ExitFailure _)) d | stage == Link, isMainMissingDiagnostic d
+ return $ EvaluationResult Compile (CaptureResult (Exited ExitSuccess) "")
+ CaptureResult (Exited ExitSuccess) "" | stage /= stageOfInterest req, Just a act a
_ return $ EvaluationResult stage cr
path :: StageString
View
7 src/Gcc.hs
@@ -2,5 +2,12 @@
module Gcc where
+import Data.Maybe (isJust)
+import Text.Regex (mkRegex, matchRegex)
+
data Stage = Preprocess | Compile | Assemble | Link | Run
deriving (Show, Eq)
+
+isMainMissingDiagnostic :: StringBool
+isMainMissingDiagnostic =
+ isJust . matchRegex (mkRegex "undefined reference to [^[:alnum:]]+main[^[:alnum:]]+$")

0 comments on commit c5f7eb8

Please sign in to comment.
Something went wrong with that request. Please try again.