MCPcopy
hub / github.com/tinygo-org/tinygo / readRawGoBuildID

Function readRawGoBuildID

builder/buildid.go:111–127  ·  view source on GitHub ↗

The Go toolchain stores a build ID in the binary that we can use, as a fallback if binary file specific build IDs can't be obtained. This function reads that build ID from the binary.

(f *os.File, prefixSize int)

Source from the content-addressed store, hash-verified

109// fallback if binary file specific build IDs can't be obtained.
110// This function reads that build ID from the binary.
111func readRawGoBuildID(f *os.File, prefixSize int) ([]byte, error) {
112 fileStart := make([]byte, prefixSize)
113 _, err := io.ReadFull(f, fileStart)
114 if err != nil {
115 return nil, fmt.Errorf("could not read build id from %s: %v", f.Name(), err)
116 }
117 index := bytes.Index(fileStart, []byte("\xff Go build ID: \""))
118 if index < 0 || index > len(fileStart)-103 {
119 return nil, fmt.Errorf("could not find build id in %s", f.Name())
120 }
121 buf := fileStart[index : index+103]
122 if bytes.HasPrefix(buf, []byte("\xff Go build ID: \"")) && bytes.HasSuffix(buf, []byte("\"\n \xff")) {
123 return buf[len("\xff Go build ID: \"") : len(buf)-1], nil
124 }
125
126 return nil, nil
127}

Callers 1

ReadBuildIDFunction · 0.85

Calls 3

ErrorfMethod · 0.65
NameMethod · 0.65
IndexMethod · 0.45

Tested by

no test coverage detected