Skip to content

Commit

Permalink
feat(compiler): added path to compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Jan 17, 2024
1 parent fe62be4 commit e80b46d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions build/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CompilerConfig struct {
User string `json:"user,omitempty" yaml:"user,omitempty"` // Name of the github user
Repo string `json:"repo,omitempty" yaml:"repo,omitempty"` // Name of the github repository
Version string `json:"version,omitempty" yaml:"version,omitempty"` // The version of the compiler to use
Path string `json:"path,omitempty" yaml:"path,omitempty"` // The path to the compiler (overrides the above)
}

// Default defines and returns a default compiler configuration
Expand All @@ -40,6 +41,7 @@ func Default() *Config {
User: "pawn-lang",
Repo: "compiler",
Version: "3.10.10",
Path: "",
},
}
}
Expand Down
44 changes: 37 additions & 7 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"io/fs"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
Expand All @@ -20,6 +21,7 @@ import (
"rs3.io/go/mserr/ntstatus"

"github.com/Southclaws/sampctl/build"
"github.com/Southclaws/sampctl/download"
"github.com/Southclaws/sampctl/print"
"github.com/Southclaws/sampctl/util"
)
Expand Down Expand Up @@ -126,11 +128,39 @@ func PrepareCommand(
config.WorkingDir = util.FullPath(config.WorkingDir)
}

var pkg download.Compiler
runtimeDir := filepath.Join(cacheDir, "pawn", config.Compiler.Version)
pkg, err := GetCompilerPackage(ctx, gh, config, runtimeDir, platform, cacheDir)
if err != nil {
err = errors.Wrap(err, "failed to get compiler package")
return
if config.Compiler.Path == "" {
pkg, err = GetCompilerPackage(ctx, gh, config, runtimeDir, platform, cacheDir)
if err != nil {
err = errors.Wrap(err, "failed to get compiler package")
return
}
} else {
print.Verb("using custom path for compiler", config.Compiler.Path)
pathStat, error := os.Stat(config.Compiler.Path)
if error != nil {
err = errors.Wrap(error, "compiler path is not valid")
return
}
if !pathStat.IsDir() {
err = errors.New("compiler path is not a valid directory")
return
}

compilerPath := ""
if runtime.GOOS == "windows" {
compilerPath = path.Join(config.Compiler.Path, "pawncc.exe")
} else {
compilerPath = path.Join(config.Compiler.Path, "pawncc")
}

pkg = download.Compiler{
Match: "",
Method: "",
Binary: compilerPath,
Paths: map[string]string{},
}
}

args := []string{
Expand All @@ -146,7 +176,7 @@ func PrepareCommand(

var (
fullPath string
contents []os.FileInfo
contents []fs.DirEntry
)
for _, inc := range config.Includes {
if filepath.IsAbs(inc) {
Expand All @@ -164,7 +194,7 @@ func PrepareCommand(
print.Verb("using include path", fullPath)
args = append(args, "-i"+fullPath)

contents, err = ioutil.ReadDir(fullPath)
contents, err = os.ReadDir(fullPath)
if err != nil {
err = errors.Wrapf(err, "failed to list dependency include path: %s", inc)
return
Expand Down

0 comments on commit e80b46d

Please sign in to comment.