summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJehan <jehan@girinstud.io>2019-01-07 14:35:21 +0100
committerRichard Hughes <richard@hughsie.com>2019-02-08 19:09:36 +0000
commit58b6e2475abfc7d8bcbe15ddb88896b9acd3d5e8 (patch)
treef9d128d4a99eac35c96433ab17d18f32b636fd5e
parente15a71feaefaf1aa1970f9e87672c29c48ed2a0e (diff)
downloadappstream-glib-wip/hughsie/win32.tar.gz
Allow building on Windowswip/hughsie/win32
Signed-off-by: Richard Hughes <richard@hughsie.com>
-rw-r--r--client/as-util.c9
-rw-r--r--libappstream-glib/as-app-builder.c1
-rw-r--r--libappstream-glib/as-app-desktop.c11
-rw-r--r--libappstream-glib/as-app-inf.c1
-rw-r--r--libappstream-glib/as-app-validate.c1
-rw-r--r--libappstream-glib/as-app.c14
-rw-r--r--libappstream-glib/as-format.c6
-rw-r--r--libappstream-glib/as-node.c23
-rw-r--r--libappstream-glib/as-require.c10
-rw-r--r--libappstream-glib/as-self-test.c41
-rw-r--r--libappstream-glib/as-utils.c19
-rw-r--r--libappstream-glib/meson.build21
-rw-r--r--meson.build19
13 files changed, 140 insertions, 36 deletions
diff --git a/client/as-util.c b/client/as-util.c
index f2f337e..72e8066 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -23,9 +23,12 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <glib-unix.h>
#include <gio/gio.h>
+#ifndef _WIN32
+#include <glib-unix.h>
+#endif
+
#include <appstream-glib.h>
#include <archive_entry.h>
#include <archive.h>
@@ -4282,6 +4285,7 @@ as_util_watch_cancelled_cb (GCancellable *cancellable, gpointer user_data)
g_main_loop_quit (priv->loop);
}
+#ifndef _WIN32
static gboolean
as_util_sigint_cb (gpointer user_data)
{
@@ -4290,6 +4294,7 @@ as_util_sigint_cb (gpointer user_data)
g_cancellable_cancel (priv->cancellable);
return FALSE;
}
+#endif
static gboolean
as_util_regex (AsUtilPrivate *priv, gchar **values, GError **error)
@@ -4355,11 +4360,13 @@ main (int argc, char *argv[])
/* do stuff on ctrl+c */
priv->loop = g_main_loop_new (NULL, FALSE);
priv->cancellable = g_cancellable_new ();
+#ifndef _WIN32
g_unix_signal_add_full (G_PRIORITY_DEFAULT,
SIGINT,
as_util_sigint_cb,
priv,
NULL);
+#endif
g_signal_connect (priv->cancellable, "cancelled",
G_CALLBACK (as_util_watch_cancelled_cb), priv);
diff --git a/libappstream-glib/as-app-builder.c b/libappstream-glib/as-app-builder.c
index 046bb6a..4ee3672 100644
--- a/libappstream-glib/as-app-builder.c
+++ b/libappstream-glib/as-app-builder.c
@@ -33,7 +33,6 @@
#include "config.h"
-#include <fnmatch.h>
#include <string.h>
#include "as-app-builder.h"
diff --git a/libappstream-glib/as-app-desktop.c b/libappstream-glib/as-app-desktop.c
index c2d6555..1199dcd 100644
--- a/libappstream-glib/as-app-desktop.c
+++ b/libappstream-glib/as-app-desktop.c
@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <fnmatch.h>
#include <string.h>
#include "as-app-private.h"
@@ -116,11 +115,11 @@ as_app_parse_file_metadata (AsApp *app, GKeyFile *kf, const gchar *key)
guint i;
g_autofree gchar *value = NULL;
const gchar *blacklist[] = {
- "X-AppInstall-*",
+ "X-AppInstall-",
"X-Desktop-File-Install-Version",
- "X-Geoclue-Reason*",
- "X-GNOME-Bugzilla-*",
- "X-GNOME-FullName*",
+ "X-Geoclue-Reason",
+ "X-GNOME-Bugzilla-",
+ "X-GNOME-FullName",
"X-GNOME-Gettext-Domain",
"X-GNOME-UsesNotifications",
NULL };
@@ -130,7 +129,7 @@ as_app_parse_file_metadata (AsApp *app, GKeyFile *kf, const gchar *key)
/* anything blacklisted */
for (i = 0; blacklist[i] != NULL; i++) {
- if (fnmatch (blacklist[i], key, 0) == 0)
+ if (g_str_has_prefix (blacklist[i], key))
return;
}
value = g_key_file_get_string (kf,
diff --git a/libappstream-glib/as-app-inf.c b/libappstream-glib/as-app-inf.c
index 61441d8..060f1c6 100644
--- a/libappstream-glib/as-app-inf.c
+++ b/libappstream-glib/as-app-inf.c
@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <fnmatch.h>
#include <string.h>
#include "as-app-private.h"
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index a9ad2ca..dd39262 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -21,7 +21,6 @@
#include "config.h"
-#include <fnmatch.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libsoup/soup.h>
#include <libsoup/soup-status.h>
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 5604c5d..f4fa59b 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -35,7 +35,6 @@
#include "config.h"
#include <string.h>
-#include <fnmatch.h>
#include "as-app-private.h"
#include "as-bundle-private.h"
@@ -58,6 +57,10 @@
#include "as-utils-private.h"
#include "as-yaml.h"
+#ifndef _WIN32
+#include <fnmatch.h>
+#endif
+
typedef struct
{
AsAppProblems problems;
@@ -6177,8 +6180,8 @@ as_app_parse_appdata_unintltoolize_cb (GNode *node, gpointer data)
static void
as_app_parse_appdata_guess_project_group (AsApp *app)
{
+#ifndef _WIN32
const gchar *tmp;
- guint i;
struct {
const gchar *project_group;
const gchar *url_glob;
@@ -6201,7 +6204,7 @@ as_app_parse_appdata_guess_project_group (AsApp *app)
tmp = as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE);
if (tmp == NULL)
return;
- for (i = 0; table[i].project_group != NULL; i++) {
+ for (guint i = 0; table[i].project_group != NULL; i++) {
if (fnmatch (table[i].url_glob, tmp, 0) == 0) {
as_app_set_project_group (app, table[i].project_group);
return;
@@ -6214,16 +6217,21 @@ as_app_parse_appdata_guess_project_group (AsApp *app)
as_app_set_project_group (AS_APP (app), "KDE");
return;
}
+#endif
}
static int
as_utils_fnmatch (const gchar *pattern, const gchar *text, gsize text_sz, gint flags)
{
+#ifndef _WIN32
if (text_sz != -1 && text[text_sz-1] != '\0') {
g_autofree gchar *text_with_nul = g_strndup (text, text_sz);
return fnmatch (pattern, text_with_nul, flags);
}
return fnmatch (pattern, text, flags);
+#else
+ return 1;
+#endif
}
/**
diff --git a/libappstream-glib/as-format.c b/libappstream-glib/as-format.c
index 96919e6..2e4835d 100644
--- a/libappstream-glib/as-format.c
+++ b/libappstream-glib/as-format.c
@@ -202,11 +202,15 @@ as_format_guess_kind (const gchar *filename)
void
as_format_set_filename (AsFormat *format, const gchar *filename)
{
+ gchar *canon_filename;
+
AsFormatPrivate *priv = GET_PRIVATE (format);
g_return_if_fail (AS_IS_FORMAT (format));
if (priv->kind == AS_FORMAT_KIND_UNKNOWN)
priv->kind = as_format_guess_kind (filename);
- as_ref_string_assign_safe (&priv->filename, filename);
+ canon_filename = g_canonicalize_filename (filename, NULL);
+ as_ref_string_assign_safe (&priv->filename, canon_filename);
+ g_free (canon_filename);
}
/**
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index f0d13fc..d20e7cf 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -949,6 +949,7 @@ as_node_from_file (GFile *file,
gsize chunk_size = 32 * 1024;
gssize len;
g_autofree gchar *data = NULL;
+ g_autofree gchar *mime_type = NULL;
g_autoptr(GMarkupParseContext) ctx = NULL;
g_autoptr(GConverter) conv = NULL;
g_autoptr(GFileInfo) info = NULL;
@@ -975,18 +976,22 @@ as_node_from_file (GFile *file,
if (file_stream == NULL)
return NULL;
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
- if (g_strcmp0 (content_type, "application/gzip") == 0 ||
- g_strcmp0 (content_type, "application/x-gzip") == 0) {
- conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
- stream_data = g_converter_input_stream_new (file_stream, conv);
- } else if (g_strcmp0 (content_type, "application/xml") == 0) {
- stream_data = g_object_ref (file_stream);
- } else {
+ mime_type = g_content_type_get_mime_type (content_type);
+ if (mime_type != NULL) {
+ if (g_strcmp0 (mime_type, "application/gzip") == 0 ||
+ g_strcmp0 (mime_type, "application/x-gzip") == 0) {
+ conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
+ stream_data = g_converter_input_stream_new (file_stream, conv);
+ } else if (g_strcmp0 (mime_type, "application/xml") == 0 ||
+ g_strcmp0 (mime_type, "text/xml") == 0) {
+ stream_data = g_object_ref (file_stream);
+ }
+ }
+ if (stream_data == NULL) {
g_set_error (error,
AS_NODE_ERROR,
AS_NODE_ERROR_FAILED,
- "cannot process file of type %s",
- content_type);
+ "cannot process file of type %s", content_type);
return NULL;
}
diff --git a/libappstream-glib/as-require.c b/libappstream-glib/as-require.c
index 11a1dc3..1494fc8 100644
--- a/libappstream-glib/as-require.c
+++ b/libappstream-glib/as-require.c
@@ -32,13 +32,15 @@
#include "config.h"
-#include <fnmatch.h>
-
#include "as-require-private.h"
#include "as-node-private.h"
#include "as-ref-string.h"
#include "as-utils-private.h"
+#ifndef _WIN32
+#include <fnmatch.h>
+#endif
+
typedef struct
{
AsRequireKind kind;
@@ -393,7 +395,11 @@ as_require_version_compare (AsRequire *require,
ret = rc >= 0;
break;
case AS_REQUIRE_COMPARE_GLOB:
+#ifdef _WIN32
+ ret = g_strcmp0 (priv->version, version) == 0;
+#else
ret = fnmatch (priv->version, version, 0) == 0;
+#endif
break;
case AS_REQUIRE_COMPARE_REGEX:
ret = g_regex_match_simple (priv->version, version, 0, 0);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index f9facaa..5a83b13 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -25,7 +25,6 @@
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
-#include <fnmatch.h>
#include "as-agreement-private.h"
#include "as-app-private.h"
@@ -54,6 +53,12 @@
#include "as-utils-private.h"
#include "as-yaml.h"
+#ifndef _WIN32
+#include <fnmatch.h>
+#else
+#include <windef.h>
+#endif
+
#define AS_TEST_WILDCARD_SHA1 "\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?"
static gboolean
@@ -66,8 +71,13 @@ as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
return TRUE;
/* matches a pattern */
+#ifdef _WIN32
+ if (g_strcmp0 (txt2, txt1) == 0)
+ return TRUE;
+#else
if (fnmatch (txt2, txt1, FNM_NOESCAPE) == 0)
return TRUE;
+#endif
/* save temp files and diff them */
if (!g_file_set_contents ("/tmp/a", txt1, -1, error))
@@ -94,7 +104,21 @@ as_test_get_filename (const gchar *filename)
g_free (path);
path = g_build_filename (TESTDIRBUILD, filename, NULL);
}
+#ifdef _WIN32
+ {
+ DWORD retval;
+ TCHAR full_path[PATH_MAX];
+
+ retval = GetFullPathNameA (path, PATH_MAX, full_path, NULL);
+
+ if (retval > 0)
+ return g_strdup (full_path);
+ else
+ return NULL;
+ }
+#else
return realpath (path, NULL);
+#endif
}
static GMainLoop *_test_loop = NULL;
@@ -2371,14 +2395,24 @@ as_test_store_local_appdata_func (void)
gboolean ret;
g_autofree gchar *filename = NULL;
g_autofree gchar *filename_full = NULL;
+ g_autofree gchar *canonical_filename;
g_autoptr(AsStore) store = NULL;
/* this are the warnings expected */
+#ifdef _WIN32
+ g_test_expect_message (G_LOG_DOMAIN,
+ G_LOG_LEVEL_WARNING,
+ "ignoring description '*' from *\\broken.appdata.xml: Unknown tag '_p'");
+#else
g_test_expect_message (G_LOG_DOMAIN,
G_LOG_LEVEL_WARNING,
"ignoring description '*' from */broken.appdata.xml: Unknown tag '_p'");
+#endif
/* open test store */
+#ifdef _WIN32
+ g_setenv ("XDG_DATA_DIRS", "/usr/share/", TRUE);
+#endif
store = as_store_new ();
filename = as_test_get_filename (".");
as_store_set_destdir (store, filename);
@@ -2398,7 +2432,8 @@ as_test_store_local_appdata_func (void)
filename_full = g_build_filename (filename,
"usr/share/appdata/broken.appdata.xml",
NULL);
- g_assert_cmpstr (as_format_get_filename (format), ==, filename_full);
+ canonical_filename = g_canonicalize_filename (filename_full, NULL);
+ g_assert_cmpstr (as_format_get_filename (format), ==, canonical_filename);
}
static void
@@ -4315,6 +4350,7 @@ as_test_utils_appstream_id_func (void)
static void
as_test_utils_guid_func (void)
{
+#ifndef _WIN32
g_autofree gchar *guid1 = NULL;
g_autofree gchar *guid2 = NULL;
@@ -4333,6 +4369,7 @@ as_test_utils_guid_func (void)
g_assert_cmpstr (guid1, ==, "886313e1-3b8a-5372-9b90-0c9aee199e5d");
guid2 = as_utils_guid_from_string ("8086:0406");
g_assert_cmpstr (guid2, ==, "1fbd1f2c-80f4-5d7c-a6ad-35c7b9bd5486");
+#endif
}
static void
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index 6f46e52..9c2ae73 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -32,13 +32,14 @@
#include "config.h"
-#include <fnmatch.h>
#include <string.h>
#include <archive_entry.h>
#include <archive.h>
#include <libsoup/soup.h>
#include <stdlib.h>
+#ifndef _WIN32
#include <uuid.h>
+#endif
#ifdef HAVE_RPM
#include <rpm/rpmlib.h>
@@ -1540,6 +1541,13 @@ as_utils_guid_from_data (const gchar *namespace_id,
gsize data_len,
GError **error)
{
+#ifdef _WIN32
+ g_set_error_literal (error,
+ AS_UTILS_ERROR,
+ AS_UTILS_ERROR_FAILED,
+ "not supported");
+ return FALSE;
+#else
gchar guid_new[37]; /* 36 plus NUL */
gsize digestlen = 20;
guint8 hash[20];
@@ -1579,6 +1587,7 @@ as_utils_guid_from_data (const gchar *namespace_id,
/* return as a string */
uuid_unparse (uu_new, guid_new);
return g_strdup (guid_new);
+#endif
}
/**
@@ -1594,12 +1603,20 @@ as_utils_guid_from_data (const gchar *namespace_id,
gboolean
as_utils_guid_is_valid (const gchar *guid)
{
+#ifdef _WIN32
+ /* XXX Ideally we should set a GError but this was already a public
+ * API, and it doesn't have such parameter.
+ */
+ g_printerr ("%s: not supported\n", G_STRFUNC);
+ return FALSE;
+#else
gint rc;
uuid_t uu;
if (guid == NULL)
return FALSE;
rc = uuid_parse (guid, uu);
return rc == 0;
+#endif
}
/**
diff --git a/libappstream-glib/meson.build b/libappstream-glib/meson.build
index 5f726b0..271c6da 100644
--- a/libappstream-glib/meson.build
+++ b/libappstream-glib/meson.build
@@ -6,13 +6,17 @@ cargs = [
deps = [
gdkpixbuf,
- giounix,
glib,
libarchive,
soup,
- uuid,
]
+if platform_win32
+ deps += [giowindows]
+else
+ deps += [giounix, uuid]
+endif
+
if get_option('dep11')
deps += yaml
endif
@@ -142,6 +146,14 @@ asglib = shared_library(
)
asglib_incdir = include_directories('.')
+pkg_req_private = [
+ 'libarchive'
+]
+
+if not platform_win32
+ pkg_req_private += ['uuid']
+endif
+
pkgg.generate(
version : as_version,
libraries : asglib,
@@ -150,10 +162,7 @@ pkgg.generate(
'gobject-2.0',
'gdk-pixbuf-2.0',
],
- requires_private : [
- 'libarchive',
- 'uuid',
- ],
+ requires_private : pkg_req_private,
name : 'appstream-glib',
description : 'Objects and helper methods to help reading and writing AppStream metadata',
filebase : 'appstream-glib',
diff --git a/meson.build b/meson.build
index a8649d5..75a7834 100644
--- a/meson.build
+++ b/meson.build
@@ -11,6 +11,17 @@ as_major_version = varr[0]
as_minor_version = varr[1]
as_micro_version = varr[2]
+# Check the right platform.
+
+platform_win32 = false
+
+host_os = host_machine.system()
+
+platform_win32 = (host_os.startswith('mingw') or
+ host_os.startswith('cygwin') or
+ host_os.startswith('windows'))
+
+
conf = configuration_data()
conf.set('AS_MAJOR_VERSION_CONF', as_major_version)
conf.set('AS_MINOR_VERSION_CONF', as_minor_version)
@@ -49,10 +60,14 @@ plugindir = join_paths(get_option('prefix'),
'asb-plugins-' + as_plugin_version)
glib_ver = '>= 2.45.8'
-uuid = dependency('uuid')
glib = dependency('glib-2.0', version : glib_ver)
gmodule = dependency('gmodule-2.0', version : glib_ver)
-giounix = dependency('gio-unix-2.0', version : glib_ver)
+if platform_win32
+ giowindows = dependency('gio-windows-2.0', version : glib_ver)
+else
+ giounix = dependency('gio-unix-2.0', version : glib_ver)
+ uuid = dependency('uuid')
+endif
libarchive = dependency('libarchive')
soup = dependency('libsoup-2.4', version : '>= 2.51.92')
json_glib = dependency('json-glib-1.0', version : '>= 1.1.2')