Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--build.full_bin appears to be ignored in favor of --build.bin #734

Open
jwarner112 opened this issue Jan 30, 2025 · 7 comments
Open

--build.full_bin appears to be ignored in favor of --build.bin #734

jwarner112 opened this issue Jan 30, 2025 · 7 comments

Comments

@jwarner112
Copy link

Hey there,

I just stumbled upon this project ~20 minutes ago and it sounds fantastic. Unfortunately I'm having trouble getting mine to work. I'm skipping the TOML file for the moment in favor of a raw CLI invocation and it seems to ignore --build.full_bin. For context, I'm building an admin panel in my app that uses templ and HTMX, and want to regenerate and rehost the app easily. My command is something like:

$ air --build.pre_cmd "go generate ./..." --build.cmd "go build -o ./my-app -a -tags netgo -ldflags '-w' ./cmd/my-app" --build.full_bin "ENVAR_A=A ENVAR_B=B ENVAR_C=C ./my-app admin"

And I see air spin up and watch the files, invokes go generate ./..., builds the binary, then a bit later tries to run it using the default ./tmp/main path:

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.61.7, built with Go go1.23.5

watching .

...
(watching many files, omitted)
...

!exclude tmp
> go generate ./...
(✓) Complete [ updates=17 duration=17.799542ms ]
building...
admin/docs_templ.go has changed
running...
/bin/sh: /path/to/my/repo/tmp/main: No such file or directory
^Ccleaning...
see you again~

Am I misunderstanding the docs in how to use --build.full_bin? Is it meant to complement --build.bin in some way? The docs had me thinking it was one or the other.

@alex-dna-tech
Copy link

Seems full_bin option not working at all.
If i try to use full_bin as a single set option air trying execute bin default value:

user@host:env$ cat <<EOF > main.go
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println("Print env ENV:")
	fmt.Println(os.Getenv("ENV"))
}
EOF
user@host:env$  air --build.cmd "go build -o main main.go" --build.full_bin "ENV=test ./main" --build.include_file "main.go"

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.61.7, built with Go go1.23.5

watching .
watching main.go
!exclude tmp
building...
running...
/bin/sh: /home/user/testdir/env/tmp/main: No such file or directory
^Ccleaning...
see you again~
user@host:env$ ENV=test-env ./main
Print env ENV:
test-env

@alex-dna-tech
Copy link

So, if you try to use both options, we know the winner:

user@host:env$ air --build.cmd "go build -o main main.go" --build.full_bin "ENV=test-full_bin ./main" --build.bin "ENV=test-bin ./main" --build.include_file "main.go"

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.61.7, built with Go go1.23.5

watching .
watching main.go
!exclude tmp
building...
running...
Print env ENV:
test-bin
Process Exit with Code 0

FYI bin option works exactly as full_bin in air_example.toml documentation file.

Is full_bin just dead code?

@jwarner112
Copy link
Author

jwarner112 commented Feb 2, 2025

To get this working I can indeed switch to the TOML file; glad to know I'm not crazy.

@alex-dna-tech
Copy link

Ok. Lets make test of TOML configuration:
main.go file

user@host:env$ cat <<EOF > main.go
package main

import (
        "fmt"
        "os"
)

func main() {
        fmt.Println("Print env ENV:")
        fmt.Println(os.Getenv("ENV"))
        fmt.Println("Print ARGS:")
        fmt.Printf("%+v\n", os.Args[1:])
}
EOF

.air.toml

user@host:env$ cat <<EOF > .air.toml
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
  args_bin = ["args","-","bin"]
  bin = "./main test-cli-arg-bin"
  cmd = "go build -o ./main main.go"
  delay = 1000
  exclude_dir = ["assets", "tmp", "vendor", "testdata"]
  exclude_file = []
  exclude_regex = ["_test.go"]
  exclude_unchanged = false
  follow_symlink = false
  full_bin = "ENV=test-Full_bin ./main test-arg-cli-full_bin"
  include_dir = []
  include_ext = ["go", "tpl", "tmpl", "html"]
  include_file = []
  kill_delay = "0s"
  log = "build-errors.log"
  poll = false
  poll_interval = 0
  post_cmd = []
  pre_cmd = []
  rerun = false
  rerun_delay = 500
  send_interrupt = false
  stop_on_error = false

[color]
  app = ""
  build = "yellow"
  main = "magenta"
  runner = "green"
  watcher = "cyan"

[log]
  main_only = false
  silent = false
  time = false

[misc]
  clean_on_exit = false

[proxy]
  app_port = 0
  enabled = false
  proxy_port = 0

[screen]
  clear_on_rebuild = false
  keep_scroll = true
EOF
user@host:env$ air

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.61.7, built with Go go1.23.5

watching .
!exclude tmp
building...
running...
Print env ENV:
test-Full_bin
Print ARGS:
[test-arg-cli-full_bin args - bin]
Process Exit with Code 0

Seems full_bin option has priority in this case and work as documented and expected.

@alex-dna-tech
Copy link

We can use bin option with CLI by split env+bin execution in bin option and move args to args_bin option:

user@host:env$ air --build.cmd "go build -o main main.go" --build.bin "ENV=test-bin ./main" --build.args_bin "test-ar-cli-bin" --build.include_file "main.go"

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.61.7, built with Go go1.23.5

watching .
watching main.go
!exclude tmp
building...
running...
Print env ENV:
test-bin
Print ARGS:
[test-ar-cli-bin]
Process Exit with Code 0
^Ccleaning...
see you again~

@alex-dna-tech
Copy link

Another way to use bin option is execute shell scripts or make targets: as in engine_test.go file

@jwarner112
Copy link
Author

Excellent, thanks for the alternative options. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants