Skip to content

Commit d867acc

Browse files
committed
ARDUIFINE: global compiler options extracted from ctags parsing
Example: these lines in the ino file: char ARDUIFINE_1 = "-DMYLIB_BUFFER_LEN=1234"; char ARDUIFINE_2 = "-DMYLIB2_PARAM"; will globally enable the following line in the compiler command: -DMYLIB_BUFFER_LEN=1234 -DMYLIB2_PARAM That, including during compilation of the core and libraries. The symbols ARDUIFINExxx, if they are not otherwise used by the sketch, are normally excluded from the final binary at link time.
1 parent 6a177eb commit d867acc

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

legacy/builder/builder_utils/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
229229
properties := buildProperties.Clone()
230230
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel))
231231
properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includes, constants.SPACE))
232+
properties.Set(constants.BUILD_PROPERTIES_INCLUDES, properties.Get(constants.BUILD_PROPERTIES_INCLUDES) + " " + ctx.Arduifines + " ")
232233
properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source)
233234
relativeSource, err := sourcePath.RelTo(source)
234235
if err != nil {

legacy/builder/ctags/ctags_parser.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const KIND_FUNCTION = "function"
3232
const TEMPLATE = "template"
3333
const STATIC = "static"
3434
const EXTERN = "extern \"C\""
35+
const ARDUIFINE = "ARDUIFINE"
3536

3637
var KNOWN_TAG_KINDS = map[string]bool{
3738
"prototype": true,
@@ -43,14 +44,19 @@ type CTagsParser struct {
4344
mainFile *paths.Path
4445
}
4546

46-
func (p *CTagsParser) Parse(ctagsOutput string, mainFile *paths.Path) []*types.CTag {
47+
func (p *CTagsParser) Parse(ctagsOutput string, mainFile *paths.Path) ([]*types.CTag, string) {
48+
Arduifines := ""
4749
rows := strings.Split(ctagsOutput, "\n")
4850
rows = removeEmpty(rows)
4951

5052
p.mainFile = mainFile
5153

5254
for _, row := range rows {
53-
p.tags = append(p.tags, parseTag(row))
55+
if strings.Index(row, " "+ARDUIFINE) != -1 {
56+
Arduifines += extractString(row)
57+
} else {
58+
p.tags = append(p.tags, parseTag(row))
59+
}
5460
}
5561

5662
p.skipTagsWhere(tagIsUnknown)
@@ -60,7 +66,7 @@ func (p *CTagsParser) Parse(ctagsOutput string, mainFile *paths.Path) []*types.C
6066
p.skipDuplicates()
6167
p.skipTagsWhere(p.prototypeAndCodeDontMatch)
6268

63-
return p.tags
69+
return p.tags, Arduifines
6470
}
6571

6672
func (p *CTagsParser) addPrototypes() {
@@ -238,3 +244,13 @@ func removeEmpty(rows []string) []string {
238244

239245
return newRows
240246
}
247+
248+
func extractString (row string) string {
249+
first := strings.Index(row, "\"");
250+
last := strings.LastIndex(row, "\";$/;\""); // <- $/;" is a ctag addition
251+
if (first <= 0 || last <= 0 || first + 1 > last - 1) {
252+
//print("\nERROR: malformed \"" + ARDUIFINE + "\" global directive\n\n")
253+
return ""
254+
}
255+
return " " + strings.Replace(strings.Replace(row[first+1 : last], "\\\\", "\\", -1), "\\\"", "\"", -1) + " "
256+
}

legacy/builder/ctags_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *CTagsRunner) Run(ctx *types.Context) error {
5656

5757
parser := &ctags.CTagsParser{}
5858

59-
ctx.CTagsOfPreprocessedSource = parser.Parse(ctx.CTagsOutput, ctx.Sketch.MainFile.Name)
59+
ctx.CTagsOfPreprocessedSource, ctx.Arduifines = parser.Parse(ctx.CTagsOutput, ctx.Sketch.MainFile.Name)
6060
parser.FixCLinkageTagsDeclarations(ctx.CTagsOfPreprocessedSource)
6161

6262
protos, line := parser.GeneratePrototypes()

legacy/builder/types/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ type Context struct {
174174
// The provided source data is used instead of reading it from disk.
175175
// The keys of the map are paths relative to sketch folder.
176176
SourceOverride map[string]string
177+
178+
// compiler options from ctags extraction
179+
// example: 'char ARDUIFINEyyy = "<compiler options like> -DMYLIB_BUFFER_LEN=1234 -include \"somefile.h\"";'
180+
Arduifines string
177181
}
178182

179183
// ExecutableSectionSize represents a section of the executable output file

0 commit comments

Comments
 (0)