ldgen: use user input filename for processed template

Previously ldgen determines the output file name on its own. This commit
makes it so that user can dictate what the output file name will be
for the processed template, if the user needs it for something else.
This commit is contained in:
Renz Christian Bagaporo 2019-05-31 11:30:44 +08:00
parent 70dfcb35d4
commit f0f861ccd9
4 changed files with 16 additions and 9 deletions

View file

@ -58,7 +58,8 @@ else()
# Process the template file through the linker script generation mechanism, and use the output for linking the
# final binary
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" PROCESS)
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld")
target_link_libraries(${COMPONENT_LIB} gcc)

View file

@ -27,7 +27,7 @@ endfunction()
#
# Passes a linker script template to the linker script generation tool for
# processing
function(__ldgen_process_template output_var template)
function(__ldgen_process_template template output)
idf_build_get_property(idf_target IDF_TARGET)
idf_build_get_property(idf_path IDF_PATH)
@ -36,11 +36,6 @@ function(__ldgen_process_template output_var template)
file(GENERATE OUTPUT ${build_dir}/ldgen_libraries.in CONTENT $<JOIN:${ldgen_libraries},\n>)
file(GENERATE OUTPUT ${build_dir}/ldgen_libraries INPUT ${build_dir}/ldgen_libraries.in)
get_filename_component(filename "${template}" NAME)
set(output ${CMAKE_CURRENT_BINARY_DIR}/${filename}.ld)
set(${output_var} ${output} PARENT_SCOPE)
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${build_dir}/ldgen_libraries.in"

View file

@ -131,13 +131,14 @@ endfunction()
# and then adds -T with the filename only. This allows INCLUDE directives to be
# used to include other linker scripts in the same directory.
function(target_linker_script target scriptfiles)
cmake_parse_arguments(_ "PROCESS" "" "" ${ARGN})
cmake_parse_arguments(_ "" "PROCESS" "" ${ARGN})
foreach(scriptfile ${scriptfiles})
get_filename_component(abs_script "${scriptfile}" ABSOLUTE)
message(STATUS "Adding linker script ${abs_script}")
if(__PROCESS)
__ldgen_process_template(output ${abs_script})
get_filename_component(output "${__PROCESS}" ABSOLUTE)
__ldgen_process_template(${abs_script} ${output})
set(abs_script ${output})
endif()

View file

@ -19,6 +19,8 @@ import argparse
import sys
import tempfile
import subprocess
import os
import errno
from fragments import FragmentFile
from sdkconfig import SDKConfig
@ -111,6 +113,14 @@ def main():
with tempfile.TemporaryFile("w+") as output:
script_model.write(output)
output.seek(0)
if not os.path.exists(os.path.dirname(output_path)):
try:
os.makedirs(os.path.dirname(output_path))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
with open(output_path, "w") as f: # only create output file after generation has suceeded
f.write(output.read())
except LdGenFailure as e: