diff options
author | Karl Palsson <karlp@tweak.net.au> | 2013-09-07 03:43:39 +0400 |
---|---|---|
committer | Piotr Esden-Tempski <piotr@esden.net> | 2014-01-02 23:55:15 +0400 |
commit | 5c14780403607d3b7a794915f0445c842f34d428 (patch) | |
tree | 65439526fad47b6547dadb0a35c46b41a54f57f7 /scripts | |
parent | b4eb8a69718c40b7e6fe5672c0ee93682e68a0a0 (diff) |
[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.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/irq2nvic_h | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/scripts/irq2nvic_h b/scripts/irq2nvic_h index 7f57d43e..1fb48bdf 100755 --- a/scripts/irq2nvic_h +++ b/scripts/irq2nvic_h @@ -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): |