Scope parameter included in build by cmake/configs

Conflicts:
	Tools/px_generate_params.py
	src/lib/ecl
This commit is contained in:
David Sidrane
2015-11-05 11:48:35 -10:00
committed by Lorenz Meier
parent 93d261a558
commit 64d43ad381
5 changed files with 106 additions and 14 deletions
+2 -1
View File
@@ -144,7 +144,7 @@ class SourceParser(object):
def __init__(self): def __init__(self):
self.param_groups = {} self.param_groups = {}
def Parse(self, contents): def Parse(self, scope, contents):
""" """
Incrementally parse program contents and append all found parameters Incrementally parse program contents and append all found parameters
to the list. to the list.
@@ -241,6 +241,7 @@ class SourceParser(object):
if defval != "" and self.re_is_a_number.match(defval): if defval != "" and self.re_is_a_number.match(defval):
defval = self.re_cut_type_specifier.sub('', defval) defval = self.re_cut_type_specifier.sub('', defval)
param = Parameter(name, tp, defval) param = Parameter(name, tp, defval)
param.SetField("scope", scope)
param.SetField("short_desc", name) param.SetField("short_desc", name)
# If comment was found before the parameter declaration, # If comment was found before the parameter declaration,
# inject its data into the newly created parameter. # inject its data into the newly created parameter.
+3 -1
View File
@@ -33,6 +33,8 @@ class SourceScanner(object):
Scans provided file and passes its contents to the parser using Scans provided file and passes its contents to the parser using
parser.Parse method. parser.Parse method.
""" """
prefix = ".." + os.path.sep + "src" + os.path.sep
scope = re.sub(prefix, '', os.path.dirname(os.path.relpath(path)))
with codecs.open(path, 'r', 'utf-8') as f: with codecs.open(path, 'r', 'utf-8') as f:
try: try:
contents = f.read() contents = f.read()
@@ -40,4 +42,4 @@ class SourceScanner(object):
contents = '' contents = ''
print('Failed reading file: %s, skipping content.' % path) print('Failed reading file: %s, skipping content.' % path)
pass pass
return parser.Parse(contents) return parser.Parse(scope, contents)
+93 -6
View File
@@ -1,12 +1,89 @@
#!/usr/bin/env python #!/usr/bin/env python
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import os import os
import re
import codecs
if len(os.sys.argv) != 2: class Scope(object):
"""
Single parameter group
"""
def __init__(self, ):
self.scope = set()
def __str__(self):
return self.scope.__str__()
def Add(self, scope):
"""
Add Scope to set
"""
self.scope.add(scope)
def Has(self, scope):
"""
Check for existance
"""
if len(self.scope) == 0:
return True
return scope in self.scope
class CMakeParser(object):
"""
Parses provided data and stores all found paths in scope.
"""
re_split_lines = re.compile(r'[\r\n]+')
re_comment = re.compile(r'^\#')
re_start = re.compile(r'set\s*\(\s*config_module_list')
re_end = re.compile(r'\)\s*')
def Parse(self, scope, contents):
"""
Incrementally parse cmake file contents and append all found path scope
to scope.
"""
# This code is essentially a comment-parsing grammar. "state"
# represents parser state. It contains human-readable state
# names.
state = None
for line in self.re_split_lines.split(contents):
line = line.strip()
# Ignore empty lines
if line == "":
continue
if self.re_comment.match(line):
continue
elif self.re_start.match(line):
state = "gather"
continue
elif state is not None and state == "gather":
if self.re_end.match(line):
return True
scope.Add(line)
return False
if len(os.sys.argv) < 2:
print("Error in %s" % os.sys.argv[0]) print("Error in %s" % os.sys.argv[0])
print("Usage: %s <parameters.xml>" % os.sys.argv[0]) print("Usage: %s <parameters.xml> [cmake-file-scoping] " % os.sys.argv[0])
raise SystemExit raise SystemExit
scope = Scope()
if len(os.sys.argv) == 3:
with codecs.open(os.sys.argv[2], 'r', 'utf-8') as f:
try:
contents = f.read()
f.close()
parser = CMakeParser()
parser.Parse(scope, contents)
except:
contents = ''
print('Failed reading file: %s, skipping scoping.' % os.sys.argv[2])
pass
fp_header = open("px4_parameters.h", "w") fp_header = open("px4_parameters.h", "w")
fp_src = open("px4_parameters.c", "w") fp_src = open("px4_parameters.c", "w")
@@ -30,14 +107,19 @@ end_name = ""
for group in root: for group in root:
if group.tag == "group" and "no_code_generation" not in group.attrib: if group.tag == "group" and "no_code_generation" not in group.attrib:
header += """ section = """
/***************************************************************** /*****************************************************************
* %s * %s
****************************************************************/""" % group.attrib["name"] ****************************************************************/""" % group.attrib["name"]
for param in group: for param in group:
scope_ = param.find('scope').text
if not scope.Has(scope_):
continue
if not start_name: if not start_name:
start_name = param.attrib["name"] start_name = param.attrib["name"]
end_name = param.attrib["name"] end_name = param.attrib["name"]
header += section
section =""
header += """ header += """
const struct param_info_s __param__%s;""" % param.attrib["name"] const struct param_info_s __param__%s;""" % param.attrib["name"]
header += """ header += """
@@ -63,12 +145,14 @@ struct px4_parameters_t px4_parameters = {
i=0 i=0
for group in root: for group in root:
if group.tag == "group" and "no_code_generation" not in group.attrib: if group.tag == "group" and "no_code_generation" not in group.attrib:
section = """
src += """
/***************************************************************** /*****************************************************************
* %s * %s
****************************************************************/""" % group.attrib["name"] ****************************************************************/""" % group.attrib["name"]
for param in group: for param in group:
scope_ = param.find('scope').text
if not scope.Has(scope_):
continue
if not start_name: if not start_name:
start_name = param.attrib["name"] start_name = param.attrib["name"]
end_name = param.attrib["name"] end_name = param.attrib["name"]
@@ -78,6 +162,8 @@ for group in root:
elif (param.attrib["type"] == "INT32"): elif (param.attrib["type"] == "INT32"):
val_str = ".val.i = " val_str = ".val.i = "
i+=1 i+=1
src += section
section =""
src += """ src += """
{ {
"%s", "%s",
@@ -97,4 +183,5 @@ __END_DECLS
fp_header.write(header) fp_header.write(header)
fp_src.write(src) fp_src.write(src)
fp_header.close()
fp_src.close()
+7 -6
View File
@@ -820,22 +820,23 @@ endfunction()
# Generates a source file with all parameters. # Generates a source file with all parameters.
# #
# Usage: # Usage:
# px4_generate_parameters_source(OUT <list-source-files> XML <param-xml-file>) # px4_generate_parameters_source(OUT <list-source-files> XML <param-xml-file> [SCOPE <cmake file for scoping>])
# #
# Input: # Input:
# XML : the parameters.xml file # XML : the parameters.xml file
# DEPS : target dependencies # SCOPE : the cmake file used to limit scope of the paramaters
# DEPS : target dependencies
# #
# Output: # Output:
# OUT : the generated source files # OUT : the generated source files
# #
# Example: # Example:
# px4_generate_parameters_source(OUT param_files XML parameters.xml) # px4_generate_parameters_source(OUT param_files XML parameters.xml SCOPE ${OS}_${BOARD}_${LABEL}.cmake )
# #
function(px4_generate_parameters_source) function(px4_generate_parameters_source)
px4_parse_function_args( px4_parse_function_args(
NAME px4_generate_parameters_source NAME px4_generate_parameters_source
ONE_VALUE OUT XML DEPS ONE_VALUE OUT XML SCOPE DEPS
REQUIRED OUT XML REQUIRED OUT XML
ARGN ${ARGN}) ARGN ${ARGN})
set(generated_files set(generated_files
@@ -844,7 +845,7 @@ function(px4_generate_parameters_source)
set_source_files_properties(${generated_files} set_source_files_properties(${generated_files}
PROPERTIES GENERATED TRUE) PROPERTIES GENERATED TRUE)
add_custom_command(OUTPUT ${generated_files} add_custom_command(OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_generate_params.py ${XML} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_generate_params.py ${XML} ${SCOPE}
DEPENDS ${XML} ${DEPS} DEPENDS ${XML} ${DEPS}
) )
set(${OUT} ${generated_files} PARENT_SCOPE) set(${OUT} ${generated_files} PARENT_SCOPE)
+1
View File
@@ -35,6 +35,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
px4_generate_parameters_source(OUT param_files px4_generate_parameters_source(OUT param_files
XML ${CMAKE_BINARY_DIR}/parameters.xml XML ${CMAKE_BINARY_DIR}/parameters.xml
SCOPE ${CMAKE_SOURCE_DIR}/cmake/configs/${OS}_${BOARD}_${LABEL}.cmake
DEPS xml_gen DEPS xml_gen
) )