Add some more language link code

This commit is contained in:
2022-06-10 18:33:47 +02:00
parent f9d386c251
commit 1db1b01b2a
14 changed files with 469 additions and 16 deletions

View 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
]