Skip to content

Commit bd48cad

Browse files
committed
Tools - mkbuildoptglobals refactoring & attempt to fix caching
Optional include for build-dir header to exclude it from core.a when no build opts are created / used. Preventive reads before writes, too Plus, missing change to makecorever.py doing read before write Prefer to use --output-dir in scripts, tests/device *must* be out-of-tree for caching to work properly (avoid changing core nested dirs) Assume 'aggressive caching' is normal mode of operation, no need for special treatment (can be checked by looking at .d files in the build dir) Even CI uses arduino-cli ~/.cache/arduino/{sketch,core} for building Allow sketches without globals.h to share core.a, rebuild otherwise (same sketch cache is retained, core.a & .o's reused) Drop manual logging in favour of 'import logging'. Arduino-CLI might still need tweaks in debug mode, though. Output flushing does not always happen promptly. Allow multiple entries for the same name, which are then merged. Allow spaces between @ and the signature words. Allow to use line right after signature. Syntax warnings show relevant snippet from globals.h
1 parent 4214e16 commit bd48cad

File tree

11 files changed

+1076
-769
lines changed

11 files changed

+1076
-769
lines changed

.github/workflows/build-host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Run host test suite under valgrind for runtime checking of code.
2-
# Also, a quick test that the mocking builds work at all
2+
# Also, a quick test that the mock builds are actually working
33

44
name: Build on host OS
55

.github/workflows/build-ide.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
13-
# Examples are built in parallel to avoid CI total job time limitation
12+
# download toolchain and check whether gcc basic .c compilation works
1413
sanity-check:
1514
runs-on: ubuntu-latest
1615
defaults:
@@ -28,6 +27,23 @@ jobs:
2827
run: |
2928
bash ./tests/sanity_check.sh
3029
30+
# verify that any scripts that will or may be used by the builder are working
31+
tooling-check:
32+
runs-on: ubuntu-latest
33+
defaults:
34+
run:
35+
shell: bash
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
submodules: false
40+
- uses: actions/setup-python@v5
41+
with:
42+
python-version: '3.x'
43+
- run: |
44+
python ./tools/test_mkbuildoptglobals.py --quiet
45+
46+
# Examples are built in parallel to avoid CI total job time limitation
3147
build-linux:
3248
name: Linux - LwIP ${{ matrix.lwip }} (${{ matrix.chunk }})
3349
runs-on: ubuntu-latest

package/build_boards_manager_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ $SED -E "s/name=([a-zA-Z0-9\ -]+).*/name=\1(${ver})/g"\
117117
#echo "#define ARDUINO_ESP8266_GIT_DESC `git describe --tags 2>/dev/null`" >>${outdir}/cores/esp8266/core_version.h
118118
#echo "#define ARDUINO_ESP8266_RELEASE_${ver_define}" >>${outdir}/cores/esp8266/core_version.h
119119
#echo "#define ARDUINO_ESP8266_RELEASE \"${ver_define}\"" >>${outdir}/cores/esp8266/core_version.h
120-
python3 ${srcdir}/tools/makecorever.py -b ${outdir} -i cores/esp8266 -p ${srcdir} -v ${plain_ver} -r
120+
python3 ${srcdir}/tools/makecorever.py --git-root ${srcdir} --version ${plain_ver} --release ${outdir}/cores/esp8266/core_version.h
121121

122122
# Zip the package
123123
pushd package/versions/${visiblever}

platform.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,19 @@ build.spiffs_blocksize=
6666
build.iramfloat=-DFP_IN_IROM
6767

6868
# Fully qualified file names for processing sketch global options
69-
globals.h.source.fqfn={build.source.path}/{build.project_name}.globals.h
70-
commonhfile.fqfn={build.core.path}/CommonHFile.h
71-
build.opt.fqfn={build.path}/core/build.opt
69+
globals.h.build.source.fqfn={build.source.path}/{build.project_name}.globals.h
70+
globals.h.build.fqfn={build.path}/{build.project_name}.globals.h
71+
common.h.fqfn={build.core.path}/CommonHFile.h
72+
build.opt.fqfn={build.path}/sketch/build.opt
7273
build.opt.flags="@{build.opt.fqfn}"
7374
mkbuildoptglobals.extra_flags=
7475

7576
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
7677
compiler.sdk.path={runtime.platform.path}/tools/sdk
7778

7879
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
79-
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 {build.debug_optim} {build.opt.flags} "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
80+
compiler.cpreprocessor.extra_flags=
81+
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 {build.debug_optim} {build.opt.flags} "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core" {compiler.cpreprocessor.extra_flags}
8082

8183
# support precompiled libraries in IDE v1.8.6+
8284
compiler.libraries.ldflags=
@@ -123,8 +125,8 @@ recipe.hooks.sketch.prebuild.pattern="{runtime.tools.python3.path}/python3" -I "
123125
# This is quite a working hack. This form of prebuild hook, while intuitive, is not explicitly documented.
124126
recipe.hooks.prebuild.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.makecorever}" --git-root "{runtime.platform.path}" --version "{version}" "{build.path}/core/core_version.h"
125127

