Skip to content

Commit 27d34e7

Browse files
committed
[build] Fix relative openocd paths when relocating outpath
1 parent 98a2483 commit 27d34e7

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

tools/build_script_generator/module.lb

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def prepare(module, options):
132132
if is_cortex_m:
133133
module.add_collector(
134134
PathCollector(name="openocd.source",
135-
description="Additional OpenOCD source files."))
135+
description=descr_opencd_source))
136136
module.add_collector(
137137
PathCollector(name="path.openocd",
138-
description="Search path for OpenOCD configuration files"))
138+
description="Search path for OpenOCD configuration files."))
139139

140140
if platform == "sam":
141141
module.add_collector(
@@ -242,7 +242,10 @@ def post_build(env):
242242
# prepare custom path
243243
openocd_cfg = env.get(":build:openocd.cfg", "")
244244
if len(openocd_cfg):
245-
env.substitutions["openocd_user_path"] = env.relative_outpath(openocd_cfg)
245+
env.substitutions["openocd_user_path"] = env.relcwdoutpath(openocd_cfg)
246+
env.substitutions["openocd_search_dirs"] = \
247+
[env.relcwdoutpath(path) for path in env.collector_values("path.openocd")]
248+
env.substitutions["openocd_sources"] = env.collector_values("openocd.source")
246249

247250
has_rtt = env.has_module(":platform:rtt")
248251
env.substitutions["has_rtt"] = has_rtt
@@ -308,3 +311,31 @@ projects using the same target (like small bring-up and test projects).
308311
and do not execute them by default. A stray `init` or similar in your script
309312
will mess with modm's ability to program and debug a device correctly.
310313
"""
314+
315+
descr_opencd_source = """# Additional OpenOCD source files
316+
317+
You can add multiple source files that will get included by the generated
318+
`modm/openocd.cfg` to provide a default config for targets and boards.
319+
You can add source files that are shipped with OpenOCD, for example,
320+
`board/stm32f469discovery.cfg`, or custom source files from your own repository.
321+
322+
To avoid name clashes with the built-in config files, you should copy your own
323+
source files into a separate folder and add it as a search path:
324+
325+
```py
326+
def build(env):
327+
# Add a custom folder to the OpenOCD search paths
328+
env.collect("modm:build:path.openocd", "repo/src/openocd/")
329+
330+
# Namespace this folder with your repository name to prevent name clashes
331+
env.outbasepath = "repo/src/openocd/repo/board"
332+
env.copy("board.cfg", "name.cfg")
333+
# Now use a *relative* path to the source file inside this folder
334+
env.collect("modm:build:openocd.source", "repo/board/name.cfg")
335+
336+
# Alternatively for a target config
337+
env.outbasepath = "repo/src/openocd/repo/target"
338+
env.copy("target.cfg", "name.cfg")
339+
env.collect("modm:build:openocd.source", "repo/target/name.cfg")
340+
```
341+
"""

tools/build_script_generator/openocd.cfg.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
%% for path in collector_values["path.openocd"] | sort
1+
%% for path in openocd_search_dirs | sort
22
add_script_search_dir {{ path | modm.windowsify(escape_level=1) }}
33
%% endfor
44
%# Include the users config before the modm config
55
%% if openocd_user_path is defined
66
source [find {{ openocd_user_path | modm.windowsify(escape_level=1) }}]
77
%% endif
8-
%% for file in collector_values["openocd.source"] | sort
8+
%% for file in openocd_sources | sort
99
source [find {{ file | modm.windowsify(escape_level=1) }}]
1010
%% endfor
1111

0 commit comments

Comments
 (0)