Skip to content

Commit e755138

Browse files
author
Federico Fissore
committed
Added debug logging to CTagsParser, turned on only when debug level >= 10
Signed-off-by: Federico Fissore <[email protected]>
1 parent fe14f45 commit e755138

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

Diff for: src/arduino.cc/builder/constants/constants.go

+3
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ const MSG_RUNNING_COMMAND = "Running: {0}"
225225
const MSG_RUNNING_RECIPE = "Running recipe: {0}"
226226
const MSG_SETTING_BUILD_PATH = "Setting build path to {0}"
227227
const MSG_SKETCH_CANT_BE_IN_BUILDPATH = "Sketch cannot be located in build path. Please specify a different build path"
228+
const MSG_SKIPPING_TAG_ALREADY_DEFINED = "Skipping tag {0} because prototype is already defined"
229+
const MSG_SKIPPING_TAG_BECAUSE_HAS_FIELD = "Skipping tag {0} because it has field {0}"
230+
const MSG_SKIPPING_TAG_WITH_REASON = "Skipping tag {0}. Reason: {1}"
228231
const MSG_UNHANDLED_TYPE_IN_CONTEXT = "Unhandled type {0} in context key {1}"
229232
const MSG_UNKNOWN_SKETCH_EXT = "Unknown sketch file extension: {0}"
230233
const MSG_USING_LIBRARY_AT_VERSION = "Using library {0} at version {1} in folder: {2} {3}"

Diff for: src/arduino.cc/builder/ctags_parser.go

+22-21
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/utils"
35+
"os"
36+
"reflect"
37+
"runtime"
3438
"strconv"
3539
"strings"
3640
)
@@ -71,13 +75,13 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
7175
tags = append(tags, parseTag(row))
7276
}
7377

74-
skipTagsWhere(tags, tagIsUnknown)
75-
skipTagsWithField(tags, FIELDS_MARKING_UNHANDLED_TAGS)
76-
skipTagsWhere(tags, signatureContainsDefaultArg)
78+
skipTagsWhere(tags, tagIsUnknown, context)
79+
skipTagsWithField(tags, FIELDS_MARKING_UNHANDLED_TAGS, context)
80+
skipTagsWhere(tags, signatureContainsDefaultArg, context)
7781
addPrototypes(tags)
78-
removeDefinedProtypes(tags)
82+
removeDefinedProtypes(tags, context)
7983
removeDuplicate(tags)
80-
skipTagsWhere(tags, prototypeAndCodeDontMatch)
84+
skipTagsWhere(tags, prototypeAndCodeDontMatch, context)
8185

8286
context[constants.CTX_CTAGS_OF_PREPROC_SOURCE] = tags
8387

@@ -113,7 +117,7 @@ func addPrototype(tag map[string]string) {
113117
tag[KIND_PROTOTYPE_MODIFIERS] = strings.TrimSpace(tag[KIND_PROTOTYPE_MODIFIERS])
114118
}
115119

