Compiler is now downloaded and executed correctly.

This commit is contained in:
Robin Heggelund Hansen 2024-06-10 20:58:27 +02:00
parent 3cf0aff50b
commit 4f392af3d2
No known key found for this signature in database

View File

@ -175,6 +175,7 @@ makeLocalPath platform homeDir envVars =
type Msg
= ExistanceChecked (Result FileSystem.Error Path)
| CompilerDownloaded (Result (HttpClient.Error Bytes) (HttpClient.Response Bytes))
| CompilerInstalled (Result FileSystem.Error {})
| CompilerExecuted (Result ChildProcess.FailedRun ChildProcess.SuccessfulRun)
@ -228,11 +229,41 @@ update msg model =
}
CompilerDownloaded (Ok res) ->
let
cacheFolder =
Path.parentPath model.localPath
|> Maybe.withDefault Path.empty
in
{ model = model
, command =
Stream.sendLine model.stdout (Debug.toString res)
FileSystem.makeDirectory model.fsPermission { recursive = True } cacheFolder
|> Task.andThen (\_cacheFolder -> FileSystem.writeFile model.fsPermission res.data model.localPath)
|> Task.andThen
(FileSystem.changeAccess
model.fsPermission
{ owner = [ FileSystem.Read, FileSystem.Write, FileSystem.Execute ]
, group = [ FileSystem.Read, FileSystem.Execute ]
, others = [ FileSystem.Read, FileSystem.Execute ]
, resolveLink = False
}
)
|> Task.andThen (\_binPath -> Stream.sendLine model.stdout "Downloaded")
|> Task.attempt CompilerInstalled
}
CompilerInstalled (Err fsErr) ->
{ model = model
, command =
Stream.sendLine model.stderr ("Failed to install binary after download, due to error: " ++ FileSystem.errorToString fsErr)
|> Task.execute
}
CompilerInstalled (Ok {}) ->
{ model = model
, command =
ChildProcess.runWithDefaultOptions model.cpPermission (Path.toPosixString model.localPath) model.args
|> Task.attempt CompilerExecuted
}
CompilerExecuted (Err output) ->
{ model = model