-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meson: Skeleton for python3-netplan build
- Loading branch information
Showing
7 changed files
with
164 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
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,4 @@ | ||
_libnetplan*.c | ||
_libnetplan*.o | ||
_libnetplan*.so | ||
|
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,18 @@ | ||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Lukas Märdian <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Re-export submodules | ||
from .parser import * | ||
from .state import * |
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,70 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Lukas Märdian <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import os | ||
|
||
from cffi import FFI | ||
ffibuilder = FFI() | ||
|
||
# cdef() expects a single string declaring the C types, functions and | ||
# globals needed to use the shared object. It must be in valid C syntax. | ||
ffibuilder.cdef(""" | ||
typedef int gint; | ||
typedef gint gboolean; | ||
typedef struct GError NetplanError; | ||
typedef struct netplan_parser NetplanParser; | ||
typedef struct netplan_state NetplanState; | ||
typedef enum { | ||
NETPLAN_BACKEND_NONE, | ||
NETPLAN_BACKEND_NETWORKD, | ||
NETPLAN_BACKEND_NM, | ||
NETPLAN_BACKEND_OVS, | ||
NETPLAN_BACKEND_MAX_, | ||
} NetplanBackend; | ||
NetplanParser* netplan_parser_new(); | ||
void netplan_parser_clear(NetplanParser **npp); | ||
gboolean netplan_parser_load_yaml(NetplanParser* npp, const char* filename, NetplanError** error); | ||
gboolean netplan_parser_load_yaml_from_fd(NetplanParser* npp, int input_fd, NetplanError** error); | ||
//gboolean netplan_parser_load_yaml_hierarchy(NetplanParser* npp, const char* rootdir, GError** error); | ||
gboolean netplan_parser_load_keyfile(NetplanParser* npp, const char* filename, NetplanError** error); | ||
gboolean netplan_parser_load_nullable_fields(NetplanParser* npp, int input_fd, NetplanError** error); | ||
//gboolean netplan_parser_load_nullable_overrides(NetplanParser* npp, int input_fd, const char* constraint, GError** error); | ||
NetplanState* netplan_state_new(); | ||
void netplan_state_reset(NetplanState* np_state); | ||
void netplan_state_clear(NetplanState** np_state); | ||
NetplanBackend netplan_state_get_backend(const NetplanState* np_state); | ||
""") | ||
|
||
# set_source() gives the name of the python extension module to | ||
# produce, and some C source code as a string. This C code needs | ||
# to make the declarated functions, types and globals available, | ||
# so it is often just the "#include". | ||
ffibuilder.set_source_pkgconfig("_libnetplan0", ['glib-2.0'], | ||
""" | ||
// the C header of the library | ||
#include "netplan.h" | ||
#include "parse.h" | ||
#include "parse-nm.h" | ||
""", | ||
include_dirs=[os.getenv('CFFI_INC')], | ||
library_dirs=[os.getenv('CFFI_LIB')], | ||
libraries=['netplan', 'glib-2.0']) # library name, for the linker | ||
|
||
if __name__ == "__main__": | ||
ffibuilder.compile(verbose=False) |
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,26 @@ | ||
pymod = import('python') | ||
python = pymod.find_installation( | ||
'python3', | ||
modules: ['cffi'] | ||
) | ||
|
||
#https://mesonbuild.com/FAQ.html#but-i-really-want-to-use-wildcards | ||
out = run_command( | ||
'sh', '-c', 'python3 _build_cffi.py && find -name _libnetplan*.so', | ||
env: [ | ||
'CFFI_INC=' + join_paths(meson.project_source_root(), 'include'), | ||
'CFFI_LIB=' + join_paths(meson.current_build_dir(), 'src'), | ||
], | ||
check: true, | ||
) | ||
cffi_so = out.stdout().strip().split('\n') | ||
|
||
bindings_sources = ''' | ||
__init__.py | ||
parser.py | ||
state.py | ||
'''.split() | ||
|
||
bindings = python.install_sources( | ||
[bindings_sources, cffi_so], | ||
subdir: 'netplan') |
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,24 @@ | ||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Lukas Märdian <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from ._libnetplan0 import ffi, lib | ||
|
||
class Parser(): | ||
def __init__(self): | ||
self._ptr = lib.netplan_parser_new() | ||
|
||
def __del__(self): | ||
ref = ffi.new('NetplanParser **', self._ptr) | ||
lib.netplan_parser_clear(ref) |
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,21 @@ | ||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Lukas Märdian <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from ._libnetplan0 import ffi, lib | ||
|
||
class State(): | ||
def __init__(self): | ||
state = lib.netplan_state_new() | ||
print(lib.netplan_state_get_backend(state)) |