summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-24 13:19:54 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 20:03:48 -0500
commit8366ebd3a153b25273176c75f4623d7a592144c5 (patch)
treed953a42ba47d85fe3b6095ab93aa91cce9111e4b
parent8ef53b017d085a36bab7580111b8169ae07a0666 (diff)
downloadlilv-8366ebd3a153b25273176c75f4623d7a592144c5.tar.gz
lilv-8366ebd3a153b25273176c75f4623d7a592144c5.tar.bz2
lilv-8366ebd3a153b25273176c75f4623d7a592144c5.zip
Use zix_expand_environment_strings()
The removed test was the last that needed access to private code, so also remove all of the build complication around ensuring there's a static library to test (avoiding a double build in many cases).
-rw-r--r--NEWS3
-rw-r--r--meson.build26
-rw-r--r--src/util.c78
-rw-r--r--src/world.c5
-rw-r--r--test/bad_syntax.lv2/meson.build2
-rw-r--r--test/cpp/meson.build2
-rw-r--r--test/failed_instantiation.lv2/meson.build2
-rw-r--r--test/failed_lib_descriptor.lv2/meson.build2
-rw-r--r--test/lib_descriptor.lv2/meson.build2
-rw-r--r--test/meson.build5
-rw-r--r--test/missing_descriptor.lv2/meson.build2
-rw-r--r--test/missing_name.lv2/meson.build2
-rw-r--r--test/missing_plugin.lv2/meson.build2
-rw-r--r--test/missing_port.lv2/meson.build2
-rw-r--r--test/missing_port_name.lv2/meson.build2
-rw-r--r--test/test_string.c54
16 files changed, 18 insertions, 173 deletions
diff --git a/NEWS b/NEWS
index 2a9424a..220f4b3 100644
--- a/NEWS
+++ b/NEWS
@@ -5,8 +5,9 @@ lilv (0.24.25) unstable; urgency=medium
* Fix library current_version on MacOS
* Fix test suite when TMPDIR has no trailing slash
* Improve const correctness
+ * Replace more platform-specific code with use of zix
- -- David Robillard <d@drobilla.net> Sun, 06 Oct 2024 18:27:31 +0000
+ -- David Robillard <d@drobilla.net> Mon, 25 Nov 2024 01:02:40 +0000
lilv (0.24.24) stable; urgency=medium
diff --git a/meson.build b/meson.build
index fd5b001..b9e5d6c 100644
--- a/meson.build
+++ b/meson.build
@@ -222,7 +222,7 @@ add_project_arguments(platform_defines, language: ['c'])
m_dep = cc.find_library('m', required: false)
dl_dep = cc.find_library('dl', required: false)
-zix_dep = dependency('zix-0', fallback: 'zix', version: '>= 0.4.0')
+zix_dep = dependency('zix-0', fallback: 'zix', version: '>= 0.5.1')
serd_dep = dependency('serd-0', fallback: 'serd', version: '>= 0.30.10')
sord_dep = dependency('sord-0', fallback: 'sord', version: '>= 0.16.15')
lv2_dep = dependency('lv2', fallback: 'lv2', version: '>= 1.18.2')
@@ -358,29 +358,5 @@ if not get_option('docs').disabled()
endif
if not get_option('tests').disabled()
- # Get or build a static library for linking internal tests
- if get_option('default_library') == 'both'
- liblilv_static = liblilv.get_static_lib()
- elif get_option('default_library') == 'shared'
- liblilv_static = static_library(
- versioned_name,
- sources,
- include_directories: include_directories('include', 'src'),
- c_args: c_suppressions + ['-DLILV_INTERNAL', '-DLILV_STATIC'],
- dependencies: common_dependencies,
- gnu_symbol_visibility: 'default',
- )
- else
- liblilv_static = liblilv
- endif
-
- lilv_static_dep = declare_dependency(
- compile_args: extra_c_args,
- dependencies: common_dependencies,
- include_directories: include_directories('include'),
- link_with: liblilv_static,
- )
-
- # Build and run tests against static library
subdir('test')
endif
diff --git a/src/util.c b/src/util.c
index c0047d9..278f0de 100644
--- a/src/util.c
+++ b/src/util.c
@@ -12,7 +12,6 @@
#include <sys/stat.h>
-#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -133,83 +132,6 @@ lilv_get_lang(void)
return lang;
}
-#ifndef _WIN32
-
-/** Append suffix to dst, update dst_len, and return the realloc'd result. */
-static char*
-strappend(char* dst, size_t* dst_len, const char* suffix, size_t suffix_len)
-{
- dst = (char*)realloc(dst, *dst_len + suffix_len + 1);
- memcpy(dst + *dst_len, suffix, suffix_len);
- dst[(*dst_len += suffix_len)] = '\0';
- return dst;
-}
-
-/** Append the value of the environment variable var to dst. */
-static char*
-append_var(char* dst, size_t* dst_len, const char* var)
-{
- // Get value from environment
- const char* val = getenv(var);
- if (val) { // Value found, append it
- return strappend(dst, dst_len, val, strlen(val));
- }
-
- // No value found, append variable reference as-is
- return strappend(strappend(dst, dst_len, "$", 1), dst_len, var, strlen(var));
-}
-
-#endif
-
-/** Expand variables (e.g. POSIX ~ or $FOO, Windows %FOO%) in `path`. */
-char*
-lilv_expand(const char* path)
-{
-#ifdef _WIN32
- char* out = (char*)malloc(MAX_PATH);
- ExpandEnvironmentStrings(path, out, MAX_PATH);
-#else
- char* out = NULL;
- size_t len = 0;
-
- const char* start = path; // Start of current chunk to copy
- for (const char* s = path; *s;) {
- if (*s == '$') {
- // Hit $ (variable reference, e.g. $VAR_NAME)
- for (const char* t = s + 1;; ++t) {
- if (!*t || (!isupper(*t) && !isdigit(*t) && *t != '_')) {
- // Append preceding chunk
- out = strappend(out, &len, start, s - start);
-
- // Append variable value (or $VAR_NAME if not found)
- char* var = (char*)calloc(t - s, 1);
- memcpy(var, s + 1, t - s - 1);
- out = append_var(out, &len, var);
- free(var);
-
- // Continue after variable reference
- start = s = t;
- break;
- }
- }
- } else if (*s == '~' && (*(s + 1) == '/' || !*(s + 1))) {
- // Hit ~ before slash or end of string (home directory reference)
- out = strappend(out, &len, start, s - start);
- out = append_var(out, &len, "HOME");
- start = ++s;
- } else {
- ++s;
- }
- }
-
- if (*start) {
- out = strappend(out, &len, start, strlen(start));
- }
-#endif
-
- return out;
-}
-
char*
lilv_find_free_path(const char* in_path,
bool (*exists)(const char*, const void*),
diff --git a/src/world.c b/src/world.c
index d4d7f8b..1dfae9c 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,4 +1,4 @@
-// Copyright 2007-2019 David Robillard <d@drobilla.net>
+// Copyright 2007-2024 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#include "lilv_config.h" // IWYU pragma: keep
@@ -7,6 +7,7 @@
#include "lilv/lilv.h"
#include "serd/serd.h"
#include "sord/sord.h"
+#include "zix/environment.h"
#include "zix/filesystem.h"
#include "zix/tree.h"
@@ -966,7 +967,7 @@ load_dir_entry(const char* dir, const char* name, void* data)
static void
lilv_world_load_directory(LilvWorld* world, const char* dir_path)
{
- char* path = lilv_expand(dir_path);
+ char* const path = zix_expand_environment_strings(NULL, dir_path);
if (path) {
zix_dir_for_each(path, world, load_dir_entry);
free(path);
diff --git a/test/bad_syntax.lv2/meson.build b/test/bad_syntax.lv2/meson.build
index dbda502..2e22042 100644
--- a/test/bad_syntax.lv2/meson.build
+++ b/test/bad_syntax.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_bad_syntax',
files('test_bad_syntax.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/cpp/meson.build b/test/cpp/meson.build
index 5b8169c..1d697fa 100644
--- a/test/cpp/meson.build
+++ b/test/cpp/meson.build
@@ -30,7 +30,7 @@ test(
'test_lilv_hpp',
files('test_lilv_hpp.cpp'),
cpp_args: test_args + cpp_suppressions,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
include_directories: include_directories('../../src'),
),
suite: 'unit',
diff --git a/test/failed_instantiation.lv2/meson.build b/test/failed_instantiation.lv2/meson.build
index 966eed0..37f8e26 100644
--- a/test/failed_instantiation.lv2/meson.build
+++ b/test/failed_instantiation.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_failed_instantiation',
files('test_failed_instantiation.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/failed_lib_descriptor.lv2/meson.build b/test/failed_lib_descriptor.lv2/meson.build
index 61de196..15c01e1 100644
--- a/test/failed_lib_descriptor.lv2/meson.build
+++ b/test/failed_lib_descriptor.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_failed_lib_descriptor',
files('test_failed_lib_descriptor.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/lib_descriptor.lv2/meson.build b/test/lib_descriptor.lv2/meson.build
index ea29b6a..e70ed29 100644
--- a/test/lib_descriptor.lv2/meson.build
+++ b/test/lib_descriptor.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_lib_descriptor',
files('test_lib_descriptor.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/meson.build b/test/meson.build
index 1274001..3aa1869 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -5,7 +5,7 @@
# Test Setup #
##############
-test_args = ['-DLILV_STATIC']
+test_args = []
if cc.get_id() == 'msvc'
test_args += [
'/wd4464', # relative include path contains '..'
@@ -60,7 +60,6 @@ unit_tests = [
'reload_bundle',
'replace_version',
'state',
- 'string',
'ui',
'util',
'value',
@@ -83,7 +82,7 @@ foreach unit : unit_tests
files('lilv_test_utils.c', 'test_@0@.c'.format(unit)),
c_args: define_args + test_args + c_suppressions,
include_directories: include_directories('../src'),
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
suite: 'unit',
)
diff --git a/test/missing_descriptor.lv2/meson.build b/test/missing_descriptor.lv2/meson.build
index b4ad32f..78d749b 100644
--- a/test/missing_descriptor.lv2/meson.build
+++ b/test/missing_descriptor.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_missing_descriptor',
files('test_missing_descriptor.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/missing_name.lv2/meson.build b/test/missing_name.lv2/meson.build
index c32cbb5..56a695a 100644
--- a/test/missing_name.lv2/meson.build
+++ b/test/missing_name.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_missing_name',
files('test_missing_name.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/missing_plugin.lv2/meson.build b/test/missing_plugin.lv2/meson.build
index b5819ff..7e6f51f 100644
--- a/test/missing_plugin.lv2/meson.build
+++ b/test/missing_plugin.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_missing_plugin',
files('test_missing_plugin.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/missing_port.lv2/meson.build b/test/missing_port.lv2/meson.build
index f6138d8..8dfc655 100644
--- a/test/missing_port.lv2/meson.build
+++ b/test/missing_port.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_missing_port',
files('test_missing_port.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/missing_port_name.lv2/meson.build b/test/missing_port_name.lv2/meson.build
index 3bddcee..734177f 100644
--- a/test/missing_port_name.lv2/meson.build
+++ b/test/missing_port_name.lv2/meson.build
@@ -28,7 +28,7 @@ test(
'test_missing_port_name',
files('test_missing_port_name.c'),
c_args: c_suppressions + test_args,
- dependencies: [lv2_dep, lilv_static_dep],
+ dependencies: [lv2_dep, lilv_dep],
),
args: [meson.current_build_dir() / ''],
suite: 'plugin',
diff --git a/test/test_string.c b/test/test_string.c
deleted file mode 100644
index e20669d..0000000
--- a/test/test_string.c
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2007-2024 David Robillard <d@drobilla.net>
-// SPDX-License-Identifier: ISC
-
-#undef NDEBUG
-
-#include "lilv_test_utils.h"
-
-#include "../src/lilv_internal.h"
-
-#ifdef _WIN32
-# include <windows.h>
-# define setenv(n, v, r) SetEnvironmentVariable((n), (v))
-# define unsetenv(n) SetEnvironmentVariable((n), NULL)
-#endif
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef _WIN32
-static void
-check_expansion(const char* const path, const char* const expected)
-{
- char* const expanded = lilv_expand(path);
- assert(!strcmp(expanded, expected));
- free(expanded);
-}
-#endif
-
-int
-main(void)
-{
-#ifndef _WIN32
- setenv("LILV_TEST_1", "test", 1);
-
- const char* const home = getenv("HOME");
-
- check_expansion("$LILV_TEST_1", "test");
-
- if (home) {
- char* const home_foo = string_concat(home, "/foo");
- check_expansion("~", home);
- check_expansion("~foo", "~foo");
- check_expansion("~/foo", home_foo);
- free(home_foo);
- }
-
- check_expansion("$NOT_A_VAR", "$NOT_A_VAR");
-
- unsetenv("LILV_TEST_1");
-#endif
-
- return 0;
-}