Skip to content

Commit 4fdfd3b

Browse files
committed
Added context help for build option support
1 parent dc74e03 commit 4fdfd3b

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

doc/faq/a06-global-build-options.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ How to specify global build defines and options
22
===============================================
33

44
To create global defines for a Sketch, create a file with a name based
5-
on your sketch’s file name followed by ``.globals.h`` in the Sketch folder.
6-
For example, if the main Sketch file is named
5+
on your sketch’s file name followed by ``.globals.h`` in the Sketch
6+
folder. For example, if the main Sketch file is named
77
``LowWatermark.ino``, its global defines file would be
88
``LowWatermark.ino.globals.h``. This file will be implicitly included
99
with every module built for your Sketch. Do not directly include it in
@@ -21,9 +21,10 @@ command option.
2121
Actions taken in processing comment block to create ``build.opt`` \* for
2222
each line, white space is trimmed \* blank lines are skipped \* lines
2323
starting with ``*``, ``//``, or ``#`` are skipped \* the remaining
24-
results are written to build tree\ ``/core/build.opt`` \* ``build.opt``
25-
is finished with a ``-include ...`` command, which references the global
26-
.h its contents were extracted from.
24+
results are written to build tree\ ``/core/build.opt`` \* multiple
25+
``/*@create-file:build.opt@`` ``*/`` comment blocks are not allowed \*
26+
``build.opt`` is finished with a ``-include ...`` command, which
27+
references the global .h its contents were extracted from.
2728

2829
Example Sketch: ``LowWatermark.ino``
2930

@@ -72,7 +73,7 @@ Global ``.h`` file: ``LowWatermark.ino.globals.h``
7273
#endif
7374
7475
#if defined(__cplusplus)
75-
// Defines kept private to .cpp modules
76+
// Defines kept private to .cpp and .ino modules
7677
//#pragma message("__cplusplus has been seen")
7778
#define MYTITLE2 "Empty"
7879
#endif
@@ -93,14 +94,14 @@ Aggressive Caching of ``core.a``
9394

9495
Using global defines or compiler command-line options will lead to bad
9596
builds when the **Aggressively cache compiled core** feature is enabled.
96-
When ``#define`` changes require ``core.a`` to be recompiled, and
97-
multiple Sketches are open, they can no longer reliably share one cached
97+
When ``#define`` changes require rebuilding ``core.a`` and multiple
98+
Sketches are open, they can no longer reliably share one cached
9899
``core.a``. In a simple case: The 1st Sketch to be built has its version
99100
of ``core.a`` cached. Other sketches will use this cached version for
100101
their builds.
101102

102103
To turn this off, you need to find the location of ``preferences.txt``.
103-
Using the Arduino IDE, go to *File->Preferences*. Make note of the path
104+
From the Arduino IDE, go to *File->Preferences*. Make note of the path
104105
to ``prefereces.txt``. You cannot edit the file while the Arduino IDE is
105106
running. Close all Arduino IDE windows and edit the file
106107
``preferences.txt``. Change ``compiler.cache_core=true`` to
@@ -113,11 +114,12 @@ Sketch that uses global defines.
113114
Other build confusion
114115
=====================
115116

116-
1. Renaming files does not change the last modified timestamp, possibly
117-
causing issues when replacing files by renaming and rebuilding. A good
117+
1. Renaming a file does not change the last modified timestamp, possibly
118+
causing issues when adding a file by renaming and rebuilding. A good
118119
example of this problem would be to have then fixed a typo in file
119120
name ``LowWatermark.ino.globals.h``. You need to touch (update
120121
timestamp) the file so a “rebuild all” is performed.
122+
121123
2. When a ``.h`` file is renamed in the sketch folder, a copy of the old
122124
file remains in the build sketch folder. This can create confusion if
123125
you missed an edit in updating an ``#include`` in one or more of your

tools/mkbuildoptglobals.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
# existing embedded documentation methods.
188188
build_opt_signature = "/*@create-file:build.opt@"
189189

190+
docs_url = "https://arduino-esp8266.readthedocs.io/en/latest/faq/a06-global-build-options.html"
190191

191192
def print_msg(*args, **kwargs):
192193
print(*args, flush=True, **kwargs)
@@ -307,6 +308,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
307308
build_opt.close()
308309
return complete_comment
309310

311+
310312
def get_sketchbook_globals(build_path, sketchbook_globals_path, build_opt_fqfn):
311313
"""
312314
Construct path to sketchbook globals using relative path from users home directory.
@@ -321,6 +323,7 @@ def get_sketchbook_globals(build_path, sketchbook_globals_path, build_opt_fqfn):
321323

322324
def main():
323325
global build_opt_signature
326+
global docs_url
324327

325328
if len(sys.argv) >= 4:
326329
source_globals_h_fqfn = os.path.normpath(sys.argv[1])
@@ -353,7 +356,9 @@ def main():
353356
# positives. Only report when globals.h is being used.
354357
if os.path.getsize(globals_h_fqfn) and len(os.listdir(build_path)) < 20:
355358
print_err("Aggressive caching of core.a might be enabled. This may create build errors.")
356-
print_err("Suggest turning off in preferences.txt: \"compiler.cache_core=false\"")
359+
print_err(" Suggest turning off in preferences.txt: \"compiler.cache_core=false\"")
360+
print_err(" Read more at " + docs_url)
361+
357362
else:
358363
# Info: When platform.txt, platform.local.txt, or IDE Tools are
359364
# changed, our build path directory was cleaned. Note,
@@ -371,16 +376,26 @@ def main():
371376
# controls the rebuild on change. We can always extact a new build.opt
372377
# w/o triggering a needless rebuild.
373378
embedded_options = extract_create_build_opt_file(globals_h_fqfn, globals_name, build_opt_fqfn)
374-
if not embedded_options and os.path.exists(source_globals_h_fqfn):
375-
print_msg("To add embedded compiler options, include them in a block comment starting with '" + build_opt_signature + "'." )
379+
380+
# Provide context help for build option support.
381+
source_build_opt_h_fqfn = os.path.join(os.path.dirname(source_globals_h_fqfn), "build_opt.h")
382+
if os.path.exists(source_build_opt_h_fqfn) and not embedded_options:
383+
print_err("Build options file '" + source_build_opt_h_fqfn + "' not supported.")
384+
print_err(" Add build option content to '" + source_globals_h_fqfn + "'.")
385+
print_err(" Embedd compiler command-line options in a block comment starting with '" + build_opt_signature + "'.")
386+
print_err(" Read more at " + docs_url)
387+
elif os.path.exists(source_globals_h_fqfn):
388+
if not embedded_options:
389+
print_msg("Tip: Embedd compiler command-line options in a block comment starting with '" + build_opt_signature + "'.")
390+
print_msg(" Read more at " + docs_url)
376391

377392
add_include_line(build_opt_fqfn, globals_h_fqfn)
378393

379394
if len(sketchbook_globals_path):
380395
get_sketchbook_globals(build_path, sketchbook_globals_path, build_opt_fqfn)
381396

382397
else:
383-
print_err("Too few arguments. Required arguments:")
398+
print_err("Too few arguments. Add arguments:")
384399
print_err(" Source FQFN SketchName.ino.globals.h, Build FQFN SketchName.ino.globals.h, Build FQFN build.opt")
385400

386401
if __name__ == '__main__':

0 commit comments

Comments
 (0)