Skip to content
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

Domain specific clang args #258

Merged
merged 5 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Unreleased `master`_

:Date: YYYY-MM-DD

Added
~~~~~

* Domain specific config options ``hawkmoth_clang_c`` and
``hawkmoth_clang_cpp``.

Changed
~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CLEAN := $(CLEAN) $(BUILDDIR)

.PHONY: update-examples
update-examples:
$(test_dir)/update-examples.py > $(doc_dir)/examples.rst
python3 -m $(test_dir).update_examples > $(doc_dir)/examples.rst

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Expand Down
12 changes: 12 additions & 0 deletions doc/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ See also additional configuration options in the :ref:`built-in extensions
You can also pass in the compiler to use, for example
``get_include_args('gcc')``.

.. py:data:: hawkmoth_clang_c
:type: list

Arguments to pass to ``clang`` after :data:`hawkmoth_clang` in the C domain
only.

.. py:data:: hawkmoth_clang_cpp
:type: list

Arguments to pass to ``clang`` after :data:`hawkmoth_clang` in the C++ domain
only.

.. py:data:: hawkmoth_source_uri
:type: str

Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ exclude = [
]

[tool.mypy]
files = [
"src",
mypy_path = "src:."
packages = [
"hawkmoth",
"test",
]
exclude = "(test/conf\\.py|test/update-examples\\.py)"
exclude = "(test/conf\\.py)"

[[tool.mypy.overrides]]
module = "test.*"
follow_imports = "skip"

[[tool.mypy.overrides]]
module = "clang.*"
Expand Down
7 changes: 7 additions & 0 deletions src/hawkmoth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def __get_clang_args(self):

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', []))

return clang_args
Expand Down Expand Up @@ -353,6 +358,8 @@ def setup(app):

app.add_config_value('hawkmoth_root', app.confdir, 'env', [str])
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])

app.add_config_value('hawkmoth_transform_default', None, 'env', [str])

Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test-verbose:
# Ensure a) update-examples works, and b) examples have been updated.
.PHONY: check-examples
check-examples:
$(test_dir)/update-examples.py | diff -u $(doc_dir)/examples.rst -
python3 -m $(test_dir).update_examples | diff -u $(doc_dir)/examples.rst -

.PHONY: quick-test
quick-test:
Expand Down
2 changes: 1 addition & 1 deletion test/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Test Cases as Examples
The examples in the documentation are generated from test cases under the
``examples`` subdirectory, ensuring the examples actually work.

``make update-examples`` runs ``update-examples.py`` to generate
``make update-examples`` runs ``update_examples.py`` to generate
``doc/examples.rst`` from the example test cases.

Running
Expand Down
5 changes: 5 additions & 0 deletions test/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None

# -- Options for Hawkmoth ----------------------------------------------------
# https://jnikula.github.io/hawkmoth/dev/extension.html#configuration

hawkmoth_clang_c = ['-std=c17']
hawkmoth_clang_cpp = ['-std=c++17']

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
Expand Down
3 changes: 0 additions & 3 deletions test/cpp/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ directives:
directive: autodoc
arguments:
- template.cpp
options:
clang:
- --std=c++17
expected: template.rst
9 changes: 8 additions & 1 deletion test/testenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
import strictyaml

from test import conf

testext = '.yaml'
testdir = os.path.dirname(os.path.abspath(__file__))
rootdir = os.path.dirname(testdir)
Expand Down Expand Up @@ -43,7 +45,12 @@ def get_directive_string(self):
return directive_str

def get_clang_args(self):
clang_args = []
clang_args = getattr(conf, 'hawkmoth_clang', [])

if self.domain == 'c':
clang_args.extend(getattr(conf, 'hawkmoth_clang_c', []))
else:
clang_args.extend(getattr(conf, 'hawkmoth_clang_cpp', []))

clang_args.extend(self.options.get('clang', []))

Expand Down
2 changes: 1 addition & 1 deletion test/update-examples.py → test/update_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import sys

import testenv
from test import testenv

class ExampleTestcase(testenv.Testcase):
pass
Expand Down
Loading