116-
func removeDefinedProtypes(tags []map[string]string) {
120+
func removeDefinedProtypes(tags []map[string]string, context map[string]interface{}) {
117121
definedPrototypes := make(map[string]bool)
118122
for _, tag := range tags {
119123
if tag[FIELD_KIND] == KIND_PROTOTYPE {
@@ -123,6 +127,9 @@ func removeDefinedProtypes(tags []map[string]string) {
123127

124128
for _, tag := range tags {
125129
if definedPrototypes[tag[KIND_PROTOTYPE]] {
130+
if utils.DebugLevel(context) >= 10 {
131+
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag[FIELD_FUNCTION_NAME])
132+
}
126133
tag[FIELD_SKIP] = TRUE
127134
}
128135
}
@@ -142,12 +149,12 @@ func removeDuplicate(tags []map[string]string) {
142149

143150
type skipFuncType func(tag map[string]string) bool
144151

145-
func skipTagsWhere(tags []map[string]string, skipFuncs ...skipFuncType) {
152+
func skipTagsWhere(tags []map[string]string, skipFunc skipFuncType, context map[string]interface{}) {
146153
for _, tag := range tags {
147154
if tag[FIELD_SKIP] != TRUE {
148-
skip := skipFuncs[0](tag)
149-
for _, skipFunc := range skipFuncs[1:] {
150-
skip = skip || skipFunc(tag)
155+
skip := skipFunc(tag)
156+
if skip && utils.DebugLevel(context) >= 10 {
157+
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_WITH_REASON, tag[FIELD_FUNCTION_NAME], runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
151158
}
152159
tag[FIELD_SKIP] = strconv.FormatBool(skip)
153160
}
@@ -180,23 +187,17 @@ func removeSpacesAndTabs(s string) string {
180187
return s
181188
}
182189

183-
func skipTagsWithField(tags []map[string]string, fields []string) {
190+
func skipTagsWithField(tags []map[string]string, fields []string, context map[string]interface{}) {
184191
for _, tag := range tags {
185-
if tagHasAtLeastOneField(tag, fields) {
192+
if field, skip := utils.TagHasAtLeastOneField(tag, fields); skip {
193+
if utils.DebugLevel(context) >= 10 {
194+
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_BECAUSE_HAS_FIELD, field)
195+
}
186196
tag[FIELD_SKIP] = TRUE
187197
}
188198
}
189199
}
190200

191-
func tagHasAtLeastOneField(tag map[string]string, fields []string) bool {
192-
for _, field := range fields {
193-
if tag[field] != constants.EMPTY_STRING {
194-
return true
195-
}
196-
}
197-
return false
198-
}
199-
200201
func tagIsUnknown(tag map[string]string) bool {
201202
return !KNOWN_TAG_KINDS[tag[FIELD_KIND]]
202203
}

Diff for: src/arduino.cc/builder/ctags_to_prototypes.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ func collectFunctionNames(tags []map[string]string) []string {
109109

110110
func firstFunctionAtLine(tags []map[string]string) (int, error) {
111111
for _, tag := range tags {
112-
if !tagIsUnknown(tag) && !tagHasAtLeastOneField(tag, FIELDS_MARKING_UNHANDLED_TAGS) && tag[FIELD_KIND] == KIND_FUNCTION {
112+
_, tagHasAtLeastOneField := utils.TagHasAtLeastOneField(tag, FIELDS_MARKING_UNHANDLED_TAGS)
113+
if !tagIsUnknown(tag) && !tagHasAtLeastOneField && tag[FIELD_KIND] == KIND_FUNCTION {
113114
return strconv.Atoi(tag[FIELD_LINE])
114115
}
115116
}

Diff for: src/arduino.cc/builder/test/prototypes_adder_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) {
6060
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
6161
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
6262
context[constants.CTX_VERBOSE] = true
63+
context[constants.CTX_DEBUG_LEVEL] = 10
6364

6465
commands := []types.Command{
6566
&builder.SetupHumanLoggerIfMissing{},
@@ -101,6 +102,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) {
101102
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
102103
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
103104
context[constants.CTX_VERBOSE] = true
105+
context[constants.CTX_DEBUG_LEVEL] = 10
104106

105107
commands := []types.Command{
106108
&builder.SetupHumanLoggerIfMissing{},
@@ -142,6 +144,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) {
142144
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
143145
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
144146
context[constants.CTX_VERBOSE] = true
147+
context[constants.CTX_DEBUG_LEVEL] = 10
145148

146149
commands := []types.Command{
147150
&builder.SetupHumanLoggerIfMissing{},
@@ -183,6 +186,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) {
183186
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
184187
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
185188
context[constants.CTX_VERBOSE] = true
189+
context[constants.CTX_DEBUG_LEVEL] = 10
186190

187191
commands := []types.Command{
188192
&builder.SetupHumanLoggerIfMissing{},
@@ -224,6 +228,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) {
224228
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
225229
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
226230
context[constants.CTX_VERBOSE] = true
231+
context[constants.CTX_DEBUG_LEVEL] = 10
227232

228233
commands := []types.Command{
229234
&builder.SetupHumanLoggerIfMissing{},
@@ -265,6 +270,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) {
265270
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
266271
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
267272
context[constants.CTX_VERBOSE] = true
273+
context[constants.CTX_DEBUG_LEVEL] = 10
268274

269275
commands := []types.Command{
270276
&builder.SetupHumanLoggerIfMissing{},
@@ -306,6 +312,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) {
306312
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
307313
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
308314
context[constants.CTX_VERBOSE] = true
315+
context[constants.CTX_DEBUG_LEVEL] = 10
309316

310317
commands := []types.Command{
311318
&builder.SetupHumanLoggerIfMissing{},
@@ -347,6 +354,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
347354
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
348355
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
349356
context[constants.CTX_VERBOSE] = true
357+
context[constants.CTX_DEBUG_LEVEL] = 10
350358

351359
commands := []types.Command{
352360
&builder.SetupHumanLoggerIfMissing{},
@@ -391,6 +399,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
391399
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
392400
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
393401
context[constants.CTX_VERBOSE] = true
402+
context[constants.CTX_DEBUG_LEVEL] = 10
394403

395404
commands := []types.Command{
396405
&builder.SetupHumanLoggerIfMissing{},
@@ -435,6 +444,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) {
435444
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
436445
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
437446
context[constants.CTX_VERBOSE] = true
447+
context[constants.CTX_DEBUG_LEVEL] = 10
438448

439449
commands := []types.Command{
440450
&builder.SetupHumanLoggerIfMissing{},
@@ -476,6 +486,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) {
476486
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
477487
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
478488
context[constants.CTX_VERBOSE] = true
489+
context[constants.CTX_DEBUG_LEVEL] = 10
479490

480491
commands := []types.Command{
481492
&builder.SetupHumanLoggerIfMissing{},
@@ -520,6 +531,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) {
520531
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
521532
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
522533
context[constants.CTX_VERBOSE] = true
534+
context[constants.CTX_DEBUG_LEVEL] = 10
523535

524536
commands := []types.Command{
525537
&builder.SetupHumanLoggerIfMissing{},
@@ -564,6 +576,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
564576
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
565577
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
566578
context[constants.CTX_VERBOSE] = true
579+
context[constants.CTX_DEBUG_LEVEL] = 10
567580

568581
commands := []types.Command{
569582
&builder.SetupHumanLoggerIfMissing{},
@@ -608,6 +621,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
608621
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
609622
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
610623
context[constants.CTX_VERBOSE] = true
624+
context[constants.CTX_DEBUG_LEVEL] = 10
611625

612626
commands := []types.Command{
613627
&builder.SetupHumanLoggerIfMissing{},
@@ -652,6 +666,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) {
652666
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
653667
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
654668
context[constants.CTX_VERBOSE] = true
669+
context[constants.CTX_DEBUG_LEVEL] = 10
655670

656671
commands := []types.Command{
657672
&builder.SetupHumanLoggerIfMissing{},
@@ -695,6 +710,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {
695710
context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
696711
context[constants.CTX_LIBRARIES_FOLDERS] = []string{"libraries", "downloaded_libraries"}
697712
context[constants.CTX_VERBOSE] = true
713+
context[constants.CTX_DEBUG_LEVEL] = 10
698714

699715
commands := []types.Command{
700716
&builder.SetupHumanLoggerIfMissing{},
@@ -739,6 +755,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {
739755
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
740756
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
741757
context[constants.CTX_VERBOSE] = true
758+
context[constants.CTX_DEBUG_LEVEL] = 10
742759

743760
commands := []types.Command{
744761
&builder.SetupHumanLoggerIfMissing{},
@@ -786,6 +803,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) {
786803
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
787804
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
788805
context[constants.CTX_VERBOSE] = true
806+
context[constants.CTX_DEBUG_LEVEL] = 10
789807

790808
commands := []types.Command{
791809
&builder.SetupHumanLoggerIfMissing{},

Diff for: src/arduino.cc/builder/utils/utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,12 @@ func WriteFile(targetFilePath string, data string) error {
442442
func TouchFile(targetFilePath string) error {
443443
return WriteFileBytes(targetFilePath, []byte{})
444444
}
445+
446+
func TagHasAtLeastOneField(tag map[string]string, fields []string) (string, bool) {
447+
for _, field := range fields {
448+
if tag[field] != constants.EMPTY_STRING {
449+
return field, true
450+
}
451+
}
452+
return "", false
453+
}

0 commit comments

Comments
 (0)