[build] Remove PyYAML dependency
This converts all the YAML files to JSON files, as json parsing is built into python instead of being a separate library requiring installation. YAML is a superset of JSON, but putting comments in is not quite as obvious as it is in yaml. The following glue was used to convert yaml to json: python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < $1 > $2 Clearly I haven't tested this on every single platform, and this doesn't address the large blobs of yaml in the lpc4300 scripts directory, only the cortex NVIC generation process. I've tested a few IRQ driven example apps, and I've checked the generated output of some known cases like the LM3s that has explicit gaps, and they are all generated correctly.
This commit is contained in:
committed by
Piotr Esden-Tempski
parent
b4eb8a6971
commit
5c14780403
@@ -17,7 +17,7 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Generate an nvic.h header from a small YAML file describing the interrupt
|
||||
"""Generate an nvic.h header from a small JSON file describing the interrupt
|
||||
numbers.
|
||||
|
||||
Code generation is chosen here because the resulting C code needs to be very
|
||||
@@ -29,7 +29,7 @@ method to achive the same thing with C preprocessor is known to the author.
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import yaml
|
||||
import json
|
||||
|
||||
template_nvic_h = '''\
|
||||
/* This file is part of the libopencm3 project.
|
||||
@@ -110,7 +110,7 @@ template_cmsis_h = '''\
|
||||
'''
|
||||
|
||||
def convert(infile, outfile_nvic, outfile_vectornvic, outfile_cmsis):
|
||||
data = yaml.load(infile)
|
||||
data = json.load(infile)
|
||||
|
||||
irq2name = list(enumerate(data['irqs']) if isinstance(data['irqs'], list) else data['irqs'].items())
|
||||
irqnames = [v for (k,v) in irq2name]
|
||||
@@ -118,9 +118,9 @@ def convert(infile, outfile_nvic, outfile_vectornvic, outfile_cmsis):
|
||||
if isinstance(data['irqs'], list):
|
||||
data['irqcount'] = len(irq2name)
|
||||
else:
|
||||
data['irqcount'] = max(data['irqs'].keys()) + 1
|
||||
data['irqcount'] = max([int(x) for x in data['irqs'].keys()]) + 1
|
||||
|
||||
data['irqdefinitions'] = "\n".join('#define NVIC_%s_IRQ %d'%(v.upper(),k) for (k,v) in irq2name)
|
||||
data['irqdefinitions'] = "\n".join('#define NVIC_%s_IRQ %d'%(v.upper(),int(k)) for (k,v) in irq2name)
|
||||
data['isrprototypes'] = "\n".join('void WEAK %s_isr(void);'%name.lower() for name in irqnames)
|
||||
data['isrpragmas'] = "\n".join('#pragma weak %s_isr = blocking_handler'%name.lower() for name in irqnames)
|
||||
data['vectortableinitialization'] = ', \\\n '.join('[NVIC_%s_IRQ] = %s_isr'%(name.upper(), name.lower()) for name in irqnames)
|
||||
@@ -148,11 +148,11 @@ def main():
|
||||
else:
|
||||
remove = False
|
||||
infile = sys.argv[1]
|
||||
if not infile.startswith('./include/libopencm3/') or not infile.endswith('/irq.yaml'):
|
||||
raise ValueError("Arguent must match ./include/libopencm3/**/irq.yaml")
|
||||
nvic_h = infile.replace('irq.yaml', 'nvic.h')
|
||||
vector_nvic_c = infile.replace('./include/libopencm3/', './lib/').replace('irq.yaml', 'vector_nvic.c')
|
||||
cmsis = infile.replace('irq.yaml', 'irqhandlers.h').replace('/libopencm3/', '/libopencmsis/')
|
||||
if not infile.startswith('./include/libopencm3/') or not infile.endswith('/irq.json'):
|
||||
raise ValueError("Arguent must match ./include/libopencm3/**/irq.json")
|
||||
nvic_h = infile.replace('irq.json', 'nvic.h')
|
||||
vector_nvic_c = infile.replace('./include/libopencm3/', './lib/').replace('irq.json', 'vector_nvic.c')
|
||||
cmsis = infile.replace('irq.json', 'irqhandlers.h').replace('/libopencm3/', '/libopencmsis/')
|
||||
|
||||
if remove:
|
||||
if os.path.exists(nvic_h):
|
||||
|
||||
Reference in New Issue
Block a user