Add some more language link code
This commit is contained in:
142
src/Carp/CarpProcess.class.st
Normal file
142
src/Carp/CarpProcess.class.st
Normal file
@@ -0,0 +1,142 @@
|
||||
Class {
|
||||
#name : #CarpProcess,
|
||||
#superclass : #LanguageLinkAbstractProcess,
|
||||
#instVars : [
|
||||
'process',
|
||||
'environmentVariables'
|
||||
],
|
||||
#classVars : [
|
||||
'CarpPath'
|
||||
],
|
||||
#category : #'Carp-Processes'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess class >> resolveCarpPath [
|
||||
| proc |
|
||||
|
||||
proc := GtSubprocessWithInMemoryOutput new
|
||||
command: 'which';
|
||||
arguments: { 'carp' }.
|
||||
CarpPlatform subProcessEnvironmentDictionary keysAndValuesDo: [ :key :value |
|
||||
proc environmentAt: key put: value ].
|
||||
proc runAndWait.
|
||||
(#(0 1) includes: proc exitCode) ifFalse:
|
||||
[ self error: 'Unable to request carp location' ].
|
||||
^ proc stdout trim asFileReference
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess class >> resolveNodejsPath [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess class >> serverPath [
|
||||
^ CarpPath
|
||||
ifNil: [ CarpPath := self resolveCarpPath ]
|
||||
ifNotNil: [ CarpPath ]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> exitCode [
|
||||
|
||||
^ process
|
||||
ifNil: [ nil ]
|
||||
ifNotNil: [ process exitCode ]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> hasProcess [
|
||||
"Answer a boolean indicating whether the receiver has a process object"
|
||||
|
||||
^ process isNotNil
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> initialize [
|
||||
super initialize.
|
||||
environmentVariables := Dictionary new.
|
||||
self setDefaultEnvironmentVariables
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> isRunning [
|
||||
^ process
|
||||
ifNil: [ false ]
|
||||
ifNotNil: [ process isRunning ]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> newProcess| newProcess [ |
|
||||
newProcess := GtSubprocessWithInMemoryOutput new
|
||||
command: self serverPath fullName;
|
||||
arguments: self processArguments;
|
||||
workingDirectory: self workingDirectory resolve fullName;
|
||||
terminateOnShutdown;
|
||||
yourself.
|
||||
environmentVariables associationsDo: [ :assoc |
|
||||
newProcess environmentAt: assoc key put: assoc value ].
|
||||
^ newProcess
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> processArguments [
|
||||
| args |
|
||||
|
||||
args := OrderedCollection new.
|
||||
self settings serverDebugMode ifTrue:
|
||||
[ args add: '--inspect' ].
|
||||
args
|
||||
add: (self workingDirectory / 'src/languagelink.carp') resolve fullName;
|
||||
add: self settings serverSocketAddress port asString;
|
||||
add: self settings clientSocketAddress port asString.
|
||||
^ args
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> serverPath [
|
||||
| fileReference |
|
||||
|
||||
fileReference := self settings serverExecutable.
|
||||
fileReference ifNil: [ fileReference := self class serverPath ].
|
||||
^ fileReference.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> setDefaultEnvironmentVariables [
|
||||
|
||||
environmentVariables := CarpPlatform subProcessEnvironmentDictionary.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> start [
|
||||
process := self newProcess.
|
||||
process run.
|
||||
self settings serverDebugMode ifTrue:
|
||||
[ self startServerDebugger ].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> stderr [
|
||||
"Answer the process stderr contents"
|
||||
|
||||
^ process stderr
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> stdout [
|
||||
"Answer the process stdout contents"
|
||||
|
||||
^ process stdout
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
CarpProcess >> stop [
|
||||
process ifNil: [ ^ self ].
|
||||
[ process queryExitStatus ifNil: [ process terminate ] ]
|
||||
on: Error
|
||||
do: [ "Do nothing.":e | ].
|
||||
process closeAndCleanStreams.
|
||||
process := nil
|
||||
]
|
Reference in New Issue
Block a user