build binary in dedicated build directory

This commit is contained in:
Dan Anglin 2024-05-22 21:51:28 +01:00
parent 08df511506
commit 8d2426b041
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 10 additions and 7 deletions

4
.gitignore vendored
View file

@ -1,2 +1,4 @@
/environment/
/enbas
/*.enbas
/__build/*
!__build/.gitkeep

0
__build/.gitkeep Normal file
View file

View file

@ -14,7 +14,7 @@ import (
)
const (
binary = "enbas"
app = "enbas"
defaultInstallPrefix = "/usr/local"
envInstallPrefix = "ENBAS_INSTALL_PREFIX"
envTestVerbose = "ENBAS_TEST_VERBOSE"
@ -65,7 +65,8 @@ func Build() error {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
main := "./cmd/" + binary
main := "./cmd/" + app
binary := "./__build/" + app
flags := ldflags()
build := sh.RunCmd("go", "build")
args := []string{"-ldflags=" + flags, "-o", binary}
@ -93,13 +94,13 @@ func Install() error {
installPrefix = defaultInstallPrefix
}
dest := filepath.Join(installPrefix, "bin", binary)
dest := filepath.Join(installPrefix, "bin", app)
if err := sh.Copy(dest, binary); err != nil {
if err := sh.Copy(dest, app); err != nil {
return fmt.Errorf("unable to install %s; %w", dest, err)
}
fmt.Printf("%s successfully installed to %s\n", binary, dest)
fmt.Printf("%s successfully installed to %s\n", app, dest)
return nil
}
@ -110,7 +111,7 @@ func Clean() error {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
if err := sh.Rm(binary); err != nil {
if err := sh.Rm(app); err != nil {
return err
}