126-
# Handle processing sketch global options
127-
recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.mkbuildoptglobals}" "{runtime.ide.path}" {runtime.ide.version} "{build.path}" "{build.opt.fqfn}" "{globals.h.source.fqfn}" "{commonhfile.fqfn}" {mkbuildoptglobals.extra_flags}
128+
# Handle core & sketch global options
129+
recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.mkbuildoptglobals}" {mkbuildoptglobals.extra_flags} build --build-opt "{build.opt.fqfn}" --source-sketch-header "{globals.h.build.source.fqfn}" --build-sketch-header "{globals.h.build.fqfn}" --common-header "{common.h.fqfn}"
128130

129131

130132
## Build the app.ld linker file

tests/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function build_sketches()
132132
build_cmd+=${cli_path}
133133
build_cmd+=" compile"\
134134
" --warnings=all"\
135-
" --build-path $build_dir"\
135+
" --output-path $build_dir"\
136136
" --fqbn $fqbn"\
137137
" --libraries $library_path"\
138138
" --output-dir $build_out"
@@ -311,7 +311,7 @@ function install_core()
311311
printf "%s\n" \
312312
"compiler.c.extra_flags=-Wall -Wextra $debug_flags" \
313313
"compiler.cpp.extra_flags=-Wall -Wextra $debug_flags" \
314-
"mkbuildoptglobals.extra_flags=--ci --cache_core" \
314+
"recipe.hooks.prebuild.1.pattern=\"{runtime.tools.python3.path}/python3\" -I \"{runtime.tools.makecorever}\" --git-root \"{runtime.platform.path}\" --version \"{version}\" \"{runtime.platform.path}/cores/esp8266/core_version.h\"" \
315315
> ${core_path}/platform.local.txt
316316
echo -e "\n----platform.local.txt----"
317317
cat platform.local.txt

tests/device/Makefile

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ SHELL := /bin/bash
22

33
ESP8266_CORE_PATH ?= $(shell git rev-parse --show-toplevel)
44

5+
# arduino-cli core/ & sketch/ build and cache directories
6+
# by default, share build location with every other sketch
7+
CACHE_DIR ?= $(HOME)/.cache/arduino
8+
ifneq ("$(findstring $(ESP8266_CORE_PATH),$(CACHE_DIR))", "")
9+
$(warning "CACHE_DIR is located in ESP8266_CORE_PATH, core.a caching will be disabled")
10+
endif
11+
12+
# binaries (compile --output-dir=...) & test output goes in here.
513
BUILD_DIR ?= $(PWD)/build
14+
15+
# where to look for BSTest scripts
616
BS_DIR ?= $(PWD)/libraries/BSTest
717

818
PYTHON ?= python3
@@ -67,7 +77,7 @@ list: showtestlist
6777

6878
all: count tests test_report
6979

70-
$(TEST_LIST): | virtualenv $(TEST_CONFIG) $(BUILD_DIR) $(HARDWARE_DIR)
80+
$(TEST_LIST): | virtualenv $(TEST_CONFIG) $(CACHE_DIR) $(BUILD_DIR) $(HARDWARE_DIR)
7181

7282
.NOTPARALLEL: $(TEST_LIST)
7383

@@ -78,18 +88,21 @@ showtestlist:
7888
@printf '%s\n' $(TEST_LIST)
7989
@echo "--------------------------------"
8090

81-
$(TEST_LIST): LOCAL_BUILD_DIR=$(BUILD_DIR)/$(notdir $@)
82-
$(TEST_LIST): LOCAL_DATA_IMG=data.img
91+
$(TEST_LIST): LOCAL_BUILD_DIR=$(BUILD_DIR)/$(notdir $@)/
92+
$(TEST_LIST): LOCAL_TEST_RESULT_XML=$(LOCAL_BUILD_DIR)/$(TEST_RESULT_XML)
93+
$(TEST_LIST): LOCAL_DATA_DIR=$(LOCAL_BUILD_DIR)/data/
94+
$(TEST_LIST): LOCAL_DATA_IMG=$(LOCAL_BUILD_DIR)/data.img
8395

8496
define build-arduino
85-
rm -f $(LOCAL_BUILD_DIR)/build.options.json
86-
$(BUILD_TOOL) compile \
87-
$(BUILD_FLAGS) \
88-
--libraries "$(PWD)/libraries" \
89-
--warnings=all \
90-
--build-path $(LOCAL_BUILD_DIR) \
91-
--fqbn=$(FQBN) \
92-
$@
97+
export ARDUINO_BUILD_CACHE_PATH="$(CACHE_DIR)"; \
98+
$(BUILD_TOOL) config dump; \
99+
$(BUILD_TOOL) compile \
100+
$(BUILD_FLAGS) \
101+
--libraries "$(PWD)/libraries" \
102+
--output-dir "$(LOCAL_BUILD_DIR)" \
103+
--warnings=all \
104+
--fqbn=$(FQBN) \
105+
$@
93106
endef
94107

