-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Parse glean.h header at build time
- Loading branch information
Showing
5 changed files
with
43 additions
and
23 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
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,35 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
""" | ||
A helper script to build the CFFI wrappers at build time. | ||
Run as part of the setup.py script. | ||
This is the "out-of-line", "ABI mode" option, described in the CFFI docs here: | ||
https://cffi.readthedocs.io/en/latest/cdef.html | ||
""" | ||
|
||
|
||
import cffi | ||
|
||
|
||
def _load_header(path: str) -> str: | ||
""" | ||
Load a C header file and convert it to something parseable by cffi. | ||
""" | ||
with open(path, encoding="utf-8") as fd: | ||
data = fd.read() | ||
return "\n".join( | ||
line for line in data.splitlines() if not line.startswith("#include") | ||
) | ||
|
||
|
||
ffibuilder = cffi.FFI() | ||
ffibuilder.set_source("glean._glean_ffi", None) | ||
ffibuilder.cdef(_load_header("../ffi/glean.h")) | ||
|
||
|
||
if __name__ == "__main__": | ||
ffibuilder.compile() |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
auditwheel==2.1.1 | ||
cffi==1.13.1 | ||
coverage==4.5.2 | ||
flake8==3.7.8 | ||
jsonschema==3.2.0 | ||
|
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