Skip to content

Commit a30f629

Browse files
committed
Fix workdir passing through toolexec
1 parent a89dd5f commit a30f629

File tree

5 files changed

+8
-28
lines changed

5 files changed

+8
-28
lines changed

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ go 1.23.0
88
require (
99
github.com/dave/dst v0.27.3
1010
github.com/stretchr/testify v1.10.0
11-
github.com/urfave/cli/v2 v2.27.7
1211
github.com/urfave/cli/v3 v3.4.1
1312
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
1413
gopkg.in/yaml.v3 v3.0.1
1514
)
1615

1716
require (
18-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
1917
github.com/davecgh/go-spew v1.1.1 // indirect
2018
github.com/pmezard/go-difflib v1.0.0 // indirect
21-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
22-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
2319
golang.org/x/sys v0.13.0 // indirect
2420
golang.org/x/tools v0.1.12 // indirect
2521
)

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
31
github.com/dave/dst v0.27.3 h1:P1HPoMza3cMEquVf9kKy8yXsFirry4zEnWOdYPOoIzY=
42
github.com/dave/dst v0.27.3/go.mod h1:jHh6EOibnHgcUW3WjKHisiooEkYwqpHLBSX1iOBhEyc=
53
github.com/dave/jennifer v1.5.0 h1:HmgPN93bVDpkQyYbqhCHj5QlgvUkvEOzMyEvKLgCRrg=
@@ -8,18 +6,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
86
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
97
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
108
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
12-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
139
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
1410
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
1511
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1612
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
17-
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
18-
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
1913
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
2014
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
21-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
22-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
2315
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
2416
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
2517
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=

tool/cmd/cmd-toolexec.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55

66
import (
77
"context"
8-
"os"
98

109
"github.com/open-telemetry/opentelemetry-go-compile-instrumentation/tool/internal/instrument"
1110
"github.com/urfave/cli/v3"
@@ -17,14 +16,7 @@ var commandToolexec = cli.Command{
1716
Description: "Wrap a command run by the go toolchain",
1817
SkipFlagParsing: true,
1918
Hidden: true,
20-
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
21-
_, ok := os.LookupEnv("TOOLEXEC_IMPORT_PATH")
22-
if !ok {
23-
return ctx, cli.Exit("toolexec can only be invoked by the go toolchain", exitCodeUsageError)
24-
}
25-
26-
return addLoggerPhaseAttribute(ctx, cmd)
27-
},
19+
Before: addLoggerPhaseAttribute,
2820
Action: func(ctx context.Context, cmd *cli.Command) error {
2921
err := instrument.Toolexec(ctx, cmd.Args().Slice())
3022
if err != nil {

tool/cmd/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ func initLogger(ctx context.Context, cmd *cli.Command) (context.Context, error)
6464

6565
// Create a custom handler with shorter time format
6666
// Remove time and level keys as they make no sense for debugging
67-
var handler slog.Handler
68-
handler = slog.NewTextHandler(writer, &slog.HandlerOptions{
67+
handler := slog.NewTextHandler(writer, &slog.HandlerOptions{
6968
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
7069
if a.Key == slog.TimeKey || a.Key == slog.LevelKey {
7170
return slog.Attr{}

tool/internal/setup/setup.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ func BuildWithToolexec(ctx context.Context, args []string) error {
8989
if err != nil {
9090
return ex.Errorf(err, "failed to get executable path")
9191
}
92-
insert := "-toolexec=" + execPath
93-
newArgs := make([]string, 0, len(args)+1) // Avoid in-place modification
94-
newArgs = append(newArgs, args[:2]...) // Add "go build"
95-
newArgs = append(newArgs, insert) // Add "-toolexec=..."
96-
newArgs = append(newArgs, args[2:]...) // Add the rest
92+
insert := "-toolexec=" + execPath + " --work-dir=" + util.GetOtelWorkDir() + " toolexec"
93+
newArgs := make([]string, 0, len(args)+2) // Avoid in-place modification
94+
newArgs = append(newArgs, "go")
95+
newArgs = append(newArgs, args[:2]...) // Add "go build"
96+
newArgs = append(newArgs, insert) // Add "-toolexec=..."
97+
newArgs = append(newArgs, args[2:]...) // Add the rest
9798
logger.InfoContext(ctx, "Running go build with toolexec", "args", newArgs)
9899

99100
// Tell the sub-process the working directory

0 commit comments

Comments
 (0)