95108
define build-mock
@@ -98,7 +111,7 @@ define build-mock
98111
$(VENV_PYTHON) $(BS_DIR)/runner.py \
99112
$(BS_FLAGS) \
100113
--name $(basename $(notdir $@)) \
101-
--output $(LOCAL_BUILD_DIR)/$(TEST_RESULT_XML) \
114+
--output $(LOCAL_TEST_RESULT_XML) \
102115
--env-file $(TEST_CONFIG) \
103116
$(call mock_script,$@) \
104117
executable "$(ESP8266_CORE_PATH)/tests/host/bin/$(@:%.ino=%)" || echo ""`
@@ -111,17 +124,17 @@ define upload-data
111124
(cd $(dir $@) && ./make_data.py ) || echo "Filesystem creation skipped"
112125
@test -d $(dir $@)/data/ && ( \
113126
$(MKFS) \
114-
--create $(dir $@)/data/ \
127+
--create $(LOCAL_DATA_DIR) \
115128
--size 0xFB000 \
116129
--block 8192 \
117130
--page 256 \
118-
$(LOCAL_BUILD_DIR)/$(LOCAL_DATA_IMG) && \
131+
$(LOCAL_DATA_IMG) && \
119132
$(ESPTOOL) \
120133
--chip esp8266 \
121134
--port $(UPLOAD_PORT) \
122135
--baud $(UPLOAD_BAUD) \
123136
--after no_reset \
124-
write_flash 0x300000 $(LOCAL_BUILD_DIR)/$(LOCAL_DATA_IMG) ) \
137+
write_flash 0x300000 $(LOCAL_DATA_IMG) ) \
125138
&& (echo "Uploaded filesystem") \
126139
|| (echo "Filesystem upload skipped")
127140
endef
@@ -149,7 +162,7 @@ define run-test
149162
$(VENV_PYTHON) $(BS_DIR)/runner.py \
150163
$(BS_FLAGS) \
151164
--name $(basename $(notdir $@)) \
152-
--output $(LOCAL_BUILD_DIR)/$(TEST_RESULT_XML) \
165+
--output $(LOCAL_TEST_RESULT_XML) \
153166
--env-file $(TEST_CONFIG) \
154167
$(call mock_script,$@) \
155168
port $(UPLOAD_PORT) \
@@ -160,6 +173,7 @@ $(TEST_LIST):
160173
@echo "--------------------------------"
161174
@echo "Running test '$@' of $(words $(TEST_LIST)) tests"
162175
mkdir -p $(LOCAL_BUILD_DIR)
176+
mkdir -p $(CACHE_DIR)
163177
ifneq ("$(NO_BUILD)","1")
164178
@echo Building $(notdir $@)
165179
ifeq ("$(MOCK)", "1")
@@ -187,13 +201,17 @@ $(TEST_REPORT_HTML): $(TEST_REPORT_XML) | virtualenv
187201
test_report: $(TEST_REPORT_HTML)
188202
@echo "Test report generated in $(TEST_REPORT_HTML)"
189203

204+
$(CACHE_DIR):
205+
@mkdir -p $@
206+
190207
$(BUILD_DIR):
191-
@mkdir -p $(BUILD_DIR)
208+
@mkdir -p $@
192209

193210
virtualenv:
194211
@make -C $(BS_DIR) PYTHON=$(PYTHON) virtualenv
195212

196213
clean:
214+
rm -rf $(CACHE_DIR)
197215
rm -rf $(BUILD_DIR)
198216
rm -rf $(BS_DIR)/virtualenv
199217
rm -f $(TEST_REPORT_HTML) $(TEST_REPORT_XML)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/*@create-file:build.opt@
2-
32
-fno-builtin
43
*/

tests/sanity_check.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ source "$root/tests/common.sh"
55

66
pushd "$root"/tools
77
python3 get.py -q
8-
8+
python3 makecorever.py --git-root "$root" "$root/cores/esp8266/core_version.h"
99
popd
10+
1011
pushd "$cache_dir"
1112

1213
gcc="$root/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc"\

tools/makecorever.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def check_git(*args: str, cwd: Optional[str]):
5656

5757

5858
def generate(
59-
out: TextIO,
6059
*,
6160
git_root: pathlib.Path,
6261
hash_length: int = 8,
@@ -118,7 +117,7 @@ def git(*args):
118117
#define ARDUINO_ESP8266_DEV 1 // development version
119118
"""
120119

121-
out.write(text)
120+
return text
122121

123122

124123
if __name__ == "__main__":
@@ -158,20 +157,18 @@ def git(*args):
158157

159158
args = parser.parse_args()
160159

161-
def select_output(s: str) -> TextIO:
162-
if not s:
163-
return sys.stdout
160+
contents = generate(
161+
git_root=args.git_root,
162+
hash_length=args.hash_length,
163+
release=args.release,
164+
version=args.version,
165+
)
164166

165-
out = pathlib.Path(s)
167+
if args.output:
168+
out = pathlib.Path(args.output)
166169
out.parent.mkdir(parents=True, exist_ok=True)
167170

168-
return out.open("w", encoding="utf-8")
169-
170-
with select_output(args.output) as out:
171-
generate(
172-
out,
173-
git_root=args.git_root,
174-
hash_length=args.hash_length,
175-
release=args.release,
176-
version=args.version,
177-
)
171+
if not out.exists() or contents != out.read_text(encoding="utf-8"):
172+
out.write_text(contents, encoding="utf-8")
173+
else:
174+
print(contents, file=sys.stdout)

0 commit comments

Comments
 (0)