-
Notifications
You must be signed in to change notification settings - Fork 918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows compilation of code using debug.BuildInfo and show correct tinygo version #4343
Changes from 3 commits
11ffebb
1d4f0e7
41dd04a
f90b5c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.DS_Store | ||
.vscode | ||
go.work | ||
go.work.sum | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
// Package debug is a dummy package that is not yet implemented. | ||
package debug | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// SetMaxStack sets the maximum amount of memory that can be used by a single | ||
// goroutine stack. | ||
// | ||
|
@@ -27,16 +34,17 @@ func Stack() []byte { | |
// | ||
// Not implemented. | ||
func ReadBuildInfo() (info *BuildInfo, ok bool) { | ||
return nil, false | ||
return &BuildInfo{GoVersion: runtime.Compiler + runtime.Version()}, true | ||
} | ||
|
||
// BuildInfo represents the build information read from | ||
// the running binary. | ||
type BuildInfo struct { | ||
ldemailly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Path string // The main package path | ||
Main Module // The module containing the main package | ||
Deps []*Module // Module dependencies | ||
Settings []BuildSetting | ||
GoVersion string // version of the Go toolchain that built the binary, e.g. "go1.19.2" | ||
Path string // The main package path | ||
Main Module // The module containing the main package | ||
Deps []*Module // Module dependencies | ||
Settings []BuildSetting | ||
} | ||
|
||
type BuildSetting struct { | ||
|
@@ -58,3 +66,60 @@ type Module struct { | |
func SetGCPercent(n int) int { | ||
return n | ||
} | ||
|
||
// Start of stolen from big go. TODO: import/reuse without copy pasta. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do believe a copyright notice should be copied here...? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn’t this covered by https://github.com/tinygo-org/tinygo/blob/release/LICENSE#L3 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the copyright folks like to have a greppable marker in each file. I like the way runtime/timer.go does it: copy the three top llines from the file you're copying, and change "Copyright" to "Portions copyright". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I was looking for an example, thanks for mentioning src/runtime/timer.go Done |
||
|
||
// quoteKey reports whether key is required to be quoted. | ||
func quoteKey(key string) bool { | ||
return len(key) == 0 || strings.ContainsAny(key, "= \t\r\n\"`") | ||
} | ||
|
||
// quoteValue reports whether value is required to be quoted. | ||
func quoteValue(value string) bool { | ||
return strings.ContainsAny(value, " \t\r\n\"`") | ||
} | ||
|
||
func (bi *BuildInfo) String() string { | ||
buf := new(strings.Builder) | ||
if bi.GoVersion != "" { | ||
fmt.Fprintf(buf, "go\t%s\n", bi.GoVersion) | ||
} | ||
if bi.Path != "" { | ||
fmt.Fprintf(buf, "path\t%s\n", bi.Path) | ||
} | ||
var formatMod func(string, Module) | ||
formatMod = func(word string, m Module) { | ||
buf.WriteString(word) | ||
buf.WriteByte('\t') | ||
buf.WriteString(m.Path) | ||
buf.WriteByte('\t') | ||
buf.WriteString(m.Version) | ||
if m.Replace == nil { | ||
buf.WriteByte('\t') | ||
buf.WriteString(m.Sum) | ||
} else { | ||
buf.WriteByte('\n') | ||
formatMod("=>", *m.Replace) | ||
} | ||
buf.WriteByte('\n') | ||
} | ||
if bi.Main != (Module{}) { | ||
formatMod("mod", bi.Main) | ||
} | ||
for _, dep := range bi.Deps { | ||
formatMod("dep", *dep) | ||
} | ||
for _, s := range bi.Settings { | ||
key := s.Key | ||
if quoteKey(key) { | ||
key = strconv.Quote(key) | ||
} | ||
value := s.Value | ||
if quoteValue(value) { | ||
value = strconv.Quote(value) | ||
} | ||
fmt.Fprintf(buf, "build\t%s=%s\n", key, value) | ||
} | ||
|
||
return buf.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's still kinda dummy - I was wondering about the comment
and figured to leave it as it's... only giving an empty one (no modules, no settings etc) except for GoVersion