Tools: Close temporary file before invoking external tools accessing it

This commit is contained in:
Roland Dobai
2020-07-28 18:19:19 +02:00
parent 7abb8e7fc3
commit 6bec17308c

View File

@ -71,7 +71,7 @@ def action_extensions(base_actions, project_path=os.getcwd()):
new_cache_values["TEST_COMPONENTS"] = config.get("TEST_COMPONENTS", "''") new_cache_values["TEST_COMPONENTS"] = config.get("TEST_COMPONENTS", "''")
new_cache_values["TESTS_ALL"] = int(new_cache_values["TEST_COMPONENTS"] == "''") new_cache_values["TESTS_ALL"] = int(new_cache_values["TEST_COMPONENTS"] == "''")
with tempfile.NamedTemporaryFile() as sdkconfig_temp: with tempfile.NamedTemporaryFile(delete=False) as sdkconfig_temp:
# Use values from the combined defaults and the values from # Use values from the combined defaults and the values from
# config folder to build config # config folder to build config
sdkconfig_default = os.path.join(project_path, "sdkconfig.defaults") sdkconfig_default = os.path.join(project_path, "sdkconfig.defaults")
@ -84,13 +84,18 @@ def action_extensions(base_actions, project_path=os.getcwd()):
sdkconfig_temp.write(b"\n") sdkconfig_temp.write(b"\n")
sdkconfig_temp.write(sdkconfig_config_file.read()) sdkconfig_temp.write(sdkconfig_config_file.read())
sdkconfig_temp.flush()
new_cache_values["SDKCONFIG_DEFAULTS"] = sdkconfig_temp.name new_cache_values["SDKCONFIG_DEFAULTS"] = sdkconfig_temp.name
try:
args.define_cache_entry.extend(["%s=%s" % (k, v) for k, v in new_cache_values.items()]) args.define_cache_entry.extend(["%s=%s" % (k, v) for k, v in new_cache_values.items()])
reconfigure = base_actions["actions"]["reconfigure"]["callback"] reconfigure = base_actions["actions"]["reconfigure"]["callback"]
reconfigure(None, ctx, args) reconfigure(None, ctx, args)
finally:
try:
os.unlink(sdkconfig_temp.name)
except OSError:
pass
# This target builds the configuration. It does not currently track dependencies, # This target builds the configuration. It does not currently track dependencies,
# but is good enough for CI builds if used together with clean-all-configs. # but is good enough for CI builds if used together with clean-all-configs.