Skip to content

Commit 8b74855

Browse files
committed
Moved Include preprocessing and discovery fields into Context
Signed-off-by: Cristian Maglie <[email protected]>
1 parent 602e02b commit 8b74855

File tree

7 files changed

+21
-24
lines changed

7 files changed

+21
-24
lines changed

src/arduino.cc/builder/constants/constants.go

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path"
7373
const BUILD_PROPERTIES_TOOLS_KEY = "tools"
7474
const BUILD_PROPERTIES_VID = "vid"
7575
const CTAGS = "ctags"
76-
const CTX_INCLUDE_SECTION = "includeSection"
77-
const CTX_INCLUDES_JUST_FOUND = "includesJustFound"
78-
const CTX_LINE_OFFSET = "lineOffset"
7976
const EMPTY_STRING = ""
8077
const FILE_BOARDS_LOCAL_TXT = "boards.local.txt"
8178
const FILE_BOARDS_TXT = "boards.txt"

src/arduino.cc/builder/container_find_includes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s
114114
return i18n.WrapError(err)
115115
}
116116
}
117-
if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 {
117+
if len(ctx.IncludesJustFound) == 0 {
118118
done = true
119119
} else if len(ctx.ImportedLibraries) == len(importedLibraries) {
120120
err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
121121
return i18n.WrapError(err)
122122
}
123123
importedLibraries = ctx.ImportedLibraries
124-
context[constants.CTX_INCLUDES_JUST_FOUND] = []string{}
124+
ctx.IncludesJustFound = []string{}
125125
}
126126
return nil
127127
}

src/arduino.cc/builder/includes_finder_with_regexp.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package builder
3131

3232
import (
33-
"arduino.cc/builder/constants"
3433
"arduino.cc/builder/types"
3534
"arduino.cc/builder/utils"
3635
"regexp"
@@ -58,7 +57,7 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *type
5857
}
5958
}
6059

61-
context[constants.CTX_INCLUDES_JUST_FOUND] = includes
60+
ctx.IncludesJustFound = includes
6261
ctx.Includes = utils.AppendIfNotPresent(ctx.Includes, includes...)
6362
return nil
6463
}

src/arduino.cc/builder/prototypes_adder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context
5353
return nil
5454
}
5555

56-
insertionLine := firstFunctionLine + context[constants.CTX_LINE_OFFSET].(int) - 1
56+
insertionLine := firstFunctionLine + ctx.LineOffset - 1
5757
firstFunctionChar := len(strings.Join(sourceRows[:insertionLine], "\n")) + 1
5858
prototypeSection := composePrototypeSection(firstFunctionLine, ctx.Prototypes)
5959
ctx.PrototypesSection = prototypeSection

src/arduino.cc/builder/sketch_source_merger.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
package builder
3232

3333
import (
34-
"arduino.cc/builder/constants"
3534
"arduino.cc/builder/types"
3635
"regexp"
3736
"strings"
@@ -50,7 +49,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Cont
5049
}
5150
includeSection += "#line 1 \"" + strings.Replace((&sketch.MainFile).Name, "\\", "\\\\", -1) + "\"\n"
5251
lineOffset++
53-
context[constants.CTX_INCLUDE_SECTION] = includeSection
52+
ctx.IncludeSection = includeSection
5453

5554
source := includeSection
5655
source += addSourceWrappedWithLineDirective(&sketch.MainFile)
@@ -59,7 +58,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Cont
5958
source += addSourceWrappedWithLineDirective(&file)
6059
}
6160

62-
context[constants.CTX_LINE_OFFSET] = lineOffset
61+
ctx.LineOffset = lineOffset
6362
ctx.Source = source
6463

6564
return nil

src/arduino.cc/builder/test/prototypes_adder_test.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package test
3232

3333
import (
3434
"arduino.cc/builder"
35-
"arduino.cc/builder/constants"
3635
"arduino.cc/builder/types"
3736
"github.com/stretchr/testify/require"
3837
"os"
@@ -83,7 +82,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) {
8382
NoError(t, err)
8483
}
8584

86-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
85+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
8786
require.Equal(t, "#line 33 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 46 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 62 \""+absoluteSketchLocation+"\"\nvoid process(BridgeClient client);\n#line 82 \""+absoluteSketchLocation+"\"\nvoid digitalCommand(BridgeClient client);\n#line 109 \""+absoluteSketchLocation+"\"\nvoid analogCommand(BridgeClient client);\n#line 149 \""+absoluteSketchLocation+"\"\nvoid modeCommand(BridgeClient client);\n#line 33 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
8887
}
8988

@@ -419,7 +418,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
419418
NoError(t, err)
420419
}
421420

422-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
421+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
423422
require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
424423

425424
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context, ctx)
@@ -466,7 +465,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) {
466465
NoError(t, err)
467466
}
468467

469-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
468+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
470469
require.Equal(t, "", ctx.PrototypesSection)
471470
}
472471

@@ -510,7 +509,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) {
510509
NoError(t, err)
511510
}
512511

513-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
512+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
514513
require.Equal(t, "", ctx.PrototypesSection)
515514
}
516515

@@ -554,7 +553,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) {
554553
NoError(t, err)
555554
}
556555

557-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
556+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
558557
require.Equal(t, "#line 4 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 7 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
559558
}
560559

@@ -598,7 +597,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
598597
NoError(t, err)
599598
}
600599

601-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
600+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
602601

603602
expected := "#line 1 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 2 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 4 \"" + absoluteSketchLocation + "\"\nshort unsigned int testInt();\n#line 8 \"" + absoluteSketchLocation + "\"\nstatic int8_t testInline();\n#line 12 \"" + absoluteSketchLocation + "\"\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1 \"" + absoluteSketchLocation + "\"\n"
604603
obtained := ctx.PrototypesSection
@@ -653,7 +652,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
653652
NoError(t, err)
654653
}
655654

656-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
655+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
657656
require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 3 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 15 \""+absoluteSketchLocation+"\"\nint8_t adalight();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
658657
}
659658

@@ -697,7 +696,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) {
697696
NoError(t, err)
698697
}
699698

700-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
699+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
701700
require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid ciao();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 15 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
702701
}
703702

@@ -740,7 +739,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {
740739
NoError(t, err)
741740
}
742741

743-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
742+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
744743
expected := "#line 6 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 10 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 12 \"" + absoluteSketchLocation + "\"\ntypename Foo<char>::Bar func();\n#line 6 \"" + absoluteSketchLocation + "\"\n"
745744
obtained := ctx.PrototypesSection
746745
// ctags based preprocessing ignores line with typename
@@ -790,7 +789,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {
790789
NoError(t, err)
791790
}
792791

793-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
792+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
794793
require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
795794

796795
expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context, ctx)
@@ -837,7 +836,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) {
837836
NoError(t, err)
838837
}
839838

840-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
839+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
841840
require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
842841

843842
expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context, ctx)
@@ -884,7 +883,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
884883
NoError(t, err)
885884
}
886885

887-
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string))
886+
require.Equal(t, "#include <Arduino.h>\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection)
888887
require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection)
889888
}
890889

src/arduino.cc/builder/types/context.go

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Context struct {
5858
HeaderToLibraries map[string][]*Library
5959
ImportedLibraries []*Library
6060
LibrariesResolutionResults map[string]LibraryResolutionResult
61+
IncludesJustFound []string
6162
IncludeFolders []string
6263
OutputGccMinusM string
6364

@@ -67,6 +68,8 @@ type Context struct {
6768
CTagsOfSource []*CTag
6869
CTagsOfPreprocessedSource []*CTag
6970
CTagsCollected []*CTag
71+
IncludeSection string
72+
LineOffset int
7073
PrototypesSection string
7174
PrototypesLineWhereToInsert int
7275
Prototypes []*Prototype

0 commit comments

Comments
 (0)