-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix include paths #263
base: master
Are you sure you want to change the base?
Fix include paths #263
Changes from 1 commit
961c15a
d979c64
66748da
d27cc96
b6c57de
ad093b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from sphinx.util.docutils import switch_source_input, SphinxDirective | ||
from sphinx.util import logging | ||
|
||
from hawkmoth.util import compiler | ||
from hawkmoth.parser import parse, ErrorLevel | ||
from hawkmoth.util import strutil | ||
from hawkmoth import docstring | ||
|
@@ -39,6 +40,31 @@ class _AutoBaseDirective(SphinxDirective): | |
_domain: Optional[str] = None | ||
_docstring_types: Optional[list[type[docstring.Docstring]]] = None | ||
|
||
def __init__(self, name, arguments, options, | ||
content, lineno, content_offset, | ||
block_text, state, state_machine): | ||
|
||
super().__init__(name, arguments, options, | ||
content, lineno, content_offset, | ||
block_text, state, state_machine) | ||
|
||
cpath = self.env.config.hawkmoth_compiler | ||
autoconf = self.env.config.hawkmoth_autoconf | ||
|
||
ignored_options = [x for x in autoconf if x not in ['stdinc']] | ||
if len(ignored_options) > 0: | ||
self.logger.warning(f'autoconf: {ignored_options} unsupported option(s) ignored') | ||
|
||
self._clang_args_post = [] | ||
if 'stdinc' in autoconf: | ||
if cpath: | ||
if self._domain == 'c': | ||
self._clang_args_post = compiler.get_include_args(cpath, 'c') | ||
else: | ||
self._clang_args_post = compiler.get_include_args(cpath, 'c++') | ||
else: | ||
self.logger.warning('autoconf: \'stdinc\' option ignored (missing compiler)') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still gets called once per each directive used in the documentation. There's one instance for directive. The hard part is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alternative is to simplify and go back to the first version (instead of the constructor) and optimize later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, of course. Well, I did this on a crowded flight, it was bound to happen 😅 I'll look into it when I can. There are other (maybe less clean) alternatives like caching the result if we go for a temporary solution, but the events should work well enough if there's a suitable one. |
||
def __display_parser_diagnostics(self, errors): | ||
# Map parser diagnostic level to Sphinx level name | ||
log_level_map = { | ||
|
@@ -56,15 +82,14 @@ def __display_parser_diagnostics(self, errors): | |
def __get_clang_args(self): | ||
clang_args = [] | ||
|
||
clang_args.extend(self.env.config.hawkmoth_clang.copy()) | ||
|
||
if self._domain == 'c': | ||
clang_args.extend(self.env.config.hawkmoth_clang_c.copy()) | ||
else: | ||
clang_args.extend(self.env.config.hawkmoth_clang_cpp.copy()) | ||
|
||
clang_args.extend(self.options.get('clang', [])) | ||
|
||
clang_args.extend(self._clang_args_post) | ||
return clang_args | ||
|
||
def __parse(self, filename): | ||
|
@@ -358,6 +383,8 @@ def setup(app): | |
app.require_sphinx('3.0') | ||
|
||
app.add_config_value('hawkmoth_root', app.confdir, 'env', [str]) | ||
app.add_config_value('hawkmoth_compiler', 'clang', 'env', [str, type(None)]) | ||
app.add_config_value('hawkmoth_autoconf', ['stdinc'], 'env', [list]) | ||
app.add_config_value('hawkmoth_clang', [], 'env', [list]) | ||
app.add_config_value('hawkmoth_clang_c', [], 'env', [list]) | ||
app.add_config_value('hawkmoth_clang_cpp', [], 'env', [list]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the documentation for
hawkmoth_compiler
should merely briefly reference what it's used for, and other places (i.e.hawkmoth_autoconf
) should describe the details.