-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce scripts automating wrapping structs members with MBEDTLS_PR…
…IVATE. Usage: run setup_and_run_MBEDTLS_PRIVATE.sh Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
- Loading branch information
1 parent
599a086
commit 09565da
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import re | ||
import fileinput | ||
import glob | ||
import pprint | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
files_to_visit = {} | ||
|
||
struct_files = glob.glob("apidoc/xml/structmbedtls*.xml") + glob.glob("apidoc/xml/structpsa*.xml") | ||
|
||
for struct_file in struct_files: | ||
struct_file_tree = ET.parse(struct_file) | ||
all_struct_members_definitions = struct_file_tree.getroot().findall(".//memberdef") | ||
|
||
for struct_member_def in all_struct_members_definitions: | ||
# find file path for this variable | ||
location = struct_member_def.find("location") | ||
file_path = location.attrib["file"] | ||
variable_name = struct_member_def.find("name").text | ||
# if path not yet in dictionary, create empty record to initialize | ||
if file_path not in files_to_visit: | ||
files_to_visit[file_path] = [] | ||
# add variable definition | ||
files_to_visit[file_path].append( | ||
{ | ||
"variable": variable_name, | ||
"lines": [int(location.attrib["line"])] | ||
} | ||
) | ||
# check where the variable was referenced | ||
references = struct_member_def.findall("referencedby") | ||
for reference in references: | ||
refid = reference.attrib["refid"] | ||
# assuming that compound name is related to header's xml file | ||
header_file = "apidoc/xml/" + reference.attrib["compoundref"] + ".xml" | ||
header_file_tree = ET.parse(header_file) | ||
# check if this reference is created by static inline function | ||
static_inline_function_definition = header_file_tree.getroot().find(f".//memberdef[@id='{refid}'][@kind='function'][@static='yes'][@inline='yes']") | ||
if static_inline_function_definition: | ||
static_inline_function_file_path = static_inline_function_definition.find("location").attrib["file"] | ||
lines_from = int(reference.attrib["startline"]) | ||
lines_to = int(reference.attrib["endline"]) | ||
# if path not yet in dictionary, create empty record to initialize. | ||
# This could happen if reference is inside header file which was not yet processed in search for variable definitions | ||
if static_inline_function_file_path not in files_to_visit: | ||
files_to_visit[static_inline_function_file_path] = [] | ||
files_to_visit[static_inline_function_file_path].append( | ||
{ | ||
"variable": variable_name, | ||
"lines": list(range(lines_from, lines_to+1)) # range counts from first element (inclusive) to last (non-inclusive), hence +1 | ||
} | ||
) | ||
|
||
# pp = pprint.PrettyPrinter(indent=4) | ||
# pp.pprint(files_to_visit) | ||
|
||
for file_path, variables in files_to_visit.items(): | ||
with fileinput.FileInput(file_path, inplace=True) as file: | ||
output_line_number = 1 | ||
for line in file: | ||
for variable in variables: | ||
for var_line in variable["lines"]: | ||
if output_line_number == var_line: | ||
old_var = variable["variable"] | ||
line = re.sub(r"(^.*)(\W+)({var})(\W+)(.*$)".format(var=old_var), r"\1\2MBEDTLS_PRIVATE(\3)\4\5", line) | ||
output_line_number += 1 | ||
print(line, end='') # fileinput redirects stdout to the target file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
make clean | ||
sed -i 's/GENERATE_XML = NO/GENERATE_XML = YES/g' doxygen/mbedtls.doxyfile | ||
scripts/config.py realfull | ||
cd doxygen | ||
doxygen mbedtls.doxyfile | ||
cd .. | ||
python3 apply_MBEDTLS_PRIVATE.py | ||
git checkout include/mbedtls/config.h doxygen/mbedtls.doxyfile |