ldgen: create python script to find linker script includes

This commit is contained in:
Renz Christian Bagaporo 2019-02-05 11:05:16 +08:00
parent 23a03cf6ad
commit 022a1da4e9
2 changed files with 57 additions and 0 deletions

View file

@ -66,6 +66,7 @@ tools/ci/multirun_with_pyenv.sh
components/espcoredump/test/test_espcoredump.py
components/espcoredump/test/test_espcoredump.sh
tools/ldgen/ldgen.py
tools/ldgen/lddeps.py
tools/ldgen/test/test_fragments.py
tools/ldgen/test/test_generation.py
examples/build_system/cmake/idf_as_lib/build.sh

56
tools/ldgen/lddeps.py Normal file
View file

@ -0,0 +1,56 @@
# !/usr/bin/env python
#
# Copyright 2019 Espressif Systems (Shanghai) PTE LTD
#
# This script is used by the linker script generation in order to list a template's
# INCLUDE'd linker scripts recursively. This is so that updates to these INCLUDE'd
# scripts also trigger a relink of the app.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import re
import argparse
INCLUDE_PATTERN = re.compile(r"INCLUDE[\t ]+([^\n]+)")
def find_includes(file_path, includes_list):
# Find include files recursively
file_dir = os.path.dirname(file_path)
with open(file_path, "r") as f:
includes_list.append(file_path)
includes = re.findall(INCLUDE_PATTERN, f.read())
for include in includes:
include_file_path = os.path.abspath(os.path.join(file_dir, include))
find_includes(include_file_path, includes_list)
def main():
argparser = argparse.ArgumentParser(description="List INCLUDE'd linker scripts recursively")
argparser.add_argument("input", help="input linker script")
args = argparser.parse_args()
includes_list = list()
find_includes(args.input, includes_list)
includes_list.remove(args.input)
print(" ".join(includes_list))
if __name__ == "__main__":
main()