]> granicus.if.org Git - esp-idf/commitdiff
ldgen: create python script to find linker script includes
authorRenz Christian Bagaporo <renz@espressif.com>
Tue, 5 Feb 2019 03:05:16 +0000 (11:05 +0800)
committerRenz Christian Bagaporo <renz@espressif.com>
Thu, 14 Feb 2019 10:58:48 +0000 (18:58 +0800)
tools/ci/executable-list.txt
tools/ldgen/lddeps.py [new file with mode: 0644]

index 06821ebbd9179405823fc306c6604fb320e3da2c..ba84bd2134264d373c6657cc4c7b8de7eb061c0e 100644 (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
diff --git a/tools/ldgen/lddeps.py b/tools/ldgen/lddeps.py
new file mode 100644 (file)
index 0000000..f396395
--- /dev/null
@@ -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()