support `garble run`

It's the third time I've wanted it to quickly test out standalone
reproducers when people submit bugs.

Fixes #661.
pull/720/head
Daniel Martí 1 year ago committed by lu4p
parent d1da066120
commit cd003eade0

@ -7,6 +7,7 @@ Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.20 or later.
garble build [build flags] [packages]
The tool also supports `garble test` to run tests with obfuscated code,
`garble run` to obfuscate and execute simple programs,
and `garble reverse` to de-obfuscate text such as stack traces.
See `garble -h` for up to date usage information.

@ -121,6 +121,7 @@ The following commands are supported:
build replace "go build"
test replace "go test"
run replace "go run"
reverse de-obfuscate output such as stack traces
version print the version and build settings of the garble binary
@ -396,7 +397,7 @@ func mainErr(args []string) error {
return nil
case "reverse":
return commandReverse(args)
case "build", "test":
case "build", "test", "run":
cmd, err := toolexecCmd(command, args)
defer os.RemoveAll(os.Getenv("GARBLE_SHARED"))
if err != nil {

@ -0,0 +1,29 @@
garble run garble_main.go
! stdout '^garble_main\.go 9$'
stdout '\.go \d'
[short] stop # no need to verify this with -short
# also with a package
garble run .
! stdout '^garble_main\.go 9$'
stdout '\.go \d'
go run garble_main.go
stdout 'garble_main\.go 9$'
-- go.mod --
module test/main
go 1.20
-- garble_main.go --
package main
import (
"fmt"
"runtime"
)
func main() {
_, file, line, _ := runtime.Caller(0)
fmt.Println(file, line)
}
Loading…
Cancel
Save