Skip to content

Commit afc98c4

Browse files
committed
- changed ARDUIFINE content to be " MACRO " or " MACRO = VALUE "
- added ARDUINOGLOBAL to be "-DMACRO=VALUE" (previous ARDUIFINE behavior) - added message on console, example: Additional compiler options provided by User sketch: "-DMACRO="VALUE"" Sketch uses 1372 bytes (4%) of program storage space. Maximum is 32256 bytes. Global variables use 192 bytes (9%) of dynamic memory, leaving 1856 bytes for local variables. Maximum is 2048 bytes.
1 parent 95edd3f commit afc98c4

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

legacy/builder/builder_utils/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ 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 + " ")
232+
if len(ctx.Arduifines) > 0 {
233+
properties.Set(constants.BUILD_PROPERTIES_INCLUDES, properties.Get(constants.BUILD_PROPERTIES_INCLUDES) + " " + ctx.Arduifines + " ")
234+
}
233235
properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source)
234236
relativeSource, err := sourcePath.RelTo(source)
235237
if err != nil {

legacy/builder/ctags/ctags_parser.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const TEMPLATE = "template"
3333
const STATIC = "static"
3434
const EXTERN = "extern \"C\""
3535
const ARDUIFINE = "ARDUIFINE"
36+
const ARDUINOGLOBAL = "ARDUINOGLOBAL"
3637

3738
var KNOWN_TAG_KINDS = map[string]bool{
3839
"prototype": true,
@@ -52,8 +53,10 @@ func (p *CTagsParser) Parse(ctagsOutput string, mainFile *paths.Path) ([]*types.
5253
p.mainFile = mainFile
5354

5455
for _, row := range rows {
55-
if strings.Index(row, " "+ARDUIFINE) != -1 {
56-
Arduifines += extractString(row)
56+
if strings.Index(row, " "+ARDUINOGLOBAL) != -1 {
57+
Arduifines += encloseForCmdLine(extractCtagsDoubleQuotedString(row, ARDUINOGLOBAL))
58+
} else if strings.Index(row, " "+ARDUIFINE) != -1 {
59+
Arduifines += encloseForCmdLine(toCompilerCmdLine(extractCtagsDoubleQuotedString(row, ARDUIFINE)))
5760
} else {
5861
p.tags = append(p.tags, parseTag(row))
5962
}
@@ -245,12 +248,33 @@ func removeEmpty(rows []string) []string {
245248
return newRows
246249
}
247250

248-
func extractString (row string) string {
251+
func extractCtagsDoubleQuotedString (row string, directive string) string {
249252
first := strings.Index(row, "\"");
250253
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")
254+
if (first <= 0) || (last <= 0) || (first + 1 >= last) {
255+
//print("\nERROR: malformed \"" + directive + "\" global directive\n\n")
253256
return ""
254257
}
255-
return " " + strings.Replace(strings.Replace(row[first+1 : last], "\\\\", "\\", -1), "\\\"", "\"", -1) + " "
258+
return strings.Replace(strings.Replace(row[first+1 : last], "\\\\", "\\", -1), "\\\"", "\"", -1)
259+
}
260+
261+
func toCompilerCmdLine (define string) string {
262+
// transforms ` A = "B C" ` to `-DA="B C"`
263+
// transforms ` A ` to `-DA`
264+
elts := strings.SplitAfterN(define, "=", 2)
265+
ret := ""
266+
if len(elts) > 0 {
267+
ret += "-D"+strings.TrimSpace(elts[0][:len(elts[0])-1])
268+
if len(elts) > 1 {
269+
ret += "="+strings.TrimSpace(elts[1])
270+
}
271+
}
272+
return ret
273+
}
274+
275+
func encloseForCmdLine (str string) string {
276+
if len(str) > 0 {
277+
return " \""+str+"\" "
278+
}
279+
return ""
256280
}

legacy/builder/phases/libraries_builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
4444
return errors.WithStack(err)
4545
}
4646

47+
if len(ctx.Arduifines) > 0 {
48+
ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Additional compiler options provided by User sketch: "+ctx.Arduifines)
49+
}
50+
4751
objectFiles, err := compileLibraries(ctx, libs, librariesBuildPath, buildProperties, includes)
4852
if err != nil {
4953
return errors.WithStack(err)

0 commit comments

Comments
 (0)