Merge pull request #378 from numero-744/gen-features-using-rust-not-python

Use our beloved Rust instead of Python
This commit is contained in:
Dario Nieuwenhuis
2021-09-13 16:47:01 +02:00
committed by GitHub
9 changed files with 978 additions and 825 deletions

View File

@ -20,7 +20,7 @@ rt = ["cortex-m-rt/device"]
memory-x = []
# BEGIN GENERATED FEATURES
# Generated by gen_features.py. DO NOT EDIT.
# Generated by stm32-gen-features. DO NOT EDIT.
stm32f030c6 = []
stm32f030c8 = []
stm32f030cc = []

View File

@ -1,47 +0,0 @@
import xmltodict
import yaml
import re
import json
import os
import re
import toml
from collections import OrderedDict
from glob import glob
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# ======= load chip list
features = {}
for f in sorted(glob('../stm32-data/data/chips/*.yaml')):
# Use the filename to get the chip name. Ultra fast, we don't have to read YAML!
name = os.path.splitext(os.path.basename(f))[0].lower()
with open(f, 'r') as f:
chip = yaml.load(f, Loader=SafeLoader)
if len(chip['cores']) > 1:
for core in chip['cores']:
features[name + "_" + core['name']] = []
else:
features[name] = []
# ========= Update Cargo features
SEPARATOR_START = '# BEGIN GENERATED FEATURES\n'
SEPARATOR_END = '# END GENERATED FEATURES\n'
HELP = '# Generated by gen_features.py. DO NOT EDIT.\n'
with open('Cargo.toml', 'r') as f:
cargo = f.read()
before, cargo = cargo.split(SEPARATOR_START, maxsplit=1)
_, after = cargo.split(SEPARATOR_END, maxsplit=1)
cargo = before + SEPARATOR_START + HELP + \
toml.dumps(features) + SEPARATOR_END + after
with open('Cargo.toml', 'w') as f:
f.write(cargo)