From 022a1da4e9e05a752159bcb211763236510c9f17 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 5 Feb 2019 11:05:16 +0800 Subject: [PATCH] ldgen: create python script to find linker script includes --- tools/ci/executable-list.txt | 1 + tools/ldgen/lddeps.py | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tools/ldgen/lddeps.py diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index 06821ebbd9..ba84bd2134 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -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 diff --git a/tools/ldgen/lddeps.py b/tools/ldgen/lddeps.py new file mode 100644 index 0000000000..f3963955a9 --- /dev/null +++ b/tools/ldgen/lddeps.py @@ -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()