mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-05 15:00:33 +00:00
volk_gnsssdr: Fix syntax for Python 3.12
Without breaking older versions, including 2.7
This commit is contained in:
parent
7d9d090a21
commit
ab4cc295e8
@ -34,6 +34,8 @@ All notable changes to GNSS-SDR will be documented in this file.
|
||||
### Improvements in Portability:
|
||||
|
||||
- Updated local `cpu_features` library to v0.9.0.
|
||||
- `volk_gnsssdr`: fix syntax for Python 3.12 without breaking backward
|
||||
compatibility with Python 2.7.
|
||||
|
||||
### Improvements in Repeatability:
|
||||
|
||||
|
@ -221,7 +221,7 @@ function(VOLK_UNIQUE_TARGET desc)
|
||||
file(RELATIVE_PATH reldir ${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib
|
||||
unique = hashlib.sha256(b'${reldir}${ARGN}').hexdigest()[:5]
|
||||
print(re.sub('\\W', '_', '${desc} ${reldir} ' + unique))"
|
||||
print(re.sub(r'\\W', '_', '${desc} ${reldir} ' + unique))"
|
||||
OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
add_custom_target(${_target} ALL DEPENDS ${ARGN})
|
||||
endfunction()
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import optparse
|
||||
import argparse
|
||||
import volk_gnsssdr_arch_defs
|
||||
import volk_gnsssdr_machine_defs
|
||||
|
||||
@ -20,6 +20,7 @@ def do_arch_flags_list(compiler):
|
||||
output.append(','.join(fields))
|
||||
print(';'.join(output))
|
||||
|
||||
|
||||
def do_machines_list(arch_names):
|
||||
output = list()
|
||||
for machine in volk_gnsssdr_machine_defs.machines:
|
||||
@ -28,6 +29,7 @@ def do_machines_list(arch_names):
|
||||
output.append(machine.name)
|
||||
print(';'.join(output))
|
||||
|
||||
|
||||
def do_machine_flags_list(compiler, machine_name):
|
||||
output = list()
|
||||
machine = volk_gnsssdr_machine_defs.machine_dict[machine_name]
|
||||
@ -35,16 +37,18 @@ def do_machine_flags_list(compiler, machine_name):
|
||||
output.extend(arch.get_flags(compiler))
|
||||
print(' '.join(output))
|
||||
|
||||
|
||||
def main():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--mode', type='string')
|
||||
parser.add_option('--compiler', type='string')
|
||||
parser.add_option('--archs', type='string')
|
||||
parser.add_option('--machine', type='string')
|
||||
(opts, args) = parser.parse_args()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--mode', type=str)
|
||||
parser.add_argument('--compiler', type=str)
|
||||
parser.add_argument('--archs', type=str)
|
||||
parser.add_argument('--machine', type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
if opts.mode == 'arch_flags': return do_arch_flags_list(opts.compiler.lower())
|
||||
if opts.mode == 'machines': return do_machines_list(opts.archs.split(';'))
|
||||
if opts.mode == 'machine_flags': return do_machine_flags_list(opts.compiler.lower(), opts.machine)
|
||||
if args.mode == 'arch_flags': return do_arch_flags_list(args.compiler.lower())
|
||||
if args.mode == 'machines': return do_machines_list(args.archs.split(';'))
|
||||
if args.mode == 'machine_flags': return do_machine_flags_list(args.compiler.lower(), args.machine)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -16,7 +16,7 @@ import glob
|
||||
########################################################################
|
||||
# Strip comments from a c/cpp file.
|
||||
# Input is code string, output is code string without comments.
|
||||
# https://stackoverflow.com/questions/241327/remove-c-and-c-comments-using-python
|
||||
# https://stackoverflow.com/questions/241327/python-snippet-to-remove-c-and-c-comments
|
||||
########################################################################
|
||||
def comment_remover(text):
|
||||
def replacer(match):
|
||||
@ -120,7 +120,7 @@ class impl_class(object):
|
||||
self.args = list()
|
||||
fcn_args = the_rest.split(',')
|
||||
for fcn_arg in fcn_args:
|
||||
arg_matcher = re.compile(r'^\s*(.*\W)\s*(\w+)\s*$', re.DOTALL | re.MULTILINE)
|
||||
arg_matcher = re.compile(r'^\s*(.*[^\w])\s*(\w+)\s*$', re.DOTALL | re.MULTILINE)
|
||||
m = arg_matcher.match(fcn_arg)
|
||||
arg_type, arg_name = m.groups()
|
||||
self.args.append((arg_type, arg_name))
|
||||
@ -164,6 +164,8 @@ class kernel_class(object):
|
||||
kern_name=self.name, header=sub_hdr, body=body,
|
||||
))
|
||||
assert(self._impls)
|
||||
if "generic" not in [impl.name for impl in self._impls]:
|
||||
raise Exception("{} does not have a generic protokernel.".format(self.name))
|
||||
self.has_dispatcher = False
|
||||
for impl in self._impls:
|
||||
if impl.name == 'dispatcher':
|
||||
|
@ -11,7 +11,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import optparse
|
||||
import argparse
|
||||
import volk_gnsssdr_arch_defs
|
||||
import volk_gnsssdr_machine_defs
|
||||
import volk_gnsssdr_kernel_defs
|
||||
@ -34,13 +34,14 @@ def __parse_tmpl(_tmpl, **kwargs):
|
||||
return str(Template(_tmpl).render(**defs))
|
||||
|
||||
def main():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--input', type='string')
|
||||
parser.add_option('--output', type='string')
|
||||
(opts, args) = parser.parse_args()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--input', type=str)
|
||||
parser.add_argument('--output', type=str)
|
||||
args, extras = parser.parse_known_args()
|
||||
|
||||
output = __parse_tmpl(open(opts.input).read(), args=args)
|
||||
if opts.output: open(opts.output, 'w').write(output)
|
||||
output = __parse_tmpl(open(args.input).read(), args=extras)
|
||||
if args.output: open(args.output, 'w').write(output)
|
||||
else: print(output)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -113,7 +113,7 @@ macro(check_arch arch_name)
|
||||
set(have_flag have${flag})
|
||||
# make the have_flag have nice alphanum chars (just for looks/not necessary)
|
||||
execute_process(
|
||||
COMMAND ${PYTHON_EXECUTABLE} -c "import re; print(re.sub('\\W', '_', '${have_flag}'))"
|
||||
COMMAND ${PYTHON_EXECUTABLE} -c "import re; print(re.sub(r'\\W', '_', '${have_flag}'))"
|
||||
OUTPUT_VARIABLE have_flag OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
if(VOLK_FLAG_CHECK_FLAGS)
|
||||
|
@ -290,9 +290,7 @@ class volk_gnsssdr_modtool(object):
|
||||
inserted = False;
|
||||
insert = False
|
||||
for otherline in otherlines:
|
||||
|
||||
if (re.match('\s*', otherline) == None or re.match('\s*#.*', otherline) == None):
|
||||
|
||||
if re.match(r'\s*', otherline) is None or re.match(r'\s*#.*', otherline) is None:
|
||||
insert = True;
|
||||
if insert and not inserted:
|
||||
inserted = True;
|
||||
|
Loading…
Reference in New Issue
Block a user