#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 13 Oct 2016 00:52:26 +0200
changeset 4019 ca410e6cca3f
parent 4018 973908080769
child 4020 96827efd120e
#FEATURE by cg class: STCCompilerInterface added: #compileToC_onError:
STCCompilerInterface.st
--- a/STCCompilerInterface.st	Thu Oct 13 00:50:39 2016 +0200
+++ b/STCCompilerInterface.st	Thu Oct 13 00:52:26 2016 +0200
@@ -412,6 +412,67 @@
 
 !STCCompilerInterface methodsFor:'machine code generation-helpers'!
 
+compileToC_onError:aBlock
+    "compile st to C using stc.
+     If any error happens, call aBlock passing it the fileName containing diagnostics"
+
+    |command ok errorOutputFile|
+
+    command := (self possiblyQuotedPath:stcPath) , ' ' , stcFlags 
+                , '-E:',(self possiblyQuotedPath:Filename tempDirectory / 'lastIncrStcErrorOutput')
+                , ' -defdir=', (self possiblyQuotedPath:cFileName asFilename directory pathName).
+    cFileName asFilename suffix ~= 'c' ifTrue:[
+        command := command , ' -cSuffix=',cFileName asFilename suffix.
+    ].
+    command := command , ' -C ' , (self possiblyQuotedPath:stFileName asFilename pathName).
+
+    Verbose == true ifTrue:[
+        Transcript show:'executing: '; showCR:command.
+    ].
+
+    originator activityNotification:'compiling (stc)'.
+
+    errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. 
+    errorOutputFile writingFileDo:[:errorStream |
+        ok := OperatingSystem 
+                    executeCommand:command 
+                    inputFrom:nil
+                    outputTo:errorStream
+                    errorTo:errorStream
+                    inDirectory:(OperatingSystem pathOfSTXExecutable)
+                    showWindow:false
+                    onError:[:stat| 
+self halt.
+                                executionStatus := stat.
+                                false
+                            ].
+    ].
+
+    cFileName asFilename exists ifTrue:[
+        ok ifFalse:[
+            'Compiler [info]: oops - system says stc failed - but c-file is there ...' infoPrintCR.
+            ok := true
+        ]
+    ] ifFalse:[
+        ok ifTrue:[
+            'Compiler [info]: oops - system says stc ok - but no c-file is there ...' infoPrintCR
+        ].
+        ok := false
+    ].
+    
+    [
+        ok ifFalse:[
+            aBlock value:errorOutputFile
+        ].
+    ] ensure:[
+        errorOutputFile remove.
+    ].
+    ^ ok
+
+    "Created: / 07-11-2006 / 12:11:24 / cg"
+    "Modified: / 08-08-2011 / 22:12:01 / cg"
+!
+
 compileToExe_onError:aBlock 
     "compile C to exe, using cc.
      If any error happens, call aBlock passing it the fileName containing diagnostics"