[PATCH RFC weston 1/4] tests: Don't rely on build directory layout
Daniel Stone
daniels at collabora.com
Tue Nov 29 17:00:00 UTC 2016
Rather than having a hardcoded dependency on the build-directory layout,
use an explicit module-map environment variable, which rewrites requests
for modules and helper/libexec binaries to specific paths.
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
compositor/main.c | 25 +++++++++++++++++-----
compositor/text-backend.c | 6 +-----
compositor/weston-screenshooter.c | 8 +++----
compositor/weston.h | 3 +++
desktop-shell/shell.c | 9 ++------
libweston/compositor.c | 45 ++++++++++++++++++++++++++++++++++-----
libweston/compositor.h | 3 +++
tests/ivi_layout-test-plugin.c | 12 +++++------
tests/weston-tests-env | 20 +++++++++++++----
9 files changed, 94 insertions(+), 37 deletions(-)
diff --git a/compositor/main.c b/compositor/main.c
index 2aa4936..32b099e 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -763,7 +763,6 @@ weston_create_listening_socket(struct wl_display *display, const char *socket_na
WL_EXPORT void *
wet_load_module(const char *name, const char *entrypoint)
{
- const char *builddir = getenv("WESTON_BUILD_DIR");
char path[PATH_MAX];
void *module, *init;
size_t len;
@@ -772,10 +771,8 @@ wet_load_module(const char *name, const char *entrypoint)
return NULL;
if (name[0] != '/') {
- if (builddir)
- len = snprintf(path, sizeof path, "%s/.libs/%s", builddir,
- name);
- else
+ len = weston_module_path_from_env(name, path, sizeof path);
+ if (len == 0)
len = snprintf(path, sizeof path, "%s/%s", MODULEDIR,
name);
} else {
@@ -812,6 +809,24 @@ wet_load_module(const char *name, const char *entrypoint)
return init;
}
+WL_EXPORT char *
+wet_get_binary_path(const char *name)
+{
+ char path[PATH_MAX];
+ size_t len;
+
+ len = weston_module_path_from_env(name, path, sizeof path);
+ if (len > 0)
+ return strdup(path);
+
+ len = snprintf(path, sizeof path, "%s/%s",
+ weston_config_get_libexec_dir(), name);
+ if (len >= sizeof path)
+ return NULL;
+
+ return strdup(path);
+}
+
static int
load_modules(struct weston_compositor *ec, const char *modules,
int *argc, char *argv[])
diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index bf5c45c..be10e5f 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -1031,14 +1031,10 @@ text_backend_configuration(struct text_backend *text_backend)
struct weston_config *config = wet_get_config(text_backend->compositor);
struct weston_config_section *section;
char *client;
- int ret;
section = weston_config_get_section(config,
"input-method", NULL, NULL);
- ret = asprintf(&client, "%s/weston-keyboard",
- weston_config_get_libexec_dir());
- if (ret < 0)
- client = NULL;
+ client = wet_get_binary_path("weston-keyboard");
weston_config_section_get_string(section, "path",
&text_backend->input_method.path,
client);
diff --git a/compositor/weston-screenshooter.c b/compositor/weston-screenshooter.c
index 9999909..01a53e8 100644
--- a/compositor/weston-screenshooter.c
+++ b/compositor/weston-screenshooter.c
@@ -117,12 +117,10 @@ screenshooter_binding(struct weston_keyboard *keyboard, uint32_t time,
{
struct screenshooter *shooter = data;
char *screenshooter_exe;
- int ret;
- ret = asprintf(&screenshooter_exe, "%s/%s",
- weston_config_get_libexec_dir(),
- "/weston-screenshooter");
- if (ret < 0) {
+
+ screenshooter_exe = wet_get_binary_path("weston-screenshooter");
+ if (!screenshooter_exe) {
weston_log("Could not construct screenshooter path.\n");
return;
}
diff --git a/compositor/weston.h b/compositor/weston.h
index bb04002..0a78741 100644
--- a/compositor/weston.h
+++ b/compositor/weston.h
@@ -63,6 +63,9 @@ wet_get_config(struct weston_compositor *compositor);
void *
wet_load_module(const char *name, const char *entrypoint);
+char *
+wet_get_binary_path(const char *name);
+
int
wet_load_xwayland(struct weston_compositor *comp);
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 3913f95..2cfe390 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -446,17 +446,12 @@ shell_configuration(struct desktop_shell *shell)
{
struct weston_config_section *section;
char *s, *client;
- int ret;
int allow_zap;
section = weston_config_get_section(wet_get_config(shell->compositor),
"shell", NULL, NULL);
- ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(),
- WESTON_SHELL_CLIENT);
- if (ret < 0)
- client = NULL;
- weston_config_section_get_string(section,
- "client", &s, client);
+ client = wet_get_binary_path(WESTON_SHELL_CLIENT);
+ weston_config_section_get_string(section, "client", &s, client);
free(client);
shell->client = s;
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 6457858..3207f63 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5219,10 +5219,47 @@ weston_version(int *major, int *minor, int *micro)
*micro = WESTON_VERSION_MICRO;
}
+/**
+ * Attempts to find a module path from the module map specified in the
+ * environment. If found, writes the full path into the path variable.
+ *
+ * @returns The length of the string written to path on success, or 0 if the
+ * module was not specified in the environment map.
+ */
+WL_EXPORT size_t
+weston_module_path_from_env(const char *name, char *path, size_t path_len)
+{
+ const char *mapping = getenv("WESTON_MODULE_MAP");
+
+ while (mapping && *mapping) {
+ const char *filename, *next;
+
+ /* early out: impossibly short string */
+ if (strlen(mapping) < strlen(name) + 1)
+ return 0;
+
+ filename = &mapping[strlen(name) + 1];
+ next = strchr(filename, ';');
+
+ if (strncmp(mapping, name, strlen(name)) == 0 &&
+ mapping[strlen(name)] == '=') {
+ size_t file_len = next - filename; /* no trailing NUL */
+ if (file_len >= path_len)
+ return 0;
+ strncpy(path, filename, file_len);
+ path[file_len] = '\0';
+ return file_len;
+ }
+
+ mapping = next ? (next + 1) : NULL;
+ }
+
+ return 0;
+}
+
WL_EXPORT void *
weston_load_module(const char *name, const char *entrypoint)
{
- const char *builddir = getenv("WESTON_BUILD_DIR");
char path[PATH_MAX];
void *module, *init;
size_t len;
@@ -5231,10 +5268,8 @@ weston_load_module(const char *name, const char *entrypoint)
return NULL;
if (name[0] != '/') {
- if (builddir)
- len = snprintf(path, sizeof path, "%s/.libs/%s",
- builddir, name);
- else
+ len = weston_module_path_from_env(name, path, sizeof path);
+ if (len == 0)
len = snprintf(path, sizeof path, "%s/%s",
LIBWESTON_MODULEDIR, name);
} else {
diff --git a/libweston/compositor.h b/libweston/compositor.h
index ce3d9ab..abee0aa 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1780,6 +1780,9 @@ weston_transformed_region(int width, int height,
void *
weston_load_module(const char *name, const char *entrypoint);
+size_t
+weston_module_path_from_env(const char *name, char *path, size_t path_len);
+
int
weston_parse_transform(const char *transform, uint32_t *out);
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index f6e465b..48be7f4 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -32,6 +32,7 @@
#include <signal.h>
#include <string.h>
#include <assert.h>
+#include <limits.h>
#include "compositor.h"
#include "compositor/weston.h"
@@ -231,7 +232,7 @@ controller_module_init(struct weston_compositor *compositor,
{
struct wl_event_loop *loop;
struct test_launcher *launcher;
- const char *path;
+ char path[PATH_MAX];
/* strict check, since this is an internal test module */
if (iface_version != sizeof(*iface)) {
@@ -239,9 +240,9 @@ controller_module_init(struct weston_compositor *compositor,
return -1;
}
- path = getenv("WESTON_BUILD_DIR");
- if (!path) {
- weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
+ if (weston_module_path_from_env("weston-ivi-layout-test", path,
+ sizeof path) == 0) {
+ weston_log("test setup failure: WESTON_MODULE_MAP not set\n");
return -1;
}
@@ -251,8 +252,7 @@ controller_module_init(struct weston_compositor *compositor,
launcher->compositor = compositor;
launcher->layout_interface = iface;
- snprintf(launcher->exe, sizeof launcher->exe,
- "%s/ivi-layout.ivi", path);
+ snprintf(launcher->exe, sizeof launcher->exe, path);
if (wl_global_create(compositor->wl_display,
&weston_test_runner_interface, 1,
diff --git a/tests/weston-tests-env b/tests/weston-tests-env
index 8a6447e..019e49f 100755
--- a/tests/weston-tests-env
+++ b/tests/weston-tests-env
@@ -26,6 +26,22 @@ SHELL_PLUGIN=$MODDIR/desktop-shell.so
TEST_PLUGIN=$MODDIR/weston-test.so
XWAYLAND_PLUGIN=$MODDIR/xwayland.so
+for mod in cms-colord cms-static desktop-shell drm-backend fbdev-backend \
+ fullscreen-shell gl-renderer headless-backend hmi-controller \
+ ivi-shell rdp-compositor screen-share wayland-backend x11-backend \
+ xwayland; do
+ WESTON_MODULE_MAP="${WESTON_MODULE_MAP}${mod}.so=${abs_builddir}/.libs/${mod}.so;"
+done
+
+for exe in weston-desktop-shell weston-keyboard weston-screenshooter \
+ weston-simple-im; do \
+ WESTON_MODULE_MAP="${WESTON_MODULE_MAP}${exe}=${abs_builddir}/${exe};"
+done
+
+WESTON_MODULE_MAP="${WESTON_MODULE_MAP}weston-ivi-layout-test=${abs_builddir}/ivi-layout.ivi;"
+
+export WESTON_MODULE_MAP
+
CONFIG_FILE="${TEST_NAME}.ini"
if [ -e "${abs_builddir}/${CONFIG_FILE}" ]; then
@@ -41,7 +57,6 @@ case $TEST_FILE in
SHELL_PLUGIN=$MODDIR/ivi-shell.so
set -x
- WESTON_BUILD_DIR=$abs_builddir \
WESTON_TEST_REFERENCE_PATH=$abs_top_srcdir/tests/reference \
$WESTON --backend=$MODDIR/$BACKEND \
--config=$abs_builddir/tests/weston-ivi.ini \
@@ -54,7 +69,6 @@ case $TEST_FILE in
;;
*.la|*.so)
set -x
- WESTON_BUILD_DIR=$abs_builddir \
WESTON_TEST_REFERENCE_PATH=$abs_top_srcdir/tests/reference \
$WESTON --backend=$MODDIR/$BACKEND \
${CONFIG} \
@@ -68,7 +82,6 @@ case $TEST_FILE in
SHELL_PLUGIN=$MODDIR/ivi-shell.so
set -x
- WESTON_BUILD_DIR=$abs_builddir \
WESTON_TEST_REFERENCE_PATH=$abs_top_srcdir/tests/reference \
WESTON_TEST_CLIENT_PATH=$abs_builddir/$TEST_FILE \
$WESTON --backend=$MODDIR/$BACKEND \
@@ -82,7 +95,6 @@ case $TEST_FILE in
;;
*)
set -x
- WESTON_BUILD_DIR=$abs_builddir \
WESTON_TEST_REFERENCE_PATH=$abs_top_srcdir/tests/reference \
WESTON_TEST_CLIENT_PATH=$abs_builddir/$TEST_FILE \
$WESTON --backend=$MODDIR/$BACKEND \
--
2.9.3
More information about the wayland-devel
mailing list