mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to v0.16.0-rc1
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
107
vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go
generated
vendored
107
vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go
generated
vendored
@ -16,6 +16,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SourceInfoMap func(*pb.SourceInfo) *pb.SourceInfo
|
||||
|
||||
const RequestLint = "frontend.lint"
|
||||
|
||||
var SubrequestLintDefinition = subrequests.Request{
|
||||
@ -39,6 +41,27 @@ type Warning struct {
|
||||
Location pb.Location `json:"location,omitempty"`
|
||||
}
|
||||
|
||||
func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo, scb SourceInfoMap) error {
|
||||
fmt.Fprintf(wr, "\nWARNING: %s", w.RuleName)
|
||||
if w.URL != "" {
|
||||
fmt.Fprintf(wr, " - %s", w.URL)
|
||||
}
|
||||
fmt.Fprintf(wr, "\n%s\n", w.Detail)
|
||||
|
||||
if w.Location.SourceIndex < 0 {
|
||||
return nil
|
||||
}
|
||||
sourceInfo := sources[w.Location.SourceIndex]
|
||||
if scb != nil {
|
||||
sourceInfo = scb(sourceInfo)
|
||||
}
|
||||
source := errdefs.Source{
|
||||
Info: sourceInfo,
|
||||
Ranges: w.Location.Ranges,
|
||||
}
|
||||
return source.Print(wr)
|
||||
}
|
||||
|
||||
type BuildError struct {
|
||||
Message string `json:"message"`
|
||||
Location pb.Location `json:"location"`
|
||||
@ -93,7 +116,7 @@ func (results *LintResults) AddWarning(rulename, description, url, fmtmsg string
|
||||
})
|
||||
}
|
||||
|
||||
func (results *LintResults) ToResult() (*client.Result, error) {
|
||||
func (results *LintResults) ToResult(scb SourceInfoMap) (*client.Result, error) {
|
||||
res := client.NewResult()
|
||||
dt, err := json.MarshalIndent(results, "", " ")
|
||||
if err != nil {
|
||||
@ -102,7 +125,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
|
||||
res.AddMeta("result.json", dt)
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
if err := PrintLintViolations(dt, b); err != nil {
|
||||
if err := PrintLintViolations(dt, b, scb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.AddMeta("result.txt", b.Bytes())
|
||||
@ -117,28 +140,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (results *LintResults) validateWarnings() error {
|
||||
for _, warning := range results.Warnings {
|
||||
if int(warning.Location.SourceIndex) >= len(results.Sources) {
|
||||
return errors.Errorf("sourceIndex is out of range")
|
||||
}
|
||||
if warning.Location.SourceIndex > 0 {
|
||||
warningSource := results.Sources[warning.Location.SourceIndex]
|
||||
if warningSource == nil {
|
||||
return errors.Errorf("sourceIndex points to nil source")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrintLintViolations(dt []byte, w io.Writer) error {
|
||||
var results LintResults
|
||||
|
||||
if err := json.Unmarshal(dt, &results); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (results *LintResults) PrintTo(w io.Writer, scb SourceInfoMap) error {
|
||||
if err := results.validateWarnings(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -169,21 +171,7 @@ func PrintLintViolations(dt []byte, w io.Writer) error {
|
||||
})
|
||||
|
||||
for _, warning := range results.Warnings {
|
||||
fmt.Fprintf(w, "\nWARNING: %s", warning.RuleName)
|
||||
if warning.URL != "" {
|
||||
fmt.Fprintf(w, " - %s", warning.URL)
|
||||
}
|
||||
fmt.Fprintf(w, "\n%s\n", warning.Detail)
|
||||
|
||||
if warning.Location.SourceIndex < 0 {
|
||||
continue
|
||||
}
|
||||
sourceInfo := results.Sources[warning.Location.SourceIndex]
|
||||
source := errdefs.Source{
|
||||
Info: sourceInfo,
|
||||
Ranges: warning.Location.Ranges,
|
||||
}
|
||||
err := source.Print(w)
|
||||
err := warning.PrintTo(w, results.Sources, scb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -192,6 +180,47 @@ func PrintLintViolations(dt []byte, w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (results *LintResults) PrintErrorTo(w io.Writer) {
|
||||
// This prints out the error in LintResults to the writer in a format that
|
||||
// is consistent with the warnings for easier downstream consumption.
|
||||
if results.Error == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, results.Error.Message)
|
||||
sourceInfo := results.Sources[results.Error.Location.SourceIndex]
|
||||
source := errdefs.Source{
|
||||
Info: sourceInfo,
|
||||
Ranges: results.Error.Location.Ranges,
|
||||
}
|
||||
source.Print(w)
|
||||
}
|
||||
|
||||
func (results *LintResults) validateWarnings() error {
|
||||
for _, warning := range results.Warnings {
|
||||
if int(warning.Location.SourceIndex) >= len(results.Sources) {
|
||||
return errors.Errorf("sourceIndex is out of range")
|
||||
}
|
||||
if warning.Location.SourceIndex > 0 {
|
||||
warningSource := results.Sources[warning.Location.SourceIndex]
|
||||
if warningSource == nil {
|
||||
return errors.Errorf("sourceIndex points to nil source")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrintLintViolations(dt []byte, w io.Writer, scb SourceInfoMap) error {
|
||||
var results LintResults
|
||||
|
||||
if err := json.Unmarshal(dt, &results); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return results.PrintTo(w, scb)
|
||||
}
|
||||
|
||||
func sourceInfoEqual(a, b *pb.SourceInfo) bool {
|
||||
if a.Filename != b.Filename || a.Language != b.Language {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user