diff --git a/compiler/compiler.go b/compiler/compiler.go index c07106a5..7eb9c95e 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -30,8 +30,8 @@ type Config struct { } // GetDefaultConfig defines and returns a default compiler configuration -func GetDefaultConfig() Config { - return Config{ +func GetDefaultConfig() *Config { + return &Config{ Args: []string{"-d3", "-;+", "-(+", "-\\+", "-Z+"}, Version: "3.10.4", } diff --git a/rook/build.go b/rook/build.go index 6525628f..fe8816ba 100644 --- a/rook/build.go +++ b/rook/build.go @@ -13,9 +13,9 @@ import ( // Build compiles a package, dependencies are ensured and a list of paths are sent to the compiler. func (pkg Package) Build(build string, ensure bool) (output string, err error) { - config, err := pkg.GetBuildConfig(build) - if err != nil { - err = errors.Wrap(err, "failed to get build config") + config := pkg.GetBuildConfig(build) + if config == nil { + err = errors.Errorf("no build config named '%s'", build) return } @@ -49,7 +49,7 @@ func (pkg Package) Build(build string, ensure bool) (output string, err error) { fmt.Println("building", pkg, "with", config.Version) - err = compiler.CompileSource(pkg.local, cacheDir, config) + err = compiler.CompileSource(pkg.local, cacheDir, *config) if err != nil { err = errors.Wrap(err, "failed to compile package entry") return @@ -63,19 +63,16 @@ func (pkg Package) Build(build string, ensure bool) (output string, err error) { // GetBuildConfig returns a matching build by name from the package build list. If no name is // specified, the first build is returned. If the package has no build definitions, a default // configuration is returned. -func (pkg Package) GetBuildConfig(name string) (config compiler.Config, err error) { +func (pkg Package) GetBuildConfig(name string) (config *compiler.Config) { if len(pkg.Builds) == 0 || name == "" { config = compiler.GetDefaultConfig() - return - } - - for _, cfg := range pkg.Builds { - if cfg.Name == name { - return cfg, nil + } else { + for _, cfg := range pkg.Builds { + if cfg.Name == name { + config = &cfg + } } } - err = errors.Errorf("build '%s' not found in config", name) - return } diff --git a/rook/build_test.go b/rook/build_test.go index 3698c9e1..141eee39 100644 --- a/rook/build_test.go +++ b/rook/build_test.go @@ -50,9 +50,6 @@ func TestPackage_Build(t *testing.T) { "Southclaws/samp-stdlib:0.3.7-R2-2-1", "ScavengeSurvive/actions", }, - Builds: []compiler.Config{ - {Name: "build", Version: "3.10.4"}, - }, }, args{"build", true}, "gamemodes/test.amx", false}, {"custominc", []byte(`#include #include @@ -73,6 +70,7 @@ func TestPackage_Build(t *testing.T) { "../build-auto-deep/dependencies/amx_assembly", "../build-auto-deep/dependencies/YSI-Includes", }, + Args: []string{"-d3", "-;+", "-(+", "-\\+", "-Z+"}, }, }, }, args{"build", true}, "gamemodes/test.amx", false},