feat(gen_json): adds option to gen_json to build without docstrings (#7471)
This commit is contained in:
@@ -5,7 +5,6 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
|
||||||
|
|
||||||
base_path = os.path.abspath(os.path.dirname(__file__))
|
base_path = os.path.abspath(os.path.dirname(__file__))
|
||||||
sys.path.insert(0, base_path)
|
sys.path.insert(0, base_path)
|
||||||
@@ -21,51 +20,13 @@ import pycparser # NOQA
|
|||||||
DEVELOP = False
|
DEVELOP = False
|
||||||
|
|
||||||
|
|
||||||
class STDOut:
|
|
||||||
def __init__(self):
|
|
||||||
self._stdout = sys.stdout
|
|
||||||
sys.__stdout__ = self
|
|
||||||
sys.stdout = self
|
|
||||||
|
|
||||||
def write(self, data):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getattr__(self, item):
|
|
||||||
if item in self.__dict__:
|
|
||||||
return self.__dict__[item]
|
|
||||||
|
|
||||||
return getattr(self._stdout, item)
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
sys.stdout = self._stdout
|
|
||||||
|
|
||||||
|
|
||||||
temp_directory = tempfile.mkdtemp(suffix='.lvgl_json')
|
temp_directory = tempfile.mkdtemp(suffix='.lvgl_json')
|
||||||
|
|
||||||
|
|
||||||
def run(output_path, lvgl_config_path, output_to_stdout, target_header, filter_private, *compiler_args):
|
def run(output_path, lvgl_config_path, output_to_stdout, target_header, filter_private, no_docstrings, *compiler_args):
|
||||||
# stdout = STDOut()
|
|
||||||
|
|
||||||
pycparser_monkeypatch.FILTER_PRIVATE = filter_private
|
pycparser_monkeypatch.FILTER_PRIVATE = filter_private
|
||||||
|
|
||||||
# The thread is to provide an indication that things are being processed.
|
|
||||||
# There are long periods where nothing gets output to the screen and this
|
|
||||||
# is to let the user know that it is still working.
|
|
||||||
if not output_to_stdout:
|
|
||||||
event = threading.Event()
|
|
||||||
|
|
||||||
def _do():
|
|
||||||
while not event.is_set():
|
|
||||||
event.wait(1)
|
|
||||||
sys.stdout.write('.')
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
print()
|
|
||||||
|
|
||||||
t = threading.Thread(target=_do)
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
lvgl_path = project_path
|
lvgl_path = project_path
|
||||||
lvgl_src_path = os.path.join(lvgl_path, 'src')
|
lvgl_src_path = os.path.join(lvgl_path, 'src')
|
||||||
temp_lvgl = os.path.join(temp_directory, 'lvgl')
|
temp_lvgl = os.path.join(temp_directory, 'lvgl')
|
||||||
@@ -218,11 +179,9 @@ def run(output_path, lvgl_config_path, output_to_stdout, target_header, filter_p
|
|||||||
cparser = pycparser.CParser()
|
cparser = pycparser.CParser()
|
||||||
ast = cparser.parse(pp_data, target_header)
|
ast = cparser.parse(pp_data, target_header)
|
||||||
|
|
||||||
ast.setup_docs(temp_directory)
|
ast.setup_docs(no_docstrings, temp_directory)
|
||||||
|
|
||||||
if not output_to_stdout and output_path is None:
|
if not output_to_stdout and output_path is None:
|
||||||
# stdout.reset()
|
|
||||||
|
|
||||||
if not DEVELOP:
|
if not DEVELOP:
|
||||||
shutil.rmtree(temp_directory)
|
shutil.rmtree(temp_directory)
|
||||||
|
|
||||||
@@ -240,17 +199,7 @@ def run(output_path, lvgl_config_path, output_to_stdout, target_header, filter_p
|
|||||||
with open(output_path, 'w') as f:
|
with open(output_path, 'w') as f:
|
||||||
f.write(json.dumps(ast.to_dict(), indent=4))
|
f.write(json.dumps(ast.to_dict(), indent=4))
|
||||||
|
|
||||||
# stdout.reset()
|
|
||||||
|
|
||||||
if not output_to_stdout:
|
|
||||||
event.set() # NOQA
|
|
||||||
t.join() # NOQA
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if not output_to_stdout:
|
|
||||||
event.set() # NOQA
|
|
||||||
t.join() # NOQA
|
|
||||||
|
|
||||||
print()
|
|
||||||
try:
|
try:
|
||||||
print(cpp_cmd) # NOQA
|
print(cpp_cmd) # NOQA
|
||||||
print()
|
print()
|
||||||
@@ -370,9 +319,15 @@ if __name__ == '__main__':
|
|||||||
help='Internal Use',
|
help='Internal Use',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--no-docstrings',
|
||||||
|
dest='no_docstrings',
|
||||||
|
help='Internal Use',
|
||||||
|
action='store_true',
|
||||||
|
)
|
||||||
|
|
||||||
args, extra_args = parser.parse_known_args()
|
args, extra_args = parser.parse_known_args()
|
||||||
|
|
||||||
DEVELOP = args.develop
|
DEVELOP = args.develop
|
||||||
|
|
||||||
run(args.output_path, args.lv_conf, args.output_path is None, args.target_header, args.filter_private, *extra_args)
|
run(args.output_path, args.lv_conf, args.output_path is None, args.target_header, args.filter_private, args.no_docstrings, *extra_args)
|
||||||
|
|||||||
@@ -16,13 +16,9 @@ except ImportError:
|
|||||||
from pycparser.c_generator import CGenerator
|
from pycparser.c_generator import CGenerator
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import doc_builder # NOQA
|
|
||||||
|
|
||||||
generator = CGenerator()
|
generator = CGenerator()
|
||||||
|
|
||||||
doc_builder.EMIT_WARNINGS = False
|
|
||||||
# doc_builder.DOXYGEN_OUTPUT = False
|
|
||||||
|
|
||||||
|
|
||||||
BASIC_TYPES = [
|
BASIC_TYPES = [
|
||||||
'float',
|
'float',
|
||||||
@@ -575,7 +571,7 @@ class FileAST(c_ast.FileAST):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._parent = None
|
self._parent = None
|
||||||
|
|
||||||
def setup_docs(self, temp_directory): # NOQA
|
def setup_docs(self, no_docstrings, temp_directory): # NOQA
|
||||||
global get_enum_item_docs
|
global get_enum_item_docs
|
||||||
global get_enum_docs
|
global get_enum_docs
|
||||||
global get_func_docs
|
global get_func_docs
|
||||||
@@ -586,17 +582,41 @@ class FileAST(c_ast.FileAST):
|
|||||||
global get_macro_docs
|
global get_macro_docs
|
||||||
global get_macros
|
global get_macros
|
||||||
|
|
||||||
docs = doc_builder.XMLSearch(temp_directory)
|
if no_docstrings:
|
||||||
|
|
||||||
get_enum_item_docs = docs.get_enum_item
|
def dummy_list():
|
||||||
get_enum_docs = docs.get_enum
|
return []
|
||||||
get_func_docs = docs.get_function
|
|
||||||
get_var_docs = docs.get_variable
|
def dummy_doc(_):
|
||||||
get_union_docs = docs.get_union
|
return None
|
||||||
get_struct_docs = docs.get_structure
|
|
||||||
get_typedef_docs = docs.get_typedef
|
get_enum_item_docs = dummy_doc
|
||||||
get_macro_docs = docs.get_macro
|
get_enum_docs = dummy_doc
|
||||||
get_macros = docs.get_macros
|
get_func_docs = dummy_doc
|
||||||
|
get_var_docs = dummy_doc
|
||||||
|
get_union_docs = dummy_doc
|
||||||
|
get_struct_docs = dummy_doc
|
||||||
|
get_typedef_docs = dummy_doc
|
||||||
|
get_macro_docs = dummy_doc
|
||||||
|
get_macros = dummy_list
|
||||||
|
|
||||||
|
else:
|
||||||
|
import doc_builder # NOQA
|
||||||
|
|
||||||
|
doc_builder.EMIT_WARNINGS = False
|
||||||
|
# doc_builder.DOXYGEN_OUTPUT = False
|
||||||
|
|
||||||
|
docs = doc_builder.XMLSearch(temp_directory)
|
||||||
|
|
||||||
|
get_enum_item_docs = docs.get_enum_item
|
||||||
|
get_enum_docs = docs.get_enum
|
||||||
|
get_func_docs = docs.get_function
|
||||||
|
get_var_docs = docs.get_variable
|
||||||
|
get_union_docs = docs.get_union
|
||||||
|
get_struct_docs = docs.get_structure
|
||||||
|
get_typedef_docs = docs.get_typedef
|
||||||
|
get_macro_docs = docs.get_macro
|
||||||
|
get_macros = docs.get_macros
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user