From f33b14715bc786f7aba8e9b4969b16c1e0a03ed0 Mon Sep 17 00:00:00 2001 From: ladislas Date: Mon, 18 Aug 2014 23:21:05 +0200 Subject: Add auto-lib.py python script to add included libraries automatically --- bin/auto-lib.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 bin/auto-lib.py (limited to 'bin/auto-lib.py') diff --git a/bin/auto-lib.py b/bin/auto-lib.py new file mode 100755 index 0000000..a0a1d4a --- /dev/null +++ b/bin/auto-lib.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +import os +import re +import sys + +# Set variables +USER_LIB_PATH = sys.argv[1] +USER_LIBS = [] ; + +includeRegex = re.compile("(?<=^\#include\s[\<\"])(.*)(?=\.h[\>\"])", re.DOTALL|re.M) + +MAIN_SRCS = [] ; +MAIN_LIBS = [] ; + +LIBS_DEPS = [] ; +LIBS_DEPS_STACK = [] ; + +# Find local sources .ino, .c or .cpp +for file in os.listdir(os.curdir): + if file.endswith((".c", ".cpp", ".ino")): + MAIN_SRCS.append(file) + +# Find all USER_LIBS +for path, dirs, files in os.walk(USER_LIB_PATH): + for d in dirs: + USER_LIBS.append(d) + +# Find MAIN_LIBS included in MAIN_SRCS +for src in MAIN_SRCS: + currentFile = open(src) + includes = [] + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS: + MAIN_LIBS.append(match.group(1)) + +MAIN_LIBS = list(sorted(MAIN_LIBS)) + +# Find LIBS_DEPS includes in MAIN_LIBS +for lib in MAIN_LIBS: + if lib in USER_LIBS: + currentFile = open(USER_LIB_PATH + "/" + lib + "/" + lib + ".h") + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS and match.group(1) not in MAIN_LIBS: + LIBS_DEPS_STACK.append(match.group(1)) + +LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK)) + +# Recursively find all dependencies of every libraries in USER_LIB_PATH +while LIBS_DEPS_STACK: + for lib in LIBS_DEPS_STACK: + if lib in USER_LIBS: + currentFile = open(USER_LIB_PATH + "/" + lib + "/" + lib + ".h") + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS and match.group(1) not in LIBS_DEPS_STACK or match.group(1) in LIBS_DEPS and match.group(1) not in MAIN_LIBS: + LIBS_DEPS_STACK.append(match.group(1)) + + else: + LIBS_DEPS.append(lib) + if lib in LIBS_DEPS_STACK: + LIBS_DEPS_STACK.remove(lib) + + LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK)) + # print(LIBS_DEPS_STACK) + +LIBS_DEPS = sorted(set(LIBS_DEPS)) + +# print("Main libraries: ") +# print(MAIN_LIBS); +# print("") +# print("Dependencies stack: ") +# print(LIBS_DEPS_STACK) +# print("") +# print("Libraries dependencies: ") +# print(LIBS_DEPS); + +def outputLibs(libArray): + for lib in libArray: + print(lib), + print("") + +print("MAIN_LIBS"), +outputLibs(MAIN_LIBS) + +print("LIBS_DEPS"), +outputLibs(LIBS_DEPS) -- cgit v1.2.3 From f930c1780170f53f81bfe42095c8c161a5802cfc Mon Sep 17 00:00:00 2001 From: ladislas Date: Tue, 19 Aug 2014 00:02:38 +0200 Subject: Add automatic lib detection with python script, enhance lib listing output when compiling --- bin/auto-lib.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'bin/auto-lib.py') diff --git a/bin/auto-lib.py b/bin/auto-lib.py index a0a1d4a..77d69f6 100755 --- a/bin/auto-lib.py +++ b/bin/auto-lib.py @@ -16,6 +16,12 @@ MAIN_LIBS = [] ; LIBS_DEPS = [] ; LIBS_DEPS_STACK = [] ; +# Define functions +def outputLibs(libArray): + for lib in libArray: + print(lib), + print("") + # Find local sources .ino, .c or .cpp for file in os.listdir(os.curdir): if file.endswith((".c", ".cpp", ".ino")): @@ -70,24 +76,10 @@ while LIBS_DEPS_STACK: LIBS_DEPS_STACK.remove(lib) LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK)) - # print(LIBS_DEPS_STACK) LIBS_DEPS = sorted(set(LIBS_DEPS)) -# print("Main libraries: ") -# print(MAIN_LIBS); -# print("") -# print("Dependencies stack: ") -# print(LIBS_DEPS_STACK) -# print("") -# print("Libraries dependencies: ") -# print(LIBS_DEPS); - -def outputLibs(libArray): - for lib in libArray: - print(lib), - print("") - +# Output libraries for the Makefile print("MAIN_LIBS"), outputLibs(MAIN_LIBS) -- cgit v1.2.3