Display diagnostic message for each conversion error.
Also, use better names for the error handling entities. Bug: 204062171 Test: manual Change-Id: I65869120ed08fc40d9ec6267c882e53aaedde9ed
This commit is contained in:
@@ -81,7 +81,7 @@ func init() {
|
|||||||
|
|
||||||
var backupSuffix string
|
var backupSuffix string
|
||||||
var tracedVariables []string
|
var tracedVariables []string
|
||||||
var errorLogger = errorsByType{data: make(map[string]datum)}
|
var errorLogger = errorSink{data: make(map[string]datum)}
|
||||||
var makefileFinder = &LinuxMakefileFinder{}
|
var makefileFinder = &LinuxMakefileFinder{}
|
||||||
var versionDefaultsMk = filepath.Join("build", "make", "core", "version_defaults.mk")
|
var versionDefaultsMk = filepath.Join("build", "make", "core", "version_defaults.mk")
|
||||||
|
|
||||||
@@ -339,9 +339,7 @@ func convertOne(mkFile string) (ok bool) {
|
|||||||
WarnPartialSuccess: !*noWarn,
|
WarnPartialSuccess: !*noWarn,
|
||||||
SourceFS: os.DirFS(*rootDir),
|
SourceFS: os.DirFS(*rootDir),
|
||||||
MakefileFinder: makefileFinder,
|
MakefileFinder: makefileFinder,
|
||||||
}
|
ErrorLogger: errorLogger,
|
||||||
if *errstat {
|
|
||||||
mk2starRequest.ErrorLogger = errorLogger
|
|
||||||
}
|
}
|
||||||
ss, err := mk2rbc.Convert(mk2starRequest)
|
ss, err := mk2rbc.Convert(mk2starRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -456,10 +454,8 @@ func printStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if *verbose {
|
if *verbose && (nPartial > 0 || nFailed > 0) {
|
||||||
fmt.Fprintf(os.Stderr, "%-16s%5d\n", "Succeeded:", nOk)
|
fmt.Fprintln(os.Stderr, "Succeeded: ", nOk, " Partial: ", nPartial, " Failed: ", nFailed)
|
||||||
fmt.Fprintf(os.Stderr, "%-16s%5d\n", "Partial:", nPartial)
|
|
||||||
fmt.Fprintf(os.Stderr, "%-16s%5d\n", "Failed:", nFailed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,11 +464,18 @@ type datum struct {
|
|||||||
formattingArgs []string
|
formattingArgs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type errorsByType struct {
|
type errorSink struct {
|
||||||
data map[string]datum
|
data map[string]datum
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ebt errorsByType) NewError(message string, node parser.Node, args ...interface{}) {
|
func (ebt errorSink) NewError(sourceFile string, sourceLine int, node parser.Node, message string, args ...interface{}) {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s:%d ", sourceFile, sourceLine)
|
||||||
|
fmt.Fprintf(os.Stderr, message, args...)
|
||||||
|
fmt.Fprintln(os.Stderr)
|
||||||
|
if !*errstat {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
v, exists := ebt.data[message]
|
v, exists := ebt.data[message]
|
||||||
if exists {
|
if exists {
|
||||||
v.count++
|
v.count++
|
||||||
@@ -497,7 +500,7 @@ func (ebt errorsByType) NewError(message string, node parser.Node, args ...inter
|
|||||||
ebt.data[message] = v
|
ebt.data[message] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ebt errorsByType) printStatistics() {
|
func (ebt errorSink) printStatistics() {
|
||||||
if len(ebt.data) > 0 {
|
if len(ebt.data) > 0 {
|
||||||
fmt.Fprintln(os.Stderr, "Error counts:")
|
fmt.Fprintln(os.Stderr, "Error counts:")
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ type Request struct {
|
|||||||
RootDir string // root directory path used to resolve included files
|
RootDir string // root directory path used to resolve included files
|
||||||
OutputSuffix string // generated Starlark files suffix
|
OutputSuffix string // generated Starlark files suffix
|
||||||
OutputDir string // if set, root of the output hierarchy
|
OutputDir string // if set, root of the output hierarchy
|
||||||
ErrorLogger ErrorMonitorCB
|
ErrorLogger ErrorLogger
|
||||||
TracedVariables []string // trace assignment to these variables
|
TracedVariables []string // trace assignment to these variables
|
||||||
TraceCalls bool
|
TraceCalls bool
|
||||||
WarnPartialSuccess bool
|
WarnPartialSuccess bool
|
||||||
@@ -169,10 +169,10 @@ type Request struct {
|
|||||||
MakefileFinder MakefileFinder
|
MakefileFinder MakefileFinder
|
||||||
}
|
}
|
||||||
|
|
||||||
// An error sink allowing to gather error statistics.
|
// ErrorLogger prints errors and gathers error statistics.
|
||||||
// NewError is called on every error encountered during processing.
|
// Its NewError function is called on every error encountered during the conversion.
|
||||||
type ErrorMonitorCB interface {
|
type ErrorLogger interface {
|
||||||
NewError(s string, node mkparser.Node, args ...interface{})
|
NewError(sourceFile string, sourceLine int, node mkparser.Node, text string, args ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derives module name for a given file. It is base name
|
// Derives module name for a given file. It is base name
|
||||||
@@ -381,6 +381,7 @@ type StarlarkScript struct {
|
|||||||
warnPartialSuccess bool
|
warnPartialSuccess bool
|
||||||
sourceFS fs.FS
|
sourceFS fs.FS
|
||||||
makefileFinder MakefileFinder
|
makefileFinder MakefileFinder
|
||||||
|
nodeLocator func(pos mkparser.Pos) int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *StarlarkScript) newNode(node starlarkNode) {
|
func (ss *StarlarkScript) newNode(node starlarkNode) {
|
||||||
@@ -406,7 +407,7 @@ type parseContext struct {
|
|||||||
fatalError error
|
fatalError error
|
||||||
builtinMakeVars map[string]starlarkExpr
|
builtinMakeVars map[string]starlarkExpr
|
||||||
outputSuffix string
|
outputSuffix string
|
||||||
errorLogger ErrorMonitorCB
|
errorLogger ErrorLogger
|
||||||
tracedVariables map[string]bool // variables to be traced in the generated script
|
tracedVariables map[string]bool // variables to be traced in the generated script
|
||||||
variables map[string]variable
|
variables map[string]variable
|
||||||
varAssignments *varAssignmentScope
|
varAssignments *varAssignmentScope
|
||||||
@@ -1031,7 +1032,7 @@ func (ctx *parseContext) parseCondition(check *mkparser.Directive) starlarkNode
|
|||||||
func (ctx *parseContext) newBadExpr(node mkparser.Node, text string, args ...interface{}) starlarkExpr {
|
func (ctx *parseContext) newBadExpr(node mkparser.Node, text string, args ...interface{}) starlarkExpr {
|
||||||
message := fmt.Sprintf(text, args...)
|
message := fmt.Sprintf(text, args...)
|
||||||
if ctx.errorLogger != nil {
|
if ctx.errorLogger != nil {
|
||||||
ctx.errorLogger.NewError(text, node, args)
|
ctx.errorLogger.NewError(ctx.script.mkFile, ctx.script.nodeLocator(node.Pos()), node, text, args...)
|
||||||
}
|
}
|
||||||
ctx.script.hasErrors = true
|
ctx.script.hasErrors = true
|
||||||
return &badExpr{node, message}
|
return &badExpr{node, message}
|
||||||
@@ -1554,11 +1555,12 @@ func (ctx *parseContext) carryAsComment(failedNode mkparser.Node) {
|
|||||||
// records that the given node failed to be converted and includes an explanatory message
|
// records that the given node failed to be converted and includes an explanatory message
|
||||||
func (ctx *parseContext) errorf(failedNode mkparser.Node, message string, args ...interface{}) {
|
func (ctx *parseContext) errorf(failedNode mkparser.Node, message string, args ...interface{}) {
|
||||||
if ctx.errorLogger != nil {
|
if ctx.errorLogger != nil {
|
||||||
ctx.errorLogger.NewError(message, failedNode, args...)
|
ctx.errorLogger.NewError(ctx.script.mkFile, ctx.script.nodeLocator(failedNode.Pos()), failedNode, message, args...)
|
||||||
}
|
}
|
||||||
message = fmt.Sprintf(message, args...)
|
message = fmt.Sprintf(message, args...)
|
||||||
ctx.insertComment(fmt.Sprintf("# MK2RBC TRANSLATION ERROR: %s", message))
|
ctx.insertComment(fmt.Sprintf("# MK2RBC TRANSLATION ERROR: %s", message))
|
||||||
ctx.carryAsComment(failedNode)
|
ctx.carryAsComment(failedNode)
|
||||||
|
|
||||||
ctx.script.hasErrors = true
|
ctx.script.hasErrors = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1675,6 +1677,7 @@ func Convert(req Request) (*StarlarkScript, error) {
|
|||||||
warnPartialSuccess: req.WarnPartialSuccess,
|
warnPartialSuccess: req.WarnPartialSuccess,
|
||||||
sourceFS: req.SourceFS,
|
sourceFS: req.SourceFS,
|
||||||
makefileFinder: req.MakefileFinder,
|
makefileFinder: req.MakefileFinder,
|
||||||
|
nodeLocator: func(pos mkparser.Pos) int { return parser.Unpack(pos).Line },
|
||||||
}
|
}
|
||||||
ctx := newParseContext(starScript, nodes)
|
ctx := newParseContext(starScript, nodes)
|
||||||
ctx.outputSuffix = req.OutputSuffix
|
ctx.outputSuffix = req.OutputSuffix
|
||||||
|
Reference in New Issue
Block a user