Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • steamrt/steam-runtime-tools
1 result
Show changes
Commits on Source (3)
......@@ -37,6 +37,10 @@ gnome.gtkdoc(
src_dir : ['steam-runtime-tools'],
dependencies : libsteamrt_dep,
install: true,
scan_args : [
'--rebuild-sections',
'--rebuild-types',
],
)
# vim:set sw=2 sts=2 et:
......@@ -14,6 +14,7 @@
<chapter id="ch-sysinfo">
<title>System information</title>
<xi:include href="xml/architecture.xml"/>
<xi:include href="xml/library.xml"/>
</chapter>
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
......
......@@ -45,9 +45,9 @@ main (int argc,
g_print ("{\n");
g_print (" \"can-run\": {\n");
g_print (" \"i386-linux-gnu\": %s,\n",
g_print (" \"%s\": %s,\n", SRT_ABI_I386,
srt_architecture_can_run_i386 () ? "true" : "false");
g_print (" \"x86_64-linux-gnu\": %s\n",
g_print (" \"%s\": %s\n", SRT_ABI_X86_64,
srt_architecture_can_run_x86_64 () ? "true" : "false");
g_print (" }\n");
......
......@@ -84,7 +84,7 @@ out:
/**
* srt_architecture_can_run_i386:
*
* Check whether we can run an i386 executable.
* Check whether we can run an i386 (%SRT_ABI_I386) executable.
*
* For this check to work as intended, the contents of the
* `libsteam-runtime-tools-0-helpers:i386` package must be available
......@@ -107,13 +107,13 @@ out:
gboolean
srt_architecture_can_run_i386 (void)
{
return _srt_architecture_can_run ("i386-linux-gnu");
return _srt_architecture_can_run (SRT_ABI_I386);
}
/**
* srt_architecture_can_run_x86_64:
*
* Check whether we can run an x86_64 executable.
* Check whether we can run an x86_64 (%SRT_ABI_X86_64) executable.
*
* For this check to work as intended, the contents of the
* `libsteam-runtime-tools-0-helpers:amd64` package must be available
......@@ -125,5 +125,5 @@ srt_architecture_can_run_i386 (void)
gboolean
srt_architecture_can_run_x86_64 (void)
{
return _srt_architecture_can_run ("x86_64-linux-gnu");
return _srt_architecture_can_run (SRT_ABI_X86_64);
}
......@@ -31,5 +31,21 @@
#include <glib.h>
/**
* SRT_ABI_I386:
*
* The multiarch tuple for the i386 (IA-32) ABI normally used on
* 32-bit x86 Linux.
*/
#define SRT_ABI_I386 "i386-linux-gnu"
/**
* SRT_ABI_X86_64:
*
* The multiarch tuple for the x86_64 ABI normally used on
* 64-bit x86 Linux.
*/
#define SRT_ABI_X86_64 "x86_64-linux-gnu"
gboolean srt_architecture_can_run_i386 (void);
gboolean srt_architecture_can_run_x86_64 (void);
/*< internal_header >*/
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "steam-runtime-tools/library.h"
/*
* _srt_library_new:
* @multiarch_tuple: A multiarch tuple like %SRT_ABI_I386,
* representing an ABI
* @soname: A SONAME like libz.so.1
* @issues: Problems found when loading a @multiarch_tuple copy
* of @soname
* @missing_symbols: (nullable) (array zero-terminated=1) (element-type utf8):
* Symbols we expected to find in @soname but did not
*
* Inline convenience function to create a new SrtLibrary.
* This is not part of the public API.
*
* Returns: (transfer full): A new #SrtLibrary
*/
static inline SrtLibrary *_srt_library_new (const char *multiarch_tuple,
const char *soname,
SrtLibraryIssues issues,
const char * const *missing_symbols);
#ifndef __GTK_DOC_IGNORE__
static inline SrtLibrary *
_srt_library_new (const char *multiarch_tuple,
const char *soname,
SrtLibraryIssues issues,
const char * const *missing_symbols)
{
g_return_val_if_fail (multiarch_tuple != NULL, NULL);
g_return_val_if_fail (soname != NULL, NULL);
return g_object_new (SRT_TYPE_LIBRARY,
"issues", issues,
"missing-symbols", missing_symbols,
"multiarch-tuple", multiarch_tuple,
"soname", soname,
NULL);
}
#endif
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "steam-runtime-tools/library.h"
#include "steam-runtime-tools/architecture.h"
#include "steam-runtime-tools/enums.h"
/**
* SECTION:library
* @title: Shared libraries
* @short_description: Information about shared libraries
* @include: steam-runtime-tools/steam-runtime-tools.h
*
* #SrtLibrary is an opaque object representing a shared library.
* This is a reference-counted object: use g_object_ref() and
* g_object_unref() to manage its lifecycle.
*/
struct _SrtLibrary
{
/*< private >*/
GObject parent;
gchar *soname;
GStrv missing_symbols;
GQuark multiarch_tuple;
SrtLibraryIssues issues;
};
struct _SrtLibraryClass
{
/*< private >*/
GObjectClass parent_class;
};
enum {
PROP_0,
PROP_ISSUES,
PROP_MISSING_SYMBOLS,
PROP_MULTIARCH_TUPLE,
PROP_SONAME,
N_PROPERTIES
};
G_DEFINE_TYPE (SrtLibrary, srt_library, G_TYPE_OBJECT)
static void
srt_library_init (SrtLibrary *self)
{
}
static void
srt_library_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SrtLibrary *self = SRT_LIBRARY (object);
switch (prop_id)
{
case PROP_ISSUES:
g_value_set_flags (value, self->issues);
break;
case PROP_MISSING_SYMBOLS:
g_value_set_boxed (value, self->missing_symbols);
break;
case PROP_MULTIARCH_TUPLE:
g_value_set_static_string (value, g_quark_to_string (self->multiarch_tuple));
break;
case PROP_SONAME:
g_value_set_string (value, self->soname);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
srt_library_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SrtLibrary *self = SRT_LIBRARY (object);
switch (prop_id)
{
case PROP_ISSUES:
/* Construct-only */
g_return_if_fail (self->issues == 0);
self->issues = g_value_get_flags (value);
break;
case PROP_MISSING_SYMBOLS:
/* Construct-only */
g_return_if_fail (self->missing_symbols == NULL);
self->missing_symbols = g_value_dup_boxed (value);
/* Guarantee non-NULL */
if (self->missing_symbols == NULL)
self->missing_symbols = g_new0 (gchar *, 1);
break;
case PROP_MULTIARCH_TUPLE:
/* Construct-only */
g_return_if_fail (self->multiarch_tuple == 0);
/* Intern the string since we only expect to deal with two values */
self->multiarch_tuple = g_quark_from_string (g_value_get_string (value));
break;
case PROP_SONAME:
/* Construct-only */
g_return_if_fail (self->soname == NULL);
self->soname = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
srt_library_finalize (GObject *object)
{
SrtLibrary *self = SRT_LIBRARY (object);
g_free (self->soname);
g_strfreev (self->missing_symbols);
G_OBJECT_CLASS (srt_library_parent_class)->finalize (object);
}
static GParamSpec *properties[N_PROPERTIES] = { NULL };
static void
srt_library_class_init (SrtLibraryClass *cls)
{
GObjectClass *object_class = G_OBJECT_CLASS (cls);
object_class->get_property = srt_library_get_property;
object_class->set_property = srt_library_set_property;
object_class->finalize = srt_library_finalize;
properties[PROP_ISSUES] =
g_param_spec_flags ("issues", "Issues", "Problems with this library",
SRT_TYPE_LIBRARY_ISSUES, SRT_LIBRARY_ISSUES_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_MISSING_SYMBOLS] =
g_param_spec_boxed ("missing-symbols", "Missing symbols",
"Symbols that were expected to be in this "
"library, but were found to be missing",
G_TYPE_STRV,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_MULTIARCH_TUPLE] =
g_param_spec_string ("multiarch-tuple", "Multiarch tuple",
"Debian-style multiarch tuple representing the "
"ABI of this library, usually " SRT_ABI_I386 " "
"or " SRT_ABI_X86_64,
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_SONAME] =
g_param_spec_string ("soname", "SONAME",
"The name of this library, for example libz.so.1",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
/**
* srt_library_get_soname:
* @self: a library
*
* Return the SONAME (machine-readable runtime name) of @self.
*
* Returns: A string like `libz.so.1`, which is valid as long as @self
* is not destroyed.
*/
const char *
srt_library_get_soname (SrtLibrary *self)
{
g_return_val_if_fail (SRT_IS_LIBRARY (self), NULL);
return self->soname;
}
/**
* srt_library_get_multiarch_tuple:
* @self: a library
*
* Return the multiarch tuple representing the ABI of @self.
*
* Returns: A Debian-style multiarch tuple, usually %SRT_ABI_I386
* or %SRT_ABI_X86_64
*/
const char *
srt_library_get_multiarch_tuple (SrtLibrary *self)
{
g_return_val_if_fail (SRT_IS_LIBRARY (self), NULL);
return g_quark_to_string (self->multiarch_tuple);
}
/**
* srt_library_get_issues:
* @self: a library
*
* Return the problems found when loading @self.
*
* Returns: A bitfield containing problems, or %SRT_LIBRARY_ISSUES_NONE
* if no problems were found
*/
SrtLibraryIssues
srt_library_get_issues (SrtLibrary *self)
{
g_return_val_if_fail (SRT_IS_LIBRARY (self), SRT_LIBRARY_ISSUES_CANNOT_LOAD);
return self->issues;
}
/**
* srt_library_get_missing_symbols:
* @self: a library
*
* Return the symbols that were expected to be provided by @self but
* were not found.
*
* Returns: (array zero-terminated=1) (element-type utf8): The symbols
* that were missing from @self, as a %NULL-terminated array. The
* pointer remains valid until @self is destroyed.
*/
const char * const *
srt_library_get_missing_symbols (SrtLibrary *self)
{
g_return_val_if_fail (SRT_IS_LIBRARY (self), NULL);
return (const char * const *) self->missing_symbols;
}
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#if !defined(_SRT_IN_SINGLE_HEADER) && !defined(_SRT_COMPILATION)
#error "Do not include directly, use <steam-runtime-tools/steam-runtime-tools.h>"
#endif
#include <glib.h>
#include <glib-object.h>
typedef struct _SrtLibrary SrtLibrary;
typedef struct _SrtLibraryClass SrtLibraryClass;
#define SRT_TYPE_LIBRARY srt_library_get_type ()
#define SRT_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SRT_TYPE_LIBRARY, SrtLibrary))
#define SRT_LIBRARY_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST ((cls), SRT_TYPE_LIBRARY, SrtLibraryClass))
#define SRT_IS_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SRT_TYPE_LIBRARY))
#define SRT_IS_LIBRARY_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE ((cls), SRT_TYPE_LIBRARY))
#define SRT_LIBRARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SRT_TYPE_LIBRARY, SrtLibraryClass)
GType srt_library_get_type (void);
/**
* SrtLibraryIssues:
* @SRT_LIBRARY_ISSUES_NONE: There are no problems
* @SRT_LIBRARY_ISSUES_CANNOT_LOAD: The library could not be loaded
* @SRT_LIBRARY_ISSUES_MISSING_SYMBOLS: Some of the expected symbols
* were not present
*
* A bitfield with flags representing problems with a library, or
* %SRT_LIBRARY_ISSUES_NONE (which is numerically zero) if no problems
* were detected.
*
* In general, more bits set means more problems.
*/
typedef enum
{
SRT_LIBRARY_ISSUES_CANNOT_LOAD = (1 << 0),
SRT_LIBRARY_ISSUES_MISSING_SYMBOLS = (1 << 1),
SRT_LIBRARY_ISSUES_NONE = 0
} SrtLibraryIssues;
const char *srt_library_get_soname (SrtLibrary *self);
const char *srt_library_get_multiarch_tuple (SrtLibrary *self);
SrtLibraryIssues srt_library_get_issues (SrtLibrary *self);
const char * const *srt_library_get_missing_symbols (SrtLibrary *self);
......@@ -25,15 +25,25 @@ libdl = c_compiler.find_library('dl', required : false)
libsteamrt_sources = [
'architecture.c',
'library-internal.h',
'library.c',
'utils-internal.h',
'utils.c',
]
libsteamrt_public_headers = [
'architecture.h',
'library.h',
'steam-runtime-tools.h',
]
enums = gnome.mkenums_simple(
'enums',
install_dir : join_paths('steam-runtime-tools-' + api_major, 'steam-runtime-tools'),
install_header : true,
sources : libsteamrt_public_headers,
)
install_headers(
libsteamrt_public_headers,
subdir : join_paths('steam-runtime-tools-' + api_major, 'steam-runtime-tools'),
......@@ -41,7 +51,7 @@ install_headers(
libsteamrt = library(
'steam-runtime-tools-' + api_major,
libsteamrt_sources + libsteamrt_public_headers,
libsteamrt_sources + libsteamrt_public_headers + enums,
c_args : [
'-DG_LOG_DOMAIN="' + meson.project_name() + '"',
'-D_SRT_COMPILATION',
......
......@@ -28,5 +28,6 @@
#define _SRT_IN_SINGLE_HEADER
#include <steam-runtime-tools/architecture.h>
#include <steam-runtime-tools/library.h>
#undef _SRT_IN_SINGLE_HEADER
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <steam-runtime-tools/steam-runtime-tools.h>
#include <glib.h>
#include "steam-runtime-tools/library-internal.h"
#include "test-utils.h"
typedef struct
{
int unused;
} Fixture;
typedef struct
{
int unused;
} Config;
static void
setup (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
}
static void
teardown (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
}
/*
* Test basic functionality of the SrtLibrary object.
*/
static void
test_object (Fixture *f,
gconstpointer context)
{
SrtLibrary *library;
const char * const *missing;
SrtLibraryIssues issues;
gchar *tuple;
gchar *soname;
GStrv missing_mutable;
const char * const one_missing[] = { "jpeg_mem_src@LIBJPEGTURBO_6.2", NULL };
library = _srt_library_new ("arm-linux-gnueabihf",
"libz.so.1",
SRT_LIBRARY_ISSUES_NONE,
NULL);
g_assert_cmpint (srt_library_get_issues (library), ==,
SRT_LIBRARY_ISSUES_NONE);
g_assert_cmpstr (srt_library_get_multiarch_tuple (library), ==,
"arm-linux-gnueabihf");
g_assert_cmpstr (srt_library_get_soname (library), ==,
"libz.so.1");
missing = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing);
g_assert_cmpstr (missing[0], ==, NULL);
g_object_get (library,
"multiarch-tuple", &tuple,
"soname", &soname,
"missing-symbols", &missing_mutable,
"issues", &issues,
NULL);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
g_assert_cmpstr (tuple, ==, "arm-linux-gnueabihf");
g_assert_cmpstr (soname, ==, "libz.so.1");
g_assert_nonnull (missing_mutable);
g_assert_cmpstr (missing_mutable[0], ==, NULL);
g_free (tuple);
g_free (soname);
g_strfreev (missing_mutable);
g_object_unref (library);
library = _srt_library_new ("s390x-linux-gnu",
"libjpeg.so.62",
SRT_LIBRARY_ISSUES_MISSING_SYMBOLS,
one_missing);
g_assert_cmpint (srt_library_get_issues (library), ==,
SRT_LIBRARY_ISSUES_MISSING_SYMBOLS);
g_assert_cmpstr (srt_library_get_multiarch_tuple (library), ==,
"s390x-linux-gnu");
g_assert_cmpstr (srt_library_get_soname (library), ==,
"libjpeg.so.62");
missing = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing);
g_assert_cmpstr (missing[0], ==, one_missing[0]);
g_assert_cmpstr (missing[1], ==, NULL);
g_object_get (library,
"multiarch-tuple", &tuple,
"soname", &soname,
"missing-symbols", &missing_mutable,
"issues", &issues,
NULL);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_MISSING_SYMBOLS);
g_assert_cmpstr (tuple, ==, "s390x-linux-gnu");
g_assert_cmpstr (soname, ==, "libjpeg.so.62");
g_assert_nonnull (missing_mutable);
g_assert_cmpstr (missing_mutable[0], ==, one_missing[0]);
g_assert_cmpstr (missing_mutable[1], ==, NULL);
g_free (tuple);
g_free (soname);
g_strfreev (missing_mutable);
g_object_unref (library);
}
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add ("/object", Fixture, NULL,
setup, test_object, teardown);
return g_test_run ();
}
......@@ -28,6 +28,7 @@ test_env.set('SRT_HELPERS_PATH', join_paths(meson.current_build_dir(), '..', 'he
tests = [
'architecture',
'library',
]
tests_dir = join_paths(
......@@ -45,7 +46,7 @@ foreach test_name : tests
exe = executable(
'test-' + test_name,
files(test_name + '.c'),
dependencies : [glib, libsteamrt_dep],
dependencies : [glib, gobject, libsteamrt_dep],
install : get_option('installed_tests'),
install_dir : tests_dir,
)
......