Skip to content

Commit 5567c95

Browse files
authored
Merge pull request #1086 from ydb-platform/clean-gtrace
Clean gtrace
2 parents f29bef1 + 0f9bf94 commit 5567c95

File tree

3 files changed

+6
-41
lines changed

3 files changed

+6
-41
lines changed

internal/cmd/gtrace/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gtrace
2+
gtrace.exe

internal/cmd/gtrace/gtrace

-10.2 MB
Binary file not shown.

internal/cmd/gtrace/main.go

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@ import (
1616
"os"
1717
"path/filepath"
1818
"strings"
19-
_ "unsafe" // For go:linkname.
2019

2120
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
2221
)
2322

24-
//go:linkname build_goodOSArchFile go/build.(*Context).goodOSArchFile
25-
//nolint:revive
26-
func build_goodOSArchFile(*build.Context, string, map[string]bool) bool
27-
2823
//nolint:gocyclo
2924
func main() {
3025
var (
@@ -64,8 +59,6 @@ func main() {
6459

6560
var writers []*Writer
6661
if isGoGenerate {
67-
// We should respect Go suffixes like `_linux.go`.
68-
name, tags, ext := splitOSArchTags(&buildCtx, gofile)
6962
openFile := func(name string) (*os.File, func()) {
7063
var f *os.File
7164
//nolint:gofumpt
@@ -82,7 +75,9 @@ func main() {
8275

8376
return f, func() { f.Close() }
8477
}
85-
f, clean := openFile(name + "_gtrace" + tags + ext)
78+
ext := filepath.Ext(gofile)
79+
name := strings.TrimSuffix(gofile, ext)
80+
f, clean := openFile(name + "_gtrace" + ext)
8681
defer clean()
8782
writers = append(writers, &Writer{
8883
Context: buildCtx,
@@ -103,7 +98,7 @@ func main() {
10398
)
10499
fset := token.NewFileSet()
105100
for _, name := range buildPkg.GoFiles {
106-
base, _, _ := splitOSArchTags(&buildCtx, name)
101+
base := strings.TrimSuffix(name, filepath.Ext(name))
107102
if isGenerated(base, "_gtrace") {
108103
continue
109104
}
@@ -313,38 +308,6 @@ func buildFunc(info *types.Info, traces map[string]*Trace, fn *ast.FuncType) (re
313308
)
314309
}
315310

316-
func splitOSArchTags(ctx *build.Context, name string) (base, tags, ext string) {
317-
fileTags := make(map[string]bool)
318-
build_goodOSArchFile(ctx, name, fileTags)
319-
ext = filepath.Ext(name)
320-
switch len(fileTags) {
321-
case 0: // *
322-
base = strings.TrimSuffix(name, ext)
323-
324-
case 1: // *_GOOS or *_GOARCH
325-
i := strings.LastIndexByte(name, '_')
326-
327-
base = name[:i]
328-
tags = strings.TrimSuffix(name[i:], ext)
329-
330-
case 2: // *_GOOS_GOARCH
331-
var i int
332-
i = strings.LastIndexByte(name, '_')
333-
i = strings.LastIndexByte(name[:i], '_')
334-
335-
base = name[:i]
336-
tags = strings.TrimSuffix(name[i:], ext)
337-
338-
default:
339-
panic(fmt.Sprintf(
340-
"gtrace: internal error: unexpected number of OS/arch tags: %d",
341-
len(fileTags),
342-
))
343-
}
344-
345-
return
346-
}
347-
348311
type Package struct {
349312
*types.Package
350313

0 commit comments

Comments
 (0)