aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Fs-module.md15
-rw-r--r--docs/markdown/snippets/fs_suffix.md4
-rw-r--r--docs/markdown/snippets/swift-module-name.md9
-rw-r--r--mesonbuild/backend/ninjabackend.py7
-rw-r--r--mesonbuild/build.py10
-rw-r--r--mesonbuild/interpreter/kwargs.py1
-rw-r--r--mesonbuild/interpreter/type_checking.py1
-rw-r--r--mesonbuild/modules/fs.py10
-rw-r--r--test cases/common/220 fs module/meson.build8
-rw-r--r--test cases/vala/32 valaless vapigen/clib.c5
-rw-r--r--test cases/vala/32 valaless vapigen/clib.h3
-rw-r--r--test cases/vala/32 valaless vapigen/meson.build34
-rw-r--r--test cases/vala/32 valaless vapigen/test_clib.c9
13 files changed, 107 insertions, 9 deletions
diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md
index 7ba4832..91c706e 100644
--- a/docs/markdown/Fs-module.md
+++ b/docs/markdown/Fs-module.md
@@ -206,13 +206,26 @@ fs.name('foo/bar/baz.dll.a') # baz.dll.a
*since 0.54.0*
Returns the last component of the path, dropping the last part of the
-suffix
+suffix.
```meson
fs.stem('foo/bar/baz.dll') # baz
fs.stem('foo/bar/baz.dll.a') # baz.dll
```
+### suffix
+
+*since 1.9.0*
+
+Returns the last dot-separated portion of the final component of the path
+including the dot, if any.
+
+```meson
+fs.suffix('foo/bar/baz.dll') # .dll
+fs.suffix('foo/bar/baz.dll.a') # .a
+fs.suffix('foo/bar') # (empty)
+```
+
### read
- `read(path, encoding: 'utf-8')` *(since 0.57.0)*:
return a [string](Syntax.md#strings) with the contents of the given `path`.
diff --git a/docs/markdown/snippets/fs_suffix.md b/docs/markdown/snippets/fs_suffix.md
new file mode 100644
index 0000000..7059008
--- /dev/null
+++ b/docs/markdown/snippets/fs_suffix.md
@@ -0,0 +1,4 @@
+## Added suffix function to the FS module
+
+The basename and stem were already available. For completeness, expose also the
+suffix.
diff --git a/docs/markdown/snippets/swift-module-name.md b/docs/markdown/snippets/swift-module-name.md
new file mode 100644
index 0000000..689dd84
--- /dev/null
+++ b/docs/markdown/snippets/swift-module-name.md
@@ -0,0 +1,9 @@
+## Explicitly setting Swift module name is now supported
+
+It is now possible to set the Swift module name for a target via the
+*swift_module_name* target kwarg, overriding the default inferred from the
+target name.
+
+```meson
+lib = library('foo', 'foo.swift', swift_module_name: 'Foo')
+```
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 82411b0..eebdd05 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2232,10 +2232,7 @@ class NinjaBackend(backends.Backend):
def swift_module_file_name(self, target):
return os.path.join(self.get_target_private_dir(target),
- self.target_swift_modulename(target) + '.swiftmodule')
-
- def target_swift_modulename(self, target):
- return target.name
+ target.swift_module_name + '.swiftmodule')
def determine_swift_dep_modules(self, target):
result = []
@@ -2262,7 +2259,7 @@ class NinjaBackend(backends.Backend):
return srcs, others
def generate_swift_target(self, target) -> None:
- module_name = self.target_swift_modulename(target)
+ module_name = target.swift_module_name
swiftc = target.compilers['swift']
abssrc = []
relsrc = []
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 72d376d..1745b9e 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -75,6 +75,7 @@ lang_arg_kwargs |= {
vala_kwargs = {'vala_header', 'vala_gir', 'vala_vapi'}
rust_kwargs = {'rust_crate_type', 'rust_dependency_map'}
cs_kwargs = {'resources', 'cs_args'}
+swift_kwargs = {'swift_module_name'}
buildtarget_kwargs = {
'build_by_default',
@@ -110,7 +111,8 @@ known_build_target_kwargs = (
pch_kwargs |
vala_kwargs |
rust_kwargs |
- cs_kwargs)
+ cs_kwargs |
+ swift_kwargs)
known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic', 'pie', 'vs_module_defs', 'android_exe_type'}
known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs', 'darwin_versions', 'rust_abi'}
@@ -963,7 +965,7 @@ class BuildTarget(Target):
self.compilers[lang] = compiler
break
else:
- if is_known_suffix(s):
+ if is_known_suffix(s) and not is_header(s):
path = pathlib.Path(str(s)).as_posix()
m = f'No {self.for_machine.get_lower_case_name()} machine compiler for {path!r}'
raise MesonException(m)
@@ -1260,6 +1262,10 @@ class BuildTarget(Target):
raise InvalidArguments(f'Invalid rust_dependency_map "{rust_dependency_map}": must be a dictionary with string values.')
self.rust_dependency_map = rust_dependency_map
+ self.swift_module_name = kwargs.get('swift_module_name')
+ if self.swift_module_name == '':
+ self.swift_module_name = self.name
+
def _extract_pic_pie(self, kwargs: T.Dict[str, T.Any], arg: str, option: str) -> bool:
# Check if we have -fPIC, -fpic, -fPIE, or -fpie in cflags
all_flags = self.extra_args['c'] + self.extra_args['cpp']
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index d741aab..62d855d 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -363,6 +363,7 @@ class _BuildTarget(_BaseBuildTarget):
d_module_versions: T.List[T.Union[str, int]]
d_unittest: bool
rust_dependency_map: T.Dict[str, str]
+ swift_module_name: str
sources: SourcesVarargsType
c_args: T.List[str]
cpp_args: T.List[str]
diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py
index fbe3e3e..a94e26b 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -633,6 +633,7 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [
default={},
since='1.2.0',
),
+ KwargInfo('swift_module_name', str, default='', since='1.9.0'),
KwargInfo('build_rpath', str, default='', since='0.42.0'),
KwargInfo(
'gnu_symbol_visibility',
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index f6c1e1d..57a6b6d 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -44,7 +44,7 @@ class FSModule(ExtensionModule):
INFO = ModuleInfo('fs', '0.53.0')
- def __init__(self, interpreter: 'Interpreter') -> None:
+ def __init__(self, interpreter: Interpreter) -> None:
super().__init__(interpreter)
self.methods.update({
'as_posix': self.as_posix,
@@ -64,6 +64,7 @@ class FSModule(ExtensionModule):
'replace_suffix': self.replace_suffix,
'size': self.size,
'stem': self.stem,
+ 'suffix': self.suffix,
})
def _absolute_dir(self, state: ModuleState, arg: FileOrString) -> str:
@@ -225,6 +226,13 @@ class FSModule(ExtensionModule):
path = self._obj_to_pathstr('fs.name', args[0], state)
return os.path.splitext(os.path.basename(path))[0]
+ @noKwargs
+ @typed_pos_args('fs.suffix', (str, File, CustomTarget, CustomTargetIndex, BuildTarget))
+ @FeatureNew('fs.suffix', '1.9.0')
+ def suffix(self, state: ModuleState, args: T.Tuple[T.Union[FileOrString, BuildTargetTypes]], kwargs: T.Dict[str, T.Any]) -> str:
+ path = self._obj_to_pathstr('fs.suffix', args[0], state)
+ return os.path.splitext(path)[1]
+
@FeatureNew('fs.read', '0.57.0')
@typed_pos_args('fs.read', (str, File))
@typed_kwargs('fs.read', KwargInfo('encoding', str, default='utf-8'))
diff --git a/test cases/common/220 fs module/meson.build b/test cases/common/220 fs module/meson.build
index f90a996..383b263 100644
--- a/test cases/common/220 fs module/meson.build
+++ b/test cases/common/220 fs module/meson.build
@@ -150,8 +150,10 @@ assert(fs.name(f[1]) == 'meson.build', 'failed to get basename')
assert(fs.name('foo/bar/baz.dll.a') == 'baz.dll.a', 'failed to get basename with compound suffix')
if host_machine.system() in ['cygwin', 'windows']
assert(fs.name(btgt) == 'btgt.exe', 'failed to get basename of build target')
+ assert(fs.suffix(btgt) == '.exe', 'failed to get build target suffix')
else
assert(fs.name(btgt) == 'btgt', 'failed to get basename of build target')
+ assert(fs.suffix(btgt) == '', 'failed to get build target suffix')
endif
assert(fs.name(ctgt) == 'ctgt.txt', 'failed to get basename of custom target')
assert(fs.name(ctgt[0]) == 'ctgt.txt', 'failed to get basename of custom target index')
@@ -160,6 +162,12 @@ assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compo
assert(fs.stem(btgt) == 'btgt', 'failed to get stem of build target')
assert(fs.stem(ctgt) == 'ctgt', 'failed to get stem of custom target')
assert(fs.stem(ctgt[0]) == 'ctgt', 'failed to get stem of custom target index')
+assert(fs.suffix('foo/bar/baz') == '', 'failed to get missing suffix')
+assert(fs.suffix('foo/bar/baz.') == '.', 'failed to get empty suffix')
+assert(fs.suffix('foo/bar/baz.dll') == '.dll', 'failed to get plain suffix')
+assert(fs.suffix('foo/bar/baz.dll.a') == '.a', 'failed to get final suffix')
+assert(fs.suffix(ctgt) == '.txt', 'failed to get suffix of custom target')
+assert(fs.suffix(ctgt[0]) == '.txt', 'failed to get suffix of custom target index')
# relative_to
if build_machine.system() == 'windows'
diff --git a/test cases/vala/32 valaless vapigen/clib.c b/test cases/vala/32 valaless vapigen/clib.c
new file mode 100644
index 0000000..a55ecd4
--- /dev/null
+++ b/test cases/vala/32 valaless vapigen/clib.c
@@ -0,0 +1,5 @@
+#include "clib.h"
+
+int clib_fun(void) {
+ return 42;
+}
diff --git a/test cases/vala/32 valaless vapigen/clib.h b/test cases/vala/32 valaless vapigen/clib.h
new file mode 100644
index 0000000..4d855c9
--- /dev/null
+++ b/test cases/vala/32 valaless vapigen/clib.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int clib_fun(void);
diff --git a/test cases/vala/32 valaless vapigen/meson.build b/test cases/vala/32 valaless vapigen/meson.build
new file mode 100644
index 0000000..22a99e5
--- /dev/null
+++ b/test cases/vala/32 valaless vapigen/meson.build
@@ -0,0 +1,34 @@
+project('valaless-vapigen', 'c')
+
+if host_machine.system() == 'cygwin'
+ error('MESON_SKIP_TEST Does not work with the Vala currently packaged in cygwin')
+endif
+
+gnome = import('gnome')
+
+clib_src = [
+ 'clib.c',
+ 'clib.h'
+]
+
+clib_lib = shared_library('clib', clib_src)
+
+clib_gir = gnome.generate_gir(clib_lib,
+ sources: clib_src,
+ namespace: 'Clib',
+ nsversion: '0',
+ header: 'clib.h',
+ symbol_prefix: 'clib'
+)
+
+clib_vapi = gnome.generate_vapi('clib', sources: clib_gir[0])
+
+clib_dep = declare_dependency(
+ include_directories: include_directories('.'),
+ link_with: clib_lib,
+ sources: clib_gir,
+ dependencies: clib_vapi
+)
+
+
+test('clib-test', executable('clib-test', 'test_clib.c', dependencies: clib_dep))
diff --git a/test cases/vala/32 valaless vapigen/test_clib.c b/test cases/vala/32 valaless vapigen/test_clib.c
new file mode 100644
index 0000000..6fd426c
--- /dev/null
+++ b/test cases/vala/32 valaless vapigen/test_clib.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+#include <clib.h>
+
+int main(void) {
+ if (clib_fun () == 42)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}