From 1bfe2ef9f7f39d93174b1f62ac4b079aac2dea59 Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Wed, 14 Mar 2018 17:56:15 +0100 Subject: Adding script to update various config files automaticaly. --- tools/update_configs.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tools/update_configs.py (limited to 'tools/update_configs.py') diff --git a/tools/update_configs.py b/tools/update_configs.py new file mode 100644 index 0000000..637429e --- /dev/null +++ b/tools/update_configs.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +__author__ = 'Fabien Poussin' +__version__ = '0.1' + +import os +import re +from argparse import ArgumentParser +from traceback import print_exc +from shutil import copy + +parser = ArgumentParser(description='Generate ChibiOS-Contrib config and make files from ChibiOS') +parser.add_argument('-s', '--src', default='../../ChibiOS-RT', type=str, help="ChibiOS folder") +parser.add_argument('-d', '--dst', default='..', type=str, help='ChibiOS-Contrib folder') + + +def makefile(lines): + + + for l in range(len(lines)): + + if 'CHIBIOS =' in lines[l]: + lines[l] = lines[l][:-1] + '/../ChibiOS-RT\n' + lines.insert(l + 1, 'CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib\n') + + if '$(CHIBIOS)/os/hal/hal.mk' in lines[l] \ + or '$(CHIBIOS)/os/hal/ports/' in lines[l] \ + or '$(CHIBIOS)/os/various' in lines[l] : + lines[l] = lines[l].replace('CHIBIOS', 'CHIBIOS_CONTRIB') + + return "".join(lines) + + +def halconf(lines): + + idx_end = lines.index('#endif /* HALCONF_H */\n') + lines.insert(idx_end - 1, '\n') + lines.insert(idx_end - 1, '#include "halconf_community.h"') + lines.insert(idx_end - 1, '\n') + + return "".join(lines) + + +def mcuconf(lines): + + idx_end = lines.index('#endif /* MCUCONF_H */\n') + lines.insert(idx_end - 1, '\n') + lines.insert(idx_end - 1, '#include "mcuconf_community.h"') + lines.insert(idx_end - 1, '\n') + + return "".join(lines) + + +if __name__ == '__main__': + + args = parser.parse_args() + sources = {} + + for family in os.scandir(args.src + '/testhal/STM32/'): + if not family.name[0].isupper() or not family.is_dir(): + continue + + for test in os.scandir(family.path): + try: + sources[family.name] = {'makefile': None, 'halconf': None, 'mcuconf': None} + + with open(test.path + '/Makefile', 'r') as file: + sources[family.name]['makefile'] = makefile(file.readlines()) + + with open(test.path + '/halconf.h', 'r') as file: + sources[family.name]['halconf'] = halconf(file.readlines()) + + with open(test.path + '/mcuconf.h', 'r') as file: + sources[family.name]['mcuconf'] = mcuconf(file.readlines()) + + except Exception as e: + print(test.path, e) + del sources[family.name] + continue + + break + + print(sources.keys()) + + for family in os.scandir(args.dst + '/testhal/STM32/'): + if not family.name[0].isupper() or not family.is_dir(): + continue + + for test in os.scandir(family.path): + copy('templates/halconf_community.h', test.path) + copy('templates/mcuconf_community.h', test.path) + + with open(test.path + '/Makefile', 'w') as file: + file.write(sources[family.name]['makefile']) + + with open(test.path + '/halconf.h', 'w') as file: + file.write(sources[family.name]['halconf']) + + with open(test.path + '/mcuconf.h', 'w') as file: + file.write(sources[family.name]['mcuconf']) -- cgit v1.2.3 From 424c7a2717fb6b2a847cec5c0060e3236f25e97f Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Wed, 14 Mar 2018 20:15:13 +0100 Subject: Fixed most testhal examples for STM32, updated configs using script. Fixed deprecated MS2ST calls. --- tools/update_configs.py | 68 ++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'tools/update_configs.py') diff --git a/tools/update_configs.py b/tools/update_configs.py index 637429e..6bc69b9 100644 --- a/tools/update_configs.py +++ b/tools/update_configs.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- __author__ = 'Fabien Poussin' __version__ = '0.1' @@ -16,7 +16,6 @@ parser.add_argument('-d', '--dst', default='..', type=str, help='ChibiOS-Contrib def makefile(lines): - for l in range(len(lines)): if 'CHIBIOS =' in lines[l]: @@ -56,45 +55,50 @@ if __name__ == '__main__': args = parser.parse_args() sources = {} - for family in os.scandir(args.src + '/testhal/STM32/'): - if not family.name[0].isupper() or not family.is_dir(): - continue + for folder in ['testhal']: - for test in os.scandir(family.path): - try: - sources[family.name] = {'makefile': None, 'halconf': None, 'mcuconf': None} + for family in os.scandir(args.src + '/{}/STM32/'.format(folder)): + if not family.name[0].isupper() or not family.is_dir(): + continue - with open(test.path + '/Makefile', 'r') as file: - sources[family.name]['makefile'] = makefile(file.readlines()) + for test in os.scandir(family.path): + try: + sources[family.name] = {'makefile': None, 'halconf': None, 'mcuconf': None} - with open(test.path + '/halconf.h', 'r') as file: - sources[family.name]['halconf'] = halconf(file.readlines()) + with open(test.path + '/Makefile', 'r') as file: + sources[family.name]['makefile'] = makefile(file.readlines()) - with open(test.path + '/mcuconf.h', 'r') as file: - sources[family.name]['mcuconf'] = mcuconf(file.readlines()) + with open(test.path + '/halconf.h', 'r') as file: + sources[family.name]['halconf'] = halconf(file.readlines()) - except Exception as e: - print(test.path, e) - del sources[family.name] - continue + with open(test.path + '/mcuconf.h', 'r') as file: + sources[family.name]['mcuconf'] = mcuconf(file.readlines()) - break + except Exception as e: + print(test.path, e) + del sources[family.name] + continue - print(sources.keys()) + break + + for family in os.scandir(args.dst + '/{}/STM32/'.format(folder)): + if not family.name[0].isupper() or not family.is_dir(): + continue - for family in os.scandir(args.dst + '/testhal/STM32/'): - if not family.name[0].isupper() or not family.is_dir(): - continue + for test in os.scandir(family.path): + copy('templates/halconf_community.h', test.path) + copy('templates/mcuconf_community.h', test.path) - for test in os.scandir(family.path): - copy('templates/halconf_community.h', test.path) - copy('templates/mcuconf_community.h', test.path) + try: + with open(test.path + '/Makefile', 'w') as file: + file.write(sources[family.name]['makefile']) - with open(test.path + '/Makefile', 'w') as file: - file.write(sources[family.name]['makefile']) + with open(test.path + '/halconf.h', 'w') as file: + file.write(sources[family.name]['halconf']) - with open(test.path + '/halconf.h', 'w') as file: - file.write(sources[family.name]['halconf']) + with open(test.path + '/mcuconf.h', 'w') as file: + file.write(sources[family.name]['mcuconf']) - with open(test.path + '/mcuconf.h', 'w') as file: - file.write(sources[family.name]['mcuconf']) + print('updated', test.path) + except KeyError as e: + print('Missing family data', e) -- cgit v1.2.3