pw_build: Make sure the stamp file's dir exists
In some circumstances with pw_python_action_foreach, a stamp file's
directory doesn't exist when the file needs to be created.
Change-Id: I774db40a7e190278594afa2215ed2008b449b24a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/42580
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_build/py/pw_build/python_runner.py b/pw_build/py/pw_build/python_runner.py
index b719650..15ce00e 100755
--- a/pw_build/py/pw_build/python_runner.py
+++ b/pw_build/py/pw_build/python_runner.py
@@ -502,7 +502,11 @@
elif touch:
# If a stamp file is provided and the command executed successfully,
# touch the stamp file to indicate a successful run of the command.
+ touch = touch.resolve()
_LOG.debug('TOUCH %s', touch)
+
+ # Create the parent directory in case GN / Ninja hasn't created it.
+ touch.parent.mkdir(parents=True, exist_ok=True)
touch.touch()
return completed_process.returncode