Skip to content
Snippets Groups Projects
Commit 674bfd77 authored by Aleksander Einarsen's avatar Aleksander Einarsen
Browse files

Renamed OS to platform, and package data to platform

parent 491a8319
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ const ( ...@@ -28,7 +28,7 @@ const (
) )
// TODO: I want to make an interface for a compilable language, so that we can add more languages in the future // TODO: I want to make an interface for a compilable language, so that we can add more languages in the future
// TODO: The cmd might also be an interface or a struct, so that it can build itself based on the OS and language // TODO: The cmd might also be an interface or a struct, so that it can build itself based on the platform and language
// TODO: A cleanup and panic might be needed in setup because if it panics the temp folders should be removed // TODO: A cleanup and panic might be needed in setup because if it panics the temp folders should be removed
// TODO: I am not sure that the setup should panic, maybe it should return an error instead so its easier to clean up // TODO: I am not sure that the setup should panic, maybe it should return an error instead so its easier to clean up
...@@ -126,14 +126,14 @@ func InitCompiler(OS OS, language Language, sourceCode string, filename string, ...@@ -126,14 +126,14 @@ func InitCompiler(OS OS, language Language, sourceCode string, filename string,
} }
func getOsPrefix(OS OS) string { func getOsPrefix(OS OS) string {
// Set the cmd prefix based on the OS // Set the cmd prefix based on the platform
switch OS { switch OS {
case Windows: case Windows:
return "cmd /c " return "cmd /c "
case Linux, MacOS: case Linux, MacOS:
return "" return ""
default: default:
panic("Unsupported OS") panic("Unsupported platform")
} }
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
// The function does not produce any executables, since they are deleted after the function ends. // The function does not produce any executables, since they are deleted after the function ends.
func CompileStringToGo(code string, filename string, dependencies ...string) (string, error) { func CompileStringToGo(code string, filename string, dependencies ...string) (string, error) {
// Get the OS // Get the platform
OS := runtime.GOOS OS := runtime.GOOS
// SetupEnvironment // SetupEnvironment
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
// CompileStringToRust compiles a string of go code to a rust executable // CompileStringToRust compiles a string of go code to a rust executable
func CompileStringToRust(code string, filename string, dependencies ...string) (string, error) { func CompileStringToRust(code string, filename string, dependencies ...string) (string, error) {
// Get the OS // Get the platform
OS := runtime.GOOS OS := runtime.GOOS
// SetupEnvironment // SetupEnvironment
......
package data package platform
type OS = string type OS = string
......
package utils package utils
import ( import (
"compiler_V2/data" p "compiler_V2/platform"
"os/exec" "os/exec"
"runtime" "runtime"
) )
// MakeCommand creates a command based on the runtime OS // MakeCommand creates a command based on the runtime platform
func MakeCommand(cmd string) *exec.Cmd { func MakeCommand(cmd string) *exec.Cmd {
OS := runtime.GOOS platform := runtime.GOOS
switch OS { switch platform {
case data.Windows: case p.Windows:
return exec.Command("cmd", "/c", cmd) return exec.Command("cmd", "/c", cmd)
case data.Linux, data.MacOS: case p.Linux, p.MacOS:
return exec.Command("bash", "-c", cmd) return exec.Command("bash", "-c", cmd)
default: default:
panic("Unsupported OS") panic("Unsupported platform")
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment