Skip to content
Snippets Groups Projects

Auto-detect path to expectations

Merged Simon McVittie requested to merge wip/smcv/auto-expectations into master
All threads resolved!
@@ -75,7 +75,10 @@ struct _SrtSystemInfo
{
/*< private >*/
GObject parent;
/* "" if we have tried and failed to auto-detect */
gchar *expectations;
/* Fake environment variables, or %NULL to use the real environment */
gchar **env;
Tristate can_write_uinput;
/* (element-type Abi) */
GPtrArray *abis;
@@ -199,6 +202,7 @@ srt_system_info_finalize (GObject *object)
g_clear_pointer (&self->abis, g_ptr_array_unref);
g_free (self->expectations);
g_strfreev (self->env);
G_OBJECT_CLASS (srt_system_info_parent_class)->finalize (object);
}
@@ -347,6 +351,43 @@ library_compare (SrtLibrary *a, SrtLibrary *b)
return g_strcmp0 (srt_library_get_soname (a), srt_library_get_soname (b));
}
static gchar **
get_environ (SrtSystemInfo *self)
{
if (self->env != NULL)
return self->env;
else
return environ;
}
static gboolean
ensure_expectations (SrtSystemInfo *self)
{
if (self->expectations == NULL)
{
const char *runtime;
const char *sysroot = "/";
gchar *def;
runtime = g_environ_getenv (get_environ (self), "STEAM_RUNTIME");
if (runtime != NULL && runtime[0] == '/')
sysroot = runtime;
def = g_build_filename (sysroot, "usr", "lib", "steamrt",
"expectations", NULL);
if (g_file_test (def, G_FILE_TEST_IS_DIR))
self->expectations = g_steal_pointer (&def);
else
self->expectations = g_strdup ("");
g_free (def);
}
return self->expectations[0] != '\0';
}
/**
* srt_system_info_check_libraries:
* @self: The #SrtSystemInfo object to use.
@@ -384,7 +425,7 @@ srt_system_info_check_libraries (SrtSystemInfo *self,
g_return_val_if_fail (libraries_out == NULL || *libraries_out == NULL,
SRT_LIBRARY_ISSUES_INTERNAL_ERROR);
if (self->expectations == NULL)
if (!ensure_expectations (self))
{
/* We don't know which libraries to check. */
return SRT_LIBRARY_ISSUES_UNKNOWN_EXPECTATIONS;
@@ -538,7 +579,7 @@ srt_system_info_check_library (SrtSystemInfo *self,
return srt_library_get_issues (library);
}
if (self->expectations != NULL)
if (ensure_expectations (self))
{
dir_path = g_build_filename (self->expectations, multiarch_tuple, NULL);
dir = g_dir_open (dir_path, 0, &error);
@@ -628,3 +669,43 @@ srt_system_info_check_library (SrtSystemInfo *self,
return ret;
}
/*
* Forget whether we can load libraries.
*/
static void
forget_libraries (SrtSystemInfo *self)
{
gsize i;
for (i = 0; i < self->abis->len; i++)
{
Abi *abi = g_ptr_array_index (self->abis, i);
g_hash_table_remove_all (abi->cached_results);
abi->cached_combined_issues = SRT_LIBRARY_ISSUES_NONE;
abi->libraries_cache_available = FALSE;
}
}
/**
* srt_system_info_set_environ:
* @self: The #SrtSystemInfo
* @env: (nullable) (array zero-terminated=1) (element-type filename) (transfer none): An
* array of environment variables
*
* Use @env instead of the real environment variable block `environ`
* when locating the Steam Runtime.
*
* If @env is %NULL, go back to using the real environment variables.
*/
void
srt_system_info_set_environ (SrtSystemInfo *self,
gchar * const *env)
{
g_return_if_fail (SRT_IS_SYSTEM_INFO (self));
forget_libraries (self);
g_strfreev (self->env);
self->env = g_strdupv ((gchar **) env);
}
Loading