Skip to content

Commit

Permalink
support garble run
Browse files Browse the repository at this point in the history
It's the third time I've wanted it to quickly test out standalone
reproducers when people submit bugs.

Fixes #661.
  • Loading branch information
mvdan authored and lu4p committed Apr 10, 2023
1 parent d1da066 commit cd003ea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions testdata/script/run.txtar
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit cd003ea

Please sign in to comment.