fix: noconfirm auto-selects first AUR match
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
def gluoninate():
|
||||
return 42
|
||||
@@ -0,0 +1,30 @@
|
||||
project('python sample')
|
||||
|
||||
py_mod = import('python')
|
||||
py = py_mod.find_installation('python3')
|
||||
|
||||
py_version = py.language_version()
|
||||
if py_version.version_compare('< 3.2')
|
||||
error('MESON_SKIP_TEST python 3 required for tests')
|
||||
endif
|
||||
|
||||
py_full_version = py.version()
|
||||
message(f'Using python version: @py_full_version@')
|
||||
|
||||
py_purelib = py.get_path('purelib')
|
||||
if not (py_purelib.endswith('site-packages') or py_purelib.endswith('dist-packages'))
|
||||
error('Python3 purelib path seems invalid? ' + py_purelib)
|
||||
endif
|
||||
message('Python purelib path:', py_purelib)
|
||||
|
||||
# could be 'lib64' or 'Lib' on some systems
|
||||
py_platlib = py.get_path('platlib')
|
||||
if not (py_platlib.endswith('site-packages') or py_platlib.endswith('dist-packages'))
|
||||
error('Python3 platlib path seems invalid? ' + py_platlib)
|
||||
endif
|
||||
|
||||
main = files('prog.py')
|
||||
|
||||
test('toplevel', py, args : main)
|
||||
|
||||
subdir('subdir')
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from gluon import gluonator
|
||||
|
||||
print('Running mainprog from root dir.')
|
||||
|
||||
if gluonator.gluoninate() != 42:
|
||||
raise ValueError("!= 42")
|
||||
@@ -0,0 +1,4 @@
|
||||
test('subdir',
|
||||
py,
|
||||
args : files('subprog.py'),
|
||||
env : 'PYTHONPATH=' + meson.source_root())
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# In order to run this program, PYTHONPATH must be set to
|
||||
# point to source root.
|
||||
|
||||
from gluon import gluonator
|
||||
|
||||
print('Running mainprog from subdir.')
|
||||
|
||||
if gluonator.gluoninate() != 42:
|
||||
raise ValueError("!= 42")
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
project('Python limited api disabled', 'c',
|
||||
default_options : ['buildtype=release', 'werror=true', 'python.allow_limited_api=false'])
|
||||
|
||||
py_mod = import('python')
|
||||
py = py_mod.find_installation()
|
||||
|
||||
module = py.extension_module('my_module',
|
||||
'module.c',
|
||||
limited_api: '3.7',
|
||||
)
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#include <Python.h>
|
||||
|
||||
#if defined(Py_LIMITED_API)
|
||||
#error "Py_LIMITED_API's definition by Meson should have been disabled."
|
||||
#endif
|
||||
|
||||
static struct PyModuleDef my_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"my_module",
|
||||
NULL,
|
||||
-1,
|
||||
NULL
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_my_module(void) {
|
||||
return PyModule_Create(&my_module);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import @tachyon_module@ as tachyon
|
||||
|
||||
result = tachyon.phaserize('shoot')
|
||||
|
||||
if not isinstance(result, int):
|
||||
raise SystemExit('Returned result not an integer.')
|
||||
|
||||
if result != 1:
|
||||
raise SystemExit('Returned result {} is not 1.'.format(result))
|
||||
@@ -0,0 +1,15 @@
|
||||
pylib = py.extension_module('tachyon',
|
||||
'tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="tachyon"',
|
||||
install: true,
|
||||
)
|
||||
|
||||
pylib2 = py2.extension_module('tachyon',
|
||||
'tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="tachyon"',
|
||||
install: true,
|
||||
)
|
||||
|
||||
subdir('nested')
|
||||
subdir('wrongdir')
|
||||
pypathdir = meson.current_build_dir()
|
||||
@@ -0,0 +1,32 @@
|
||||
py.extension_module('tachyon',
|
||||
'../tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="nested.tachyon"',
|
||||
install: true,
|
||||
subdir: 'nested'
|
||||
)
|
||||
py.install_sources(
|
||||
configure_file(
|
||||
input: '../../blaster.py.in',
|
||||
output: 'blaster.py',
|
||||
configuration: {'tachyon_module': 'nested.tachyon'}
|
||||
),
|
||||
pure: false,
|
||||
subdir: 'nested',
|
||||
)
|
||||
|
||||
|
||||
py2.extension_module('tachyon',
|
||||
'../tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="nested.tachyon"',
|
||||
install: true,
|
||||
subdir: 'nested'
|
||||
)
|
||||
py2.install_sources(
|
||||
configure_file(
|
||||
input: '../../blaster.py.in',
|
||||
output: 'blaster.py',
|
||||
configuration: {'tachyon_module': 'nested.tachyon'}
|
||||
),
|
||||
pure: false,
|
||||
subdir: 'nested',
|
||||
)
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 2018 The Meson development team
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/* A very simple Python extension module. */
|
||||
|
||||
#include <Python.h>
|
||||
#include <string.h>
|
||||
|
||||
static PyObject* phaserize(PyObject *self, PyObject *args) {
|
||||
const char *message;
|
||||
int result;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &message))
|
||||
return NULL;
|
||||
|
||||
result = strcmp(message, "shoot") ? 0 : 1;
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
return PyInt_FromLong(result);
|
||||
#else
|
||||
return PyLong_FromLong(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyMethodDef TachyonMethods[] = {
|
||||
{"phaserize", phaserize, METH_VARARGS,
|
||||
"Shoot tachyon cannons."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
PyMODINIT_FUNC inittachyon(void) {
|
||||
Py_InitModule("tachyon", TachyonMethods);
|
||||
}
|
||||
#else
|
||||
static struct PyModuleDef tachyonmodule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"tachyon",
|
||||
NULL,
|
||||
-1,
|
||||
TachyonMethods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_tachyon(void) {
|
||||
return PyModule_Create(&tachyonmodule);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
py.extension_module('tachyon',
|
||||
'../tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="tachyon"',
|
||||
install: true,
|
||||
install_dir: get_option('libdir')
|
||||
)
|
||||
py2.extension_module('tachyon',
|
||||
'../tachyon_module.c',
|
||||
c_args: '-DMESON_MODULENAME="tachyon"',
|
||||
install: true,
|
||||
install_dir: get_option('libdir')
|
||||
)
|
||||
@@ -0,0 +1,57 @@
|
||||
project('Python extension module', 'c',
|
||||
default_options : ['buildtype=release', 'werror=true', 'python.bytecompile=-1'])
|
||||
# Because Windows Python ships only with optimized libs,
|
||||
# we must build this project the same way.
|
||||
|
||||
if meson.backend() != 'ninja'
|
||||
error('MESON_SKIP_TEST: Ninja backend required')
|
||||
endif
|
||||
|
||||
|
||||
py_mod = import('python')
|
||||
py = py_mod.find_installation()
|
||||
py2 = py_mod.find_installation('python2', required: get_option('python2'), disabler: true)
|
||||
py_dep = py.dependency(required: false)
|
||||
|
||||
if not py_dep.found()
|
||||
error('MESON_SKIP_TEST: Python libraries not found.')
|
||||
endif
|
||||
|
||||
subdir('ext')
|
||||
|
||||
blaster = configure_file(
|
||||
input: 'blaster.py.in',
|
||||
output: 'blaster.py',
|
||||
configuration: {'tachyon_module': 'tachyon'}
|
||||
)
|
||||
|
||||
test('extmod',
|
||||
py,
|
||||
args : blaster,
|
||||
env : ['PYTHONPATH=' + pypathdir])
|
||||
|
||||
py.install_sources(blaster, pure: false)
|
||||
py.install_sources(blaster, subdir: 'pure')
|
||||
install_subdir('subinst', install_dir: py.get_install_dir(pure: false))
|
||||
|
||||
py2.install_sources(blaster, pure: false)
|
||||
py2.install_sources(blaster, subdir: 'pure')
|
||||
install_subdir('subinst', install_dir: py2.get_install_dir(pure: false))
|
||||
|
||||
|
||||
py3_pkg_dep = dependency('python3', method: 'pkg-config', required : false)
|
||||
if py3_pkg_dep.found()
|
||||
py3_dep_majver = py3_pkg_dep.version().split('.')
|
||||
py3_dep_majver = py3_dep_majver[0] + '.' + py3_dep_majver[1]
|
||||
message(f'got two pythons: pkg-config is @py3_dep_majver@, and module is', py.language_version())
|
||||
if py3_dep_majver != py.language_version()
|
||||
message('skipped python3 pkg-config test because the default python3 is different from Meson\'s')
|
||||
else
|
||||
python_lib_dir = py3_pkg_dep.get_pkgconfig_variable('libdir')
|
||||
|
||||
# Check we can apply a version constraint
|
||||
dependency('python3', version: '>=@0@'.format(py_dep.version()))
|
||||
endif
|
||||
else
|
||||
message('Skipped python3 pkg-config test because it was not found')
|
||||
endif
|
||||
@@ -0,0 +1 @@
|
||||
option('python2', type: 'feature', value: 'disabled')
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
print('subinst')
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
print('subinst.submod')
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"installed": [
|
||||
{ "type": "python_file", "file": "usr/@PYTHON_PLATLIB@/blaster.py" },
|
||||
{ "type": "python_lib", "file": "usr/@PYTHON_PLATLIB@/tachyon" },
|
||||
{ "type": "py_implib", "file": "usr/@PYTHON_PLATLIB@/tachyon" },
|
||||
{ "type": "python_file", "file": "usr/@PYTHON_PURELIB@/pure/blaster.py" },
|
||||
{ "type": "python_file", "file": "usr/@PYTHON_PLATLIB@/nested/blaster.py" },
|
||||
{ "type": "python_lib", "file": "usr/@PYTHON_PLATLIB@/nested/tachyon" },
|
||||
{ "type": "py_implib", "file": "usr/@PYTHON_PLATLIB@/nested/tachyon" },
|
||||
{ "type": "python_file", "file": "usr/@PYTHON_PLATLIB@/subinst/printer.py" },
|
||||
{ "type": "python_file", "file": "usr/@PYTHON_PLATLIB@/subinst/submod/printer.py" },
|
||||
{ "type": "python_lib", "file": "usr/lib/tachyon" },
|
||||
{ "type": "py_implib", "file": "usr/lib/tachyon" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from storer import Storer
|
||||
|
||||
s = Storer()
|
||||
|
||||
if s.get_value() != 0:
|
||||
raise SystemExit('Initial value incorrect.')
|
||||
|
||||
s.set_value(42)
|
||||
|
||||
if s.get_value() != 42:
|
||||
raise SystemExit('Setting value failed.')
|
||||
|
||||
try:
|
||||
s.set_value('not a number')
|
||||
raise SystemExit('Using wrong argument type did not fail.')
|
||||
except TypeError:
|
||||
pass
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
cdef extern from "storer.h":
|
||||
ctypedef struct Storer:
|
||||
pass
|
||||
|
||||
Storer* storer_new();
|
||||
void storer_destroy(Storer *s);
|
||||
int storer_get_value(Storer *s);
|
||||
void storer_set_value(Storer *s, int v);
|
||||
@@ -0,0 +1,11 @@
|
||||
pyx_c = custom_target('storer_pyx',
|
||||
output : 'storer_pyx.c',
|
||||
input : 'storer.pyx',
|
||||
command : [cython, '@INPUT@', '-o', '@OUTPUT@', '-3'],
|
||||
)
|
||||
|
||||
slib = py3.extension_module('storer',
|
||||
'storer.c', pyx_c,
|
||||
)
|
||||
|
||||
pydir = meson.current_build_dir()
|
||||
@@ -0,0 +1,24 @@
|
||||
#include"storer.h"
|
||||
#include<stdlib.h>
|
||||
|
||||
struct _Storer {
|
||||
int value;
|
||||
};
|
||||
|
||||
Storer* storer_new() {
|
||||
Storer *s = malloc(sizeof(struct _Storer));
|
||||
s->value = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
void storer_destroy(Storer *s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
int storer_get_value(Storer *s) {
|
||||
return s->value;
|
||||
}
|
||||
|
||||
void storer_set_value(Storer *s, int v) {
|
||||
s->value = v;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct _Storer Storer;
|
||||
|
||||
Storer* storer_new();
|
||||
void storer_destroy(Storer *s);
|
||||
int storer_get_value(Storer *s);
|
||||
void storer_set_value(Storer *s, int v);
|
||||
@@ -0,0 +1,16 @@
|
||||
cimport cstorer
|
||||
|
||||
cdef class Storer:
|
||||
cdef cstorer.Storer* _c_storer
|
||||
|
||||
def __cinit__(self):
|
||||
self._c_storer = cstorer.storer_new()
|
||||
|
||||
def __dealloc__(self):
|
||||
cstorer.storer_destroy(self._c_storer)
|
||||
|
||||
cpdef int get_value(self):
|
||||
return cstorer.storer_get_value(self._c_storer)
|
||||
|
||||
cpdef set_value(self, int value):
|
||||
cstorer.storer_set_value(self._c_storer, value)
|
||||
@@ -0,0 +1,25 @@
|
||||
project('cython', 'c',
|
||||
default_options : ['warning_level=3', 'buildtype=release']
|
||||
)
|
||||
if meson.backend() != 'ninja'
|
||||
error('MESON_SKIP_TEST: Ninja backend required')
|
||||
endif
|
||||
|
||||
cython = find_program('cython', required : false)
|
||||
if not cython.found()
|
||||
error('MESON_SKIP_TEST: Cython3 not found.')
|
||||
endif
|
||||
|
||||
py3 = import('python').find_installation(pure: false)
|
||||
py3_dep = py3.dependency(required: false)
|
||||
if not py3_dep.found()
|
||||
error('MESON_SKIP_TEST: Python library not found.')
|
||||
endif
|
||||
|
||||
subdir('libdir')
|
||||
|
||||
test('cython tester',
|
||||
py3,
|
||||
args : files('cytest.py'),
|
||||
env : ['PYTHONPATH=' + pydir]
|
||||
)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
filedir = Path(os.path.dirname(__file__)).resolve()
|
||||
if list(filedir.glob('ext/*tachyon*')):
|
||||
sys.path.insert(0, (filedir / 'ext').as_posix())
|
||||
|
||||
if hasattr(os, 'add_dll_directory'):
|
||||
os.add_dll_directory(filedir / 'ext' / 'lib')
|
||||
|
||||
import tachyon
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-o', dest='output', default=None)
|
||||
|
||||
options = parser.parse_args(sys.argv[1:])
|
||||
|
||||
result = tachyon.phaserize('shoot')
|
||||
|
||||
if options.output:
|
||||
with open(options.output, 'w') as f:
|
||||
f.write('success')
|
||||
|
||||
if not isinstance(result, int):
|
||||
raise SystemExit('Returned result not an integer.')
|
||||
|
||||
if result != 1:
|
||||
raise SystemExit(f'Returned result {result} is not 1.')
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
const char*
|
||||
tachyon_phaser_command (void)
|
||||
{
|
||||
return "shoot";
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllimport)
|
||||
#endif
|
||||
const char* tachyon_phaser_command (void);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
libtachyon = shared_library('tachyonlib', 'meson-tachyonlib.c')
|
||||
|
||||
libtachyon_dep = declare_dependency(link_with : libtachyon,
|
||||
include_directories : include_directories('.'))
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
subdir('lib')
|
||||
|
||||
pylib = py3.extension_module('tachyon',
|
||||
'tachyon_module.c',
|
||||
dependencies : [libtachyon_dep, py3_dep],
|
||||
)
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2016 The Meson development team
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/* A very simple Python extension module. */
|
||||
|
||||
#include <Python.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "meson-tachyonlib.h"
|
||||
|
||||
static PyObject* phaserize(PyObject *self, PyObject *args) {
|
||||
const char *message;
|
||||
int result;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &message))
|
||||
return NULL;
|
||||
|
||||
result = strcmp(message, tachyon_phaser_command()) ? 0 : 1;
|
||||
return PyLong_FromLong(result);
|
||||
}
|
||||
|
||||
static PyMethodDef TachyonMethods[] = {
|
||||
{"phaserize", phaserize, METH_VARARGS,
|
||||
"Shoot tachyon cannons."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef tachyonmodule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"tachyon",
|
||||
NULL,
|
||||
-1,
|
||||
TachyonMethods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_tachyon(void) {
|
||||
return PyModule_Create(&tachyonmodule);
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
project('Python extension module', 'c',
|
||||
default_options : ['buildtype=release'])
|
||||
# Because Windows Python ships only with optimized libs,
|
||||
# we must build this project the same way.
|
||||
|
||||
if meson.backend() != 'ninja'
|
||||
error('MESON_SKIP_TEST: Ninja backend required')
|
||||
endif
|
||||
|
||||
py_mod = import('python')
|
||||
py3 = py_mod.find_installation()
|
||||
py3_dep = py3.dependency(required : false)
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
if not py3_dep.found()
|
||||
error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.')
|
||||
endif
|
||||
|
||||
# Copy to the builddir so that blaster.py can find the built tachyon module
|
||||
# FIXME: We should automatically detect this case and append the correct paths
|
||||
# to PYTHONLIBDIR
|
||||
blaster_py = configure_file(input : 'blaster.py',
|
||||
output : 'blaster.py',
|
||||
copy : true)
|
||||
|
||||
check_exists = '''
|
||||
import os, sys
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
assert(f.read() == b'success')
|
||||
'''
|
||||
|
||||
message('Detected Python version: ' + py3_dep.version())
|
||||
if py3_dep.version().version_compare('>=3.8') and cc.get_id() == 'msvc' and cc.version().version_compare('<=19.00.24215.1')
|
||||
error('MESON_SKIP_TEST: Python modules do not work with Python 3.8 and VS2015 or earlier.')
|
||||
endif
|
||||
subdir('ext')
|
||||
|
||||
out_txt = custom_target('tachyon flux',
|
||||
input : blaster_py,
|
||||
output : 'out.txt',
|
||||
command : [py3, '@INPUT@', '-o', '@OUTPUT@'],
|
||||
depends : pylib,
|
||||
build_by_default: true)
|
||||
|
||||
test('flux', py3, args : ['-c', check_exists, out_txt])
|
||||
@@ -0,0 +1,7 @@
|
||||
project('python kwarg')
|
||||
|
||||
py = import('python')
|
||||
prog_python = py.find_installation('python3', modules : ['os', 'sys', 're'])
|
||||
assert(prog_python.found() == true, 'python not found when should be')
|
||||
prog_python = py.find_installation('python3', modules : ['thisbetternotexistmod'], required : false)
|
||||
assert(prog_python.found() == false, 'python not found but reported as found')
|
||||
@@ -0,0 +1,5 @@
|
||||
project('foo', 'cpp')
|
||||
|
||||
# Regression test for https://github.com/mesonbuild/meson/issues/9038
|
||||
dependency('bar', required: false, allow_fallback: true)
|
||||
python = import('python').find_installation('python3').dependency()
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
project('bar', 'cpp')
|
||||
|
||||
python = import('python').find_installation('python3')
|
||||
dependency('nonexistent-dependency')
|
||||
@@ -0,0 +1,25 @@
|
||||
project('install path',
|
||||
default_options: [
|
||||
'python.bytecompile=-1',
|
||||
'python.purelibdir=/pure',
|
||||
'python.platlibdir=/plat',
|
||||
]
|
||||
)
|
||||
|
||||
py = import('python').find_installation()
|
||||
py.install_sources('test.py')
|
||||
py.install_sources('test.py', pure: false)
|
||||
install_data('test.py', install_dir: py.get_install_dir() / 'data')
|
||||
install_data('test.py', install_dir: py.get_install_dir(pure: false) / 'data')
|
||||
|
||||
py_plat = import('python').find_installation(pure: false)
|
||||
py_plat.install_sources('test.py', subdir: 'kw')
|
||||
py_plat.install_sources('test.py', pure: true, subdir: 'kwrevert')
|
||||
install_data('test.py', install_dir: py_plat.get_install_dir() / 'kw/data')
|
||||
install_data('test.py', install_dir: py_plat.get_install_dir(pure: true) / 'kwrevert/data')
|
||||
|
||||
if get_option('backend') == 'none'
|
||||
subdir('target')
|
||||
endif
|
||||
|
||||
subdir('structured')
|
||||
@@ -0,0 +1,9 @@
|
||||
py.install_sources(
|
||||
'one.py',
|
||||
'two.py',
|
||||
'alpha/one.py',
|
||||
'alpha/two.py',
|
||||
'alpha/three.py',
|
||||
'beta/one.py',
|
||||
preserve_path: true,
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"installed": [
|
||||
{"type": "file", "file": "pure/one.py"},
|
||||
{"type": "file", "file": "pure/two.py"},
|
||||
{"type": "file", "file": "pure/alpha/one.py"},
|
||||
{"type": "file", "file": "pure/alpha/two.py"},
|
||||
{"type": "file", "file": "pure/alpha/three.py"},
|
||||
{"type": "file", "file": "pure/beta/one.py"},
|
||||
{"type": "file", "file": "plat/kw/test.py"},
|
||||
{"type": "file", "file": "pure/kwrevert/test.py"},
|
||||
{"type": "file", "file": "plat/test.py"},
|
||||
{"type": "file", "file": "pure/test.py"},
|
||||
{"type": "file", "file": "plat/data/test.py"},
|
||||
{"type": "file", "file": "pure/data/test.py"},
|
||||
{"type": "file", "file": "plat/kw/data/test.py"},
|
||||
{"type": "file", "file": "pure/kwrevert/data/test.py"}
|
||||
]
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import tachyon
|
||||
|
||||
result = tachyon.phaserize('shoot')
|
||||
|
||||
if not isinstance(result, int):
|
||||
print('Returned result not an integer.')
|
||||
sys.exit(1)
|
||||
|
||||
if result != 1:
|
||||
print('Returned result {} is not 1.'.format(result))
|
||||
sys.exit(1)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
pylib = py.extension_module('tachyon',
|
||||
'tachyon_module.c',
|
||||
dependencies : py_dep,
|
||||
)
|
||||
|
||||
pypathdir = meson.current_build_dir()
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 2018 The Meson development team
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/* A very simple Python extension module. */
|
||||
|
||||
#include <Python.h>
|
||||
#include <string.h>
|
||||
|
||||
static PyObject* phaserize(PyObject *self, PyObject *args) {
|
||||
const char *message;
|
||||
int result;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &message))
|
||||
return NULL;
|
||||
|
||||
result = strcmp(message, "shoot") ? 0 : 1;
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
return PyInt_FromLong(result);
|
||||
#else
|
||||
return PyLong_FromLong(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyMethodDef TachyonMethods[] = {
|
||||
{"phaserize", phaserize, METH_VARARGS,
|
||||
"Shoot tachyon cannons."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
PyMODINIT_FUNC inittachyon(void) {
|
||||
Py_InitModule("tachyon", TachyonMethods);
|
||||
}
|
||||
#else
|
||||
static struct PyModuleDef tachyonmodule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"tachyon",
|
||||
NULL,
|
||||
-1,
|
||||
TachyonMethods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_tachyon(void) {
|
||||
return PyModule_Create(&tachyonmodule);
|
||||
}
|
||||
#endif
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
project('Python extension module', 'c',
|
||||
default_options : ['buildtype=release'])
|
||||
|
||||
py_mod = import('python')
|
||||
|
||||
py = py_mod.find_installation(get_option('python'), required : false)
|
||||
|
||||
# CI images don't have 32-bit python2 for 32-bit windows,
|
||||
# so this actually gets detected then fails
|
||||
require = not (
|
||||
get_option('python') == 'python2' and
|
||||
host_machine.system() == 'windows' and
|
||||
host_machine.cpu() == 'x86'
|
||||
)
|
||||
|
||||
if py.found()
|
||||
py_dep = py.dependency(required: require)
|
||||
|
||||
if py_dep.found()
|
||||
subdir('ext')
|
||||
|
||||
test('extmod',
|
||||
py,
|
||||
args : files('blaster.py'),
|
||||
env : ['PYTHONPATH=' + pypathdir])
|
||||
else
|
||||
error('MESON_SKIP_TEST: Python libraries not found, skipping test.')
|
||||
endif
|
||||
else
|
||||
error('MESON_SKIP_TEST: Python not found, skipping test.')
|
||||
endif
|
||||
|
||||
py = py_mod.find_installation(get_option('python'), required : get_option('disabled_opt'))
|
||||
assert(not py.found(), 'find_installation not working with disabled feature')
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
option('python', type: 'string',
|
||||
description: 'Name of or path to the python executable'
|
||||
)
|
||||
option('disabled_opt', type: 'feature', value: 'disabled')
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"matrix": {
|
||||
"options": {
|
||||
"python": [
|
||||
{ "val": null },
|
||||
{ "val": "python2" },
|
||||
{ "val": "python3" },
|
||||
{ "val": "pypy" },
|
||||
{ "val": "pypy3" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <Python.h>
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
#error Py_LIMITED_API must be defined.
|
||||
#elif Py_LIMITED_API != 0x03070000
|
||||
#error Wrong value for Py_LIMITED_API
|
||||
#endif
|
||||
|
||||
static struct PyModuleDef limited_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"limited_api_test",
|
||||
NULL,
|
||||
-1,
|
||||
NULL
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_limited(void) {
|
||||
return PyModule_Create(&limited_module);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
project('Python limited api', 'c',
|
||||
default_options : ['buildtype=release', 'werror=true'])
|
||||
|
||||
py_mod = import('python')
|
||||
py = py_mod.find_installation()
|
||||
|
||||
ext_mod_limited = py.extension_module('limited',
|
||||
'limited.c',
|
||||
limited_api: '3.7',
|
||||
install: true,
|
||||
)
|
||||
|
||||
ext_mod = py.extension_module('not_limited',
|
||||
'not_limited.c',
|
||||
install: true,
|
||||
)
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef Py_LIMITED_API
|
||||
#error Py_LIMITED_API must not be defined.
|
||||
#endif
|
||||
|
||||
/* This function explicitly calls functions whose declaration is elided when
|
||||
* Py_LIMITED_API is defined. This is to test that the linker is actually
|
||||
* linking to the right version of the library on Windows. */
|
||||
static PyObject *meth_not_limited(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *list;
|
||||
Py_ssize_t size;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "o", & list))
|
||||
return NULL;
|
||||
|
||||
if (!PyList_Check(list)) {
|
||||
PyErr_Format(PyExc_TypeError, "expected 'list'");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* PyList_GET_SIZE and PyList_GET_ITEM are only available if Py_LIMITED_API
|
||||
* is not defined. It seems likely that they will remain excluded from the
|
||||
* limited API as their checked counterparts (PyList_GetSize and
|
||||
* PyList_GetItem) are made available in that mode instead. */
|
||||
size = PyList_GET_SIZE(list);
|
||||
for(Py_ssize_t i = 0; i < size; ++i) {
|
||||
PyObject *element = PyList_GET_ITEM(list, i);
|
||||
if (element == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(PyObject_Print(element, stdout, Py_PRINT_RAW) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef not_limited_methods[] = {
|
||||
{ "not_limited", meth_not_limited, METH_VARARGS,
|
||||
"Calls functions whose declaration is elided by Py_LIMITED_API" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static struct PyModuleDef not_limited_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"not_limited_api_test",
|
||||
NULL,
|
||||
-1,
|
||||
not_limited_methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_not_limited(void) {
|
||||
return PyModule_Create(¬_limited_module);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"installed": [
|
||||
{"type": "python_limited_lib", "file": "usr/@PYTHON_PLATLIB@/limited"},
|
||||
{"type": "py_limited_implib", "file": "usr/@PYTHON_PLATLIB@/limited"},
|
||||
{"type": "python_lib", "file": "usr/@PYTHON_PLATLIB@/not_limited"},
|
||||
{"type": "py_implib", "file": "usr/@PYTHON_PLATLIB@/not_limited"}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user