[gnome-boxes/flatpak-gnome-3-28: 4/5] build: Don't build with ovirt and gudev support in a flatpak



commit 81d5bf8764029dcd7107bf99f30daaac3782c231
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed May 16 17:57:07 2018 +0200

    build: Don't build with ovirt and gudev support in a flatpak
    
    Whenever Boxes is built with -Dflatpak=true

 meson_options.txt        |  5 +++++
 src/downloader.vala      |  3 ++-
 src/installer-media.vala | 17 ++++++++++++++---
 src/media-manager.vala   |  9 +++++++--
 src/meson.build          | 27 +++++++++++++++++----------
 src/vm-configurator.vala |  2 ++
 6 files changed, 47 insertions(+), 16 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index 3030bd11..773f10ee 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -16,3 +16,8 @@ option ('installed_tests',
         type: 'boolean',
         value: false,
         description: 'enable installed unit tests')
+
+option ('flatpak',
+        type: 'boolean',
+        value: false,
+        description: 'Whether Boxes is going to run in a Flatpak')
diff --git a/src/downloader.vala b/src/downloader.vala
index 2f8137eb..aeb90c0f 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -126,10 +126,11 @@ private async void download_from_http (Download download, Cancellable? cancellab
         msg.response_body.set_accumulate (false);
         var address = msg.get_address ();
         var connectable = new NetworkAddress (address.name, (uint16) address.port);
+#if !FLATPAK
         var network_monitor = NetworkMonitor.get_default ();
         if (!(yield network_monitor.can_reach_async (connectable)))
             throw new Boxes.Error.INVALID ("Failed to reach host '%s' on port '%d'", address.name, 
address.port);
-
+#endif
         GLib.Error? err = null;
         ulong cancelled_id = 0;
         if (cancellable != null)
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 43a29127..feb5d7be 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -1,7 +1,6 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 
 using Osinfo;
-using GUdev;
 using GVirConfig;
 
 private class Boxes.InstallerMedia : GLib.Object {
@@ -64,16 +63,21 @@
     public async InstallerMedia.for_path (string       path,
                                           MediaManager media_manager,
                                           Cancellable? cancellable) throws GLib.Error {
-        var device = yield get_device_from_path (path, media_manager.client, cancellable);
+        var device_file = yield get_device_file_from_path (path, cancellable);
+#if !FLATPAK
+        var device = yield get_device_from_device_file (device_file, media_manager.client);
 
         if (device != null)
             yield get_media_info_from_device (device, media_manager.os_db);
         else {
+#endif
             from_image = true;
             os_media = yield media_manager.os_db.guess_os_from_install_media_path (device_file, cancellable);
             if (os_media != null)
                 os = os_media.os;
+#if !FLATPAK
         }
+#endif
 
         label_setup ();
 
@@ -172,7 +176,7 @@ else if (os != null && os_media != null) {
         }
     }
 
-    private async GUdev.Device? get_device_from_path (string path, Client client, Cancellable? cancellable) {
+    private async string get_device_file_from_path (string path, Cancellable? cancellable) {
         try {
             var mount_dir = File.new_for_path (path);
             var mount = yield mount_dir.find_enclosing_mount_async (Priority.DEFAULT, cancellable);
@@ -189,6 +193,11 @@ else if (os != null && os_media != null) {
             device_file = path;
         }
 
+        return device_file;
+    }
+
+#if !FLATPAK
+    private async GUdev.Device? get_device_from_device_file (string device_file, GUdev.Client client) {
         return client.query_by_device_file (device_file);
     }
 
@@ -211,6 +220,7 @@ private async void get_media_info_from_device (GUdev.Device device, OSDatabase o
         } else {
             var media = new Osinfo.Media (device_file, ARCHITECTURE_ALL);
             media.volume_id = label;
+
             get_decoded_udev_properties_for_media
                                 (device,
                                  { "ID_FS_SYSTEM_ID", "ID_FS_PUBLISHER_ID", "ID_FS_APPLICATION_ID", },
@@ -254,6 +264,7 @@ private void get_decoded_udev_properties_for_media (GUdev.Device device,
 
         return decoded;
     }
+#endif
 
     private void eject_cdrom_media (Domain domain) {
         var devices = domain.get_devices ();
diff --git a/src/media-manager.vala b/src/media-manager.vala
index c02a8700..427ce874 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -1,14 +1,15 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 
 using Osinfo;
-using GUdev;
 using Tracker;
 
 private class Boxes.MediaManager : Object {
     private static MediaManager media_manager;
 
     public OSDatabase os_db { get; private set; }
-    public Client client { get; private set; }
+#if !FLATPAK
+    public GUdev.Client client { get; private set; }
+#endif
 
     public delegate void InstallerRecognized (Osinfo.Media os_media, Osinfo.Os os);
 
@@ -88,6 +89,7 @@ else if (VMConfigurator.is_libvirt_cloning_config (config))
     public async GLib.List<InstallerMedia> list_installer_medias () {
         var list = new GLib.List<InstallerMedia> ();
 
+#if !FLATPAK
         // First HW media
         var enumerator = new GUdev.Enumerator (client);
         // We don't want to deal with partitions to avoid duplicate medias
@@ -117,6 +119,7 @@ else if (VMConfigurator.is_libvirt_cloning_config (config))
                 warning ("Failed to get information on device '%s': %s. Ignoring..", path, error.message);
             }
         }
+#endif
 
         if (connection == null)
             return list;
@@ -181,7 +184,9 @@ public InstallerMedia create_installer_media_from_media (InstallerMedia media) t
     }
 
     private MediaManager () {
+#if !FLATPAK
         client = new GUdev.Client ({"block"});
+#endif
         os_db = new OSDatabase ();
         os_db.load.begin ();
         try {
diff --git a/src/meson.build b/src/meson.build
index 518fc02d..ac79b7fc 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -121,7 +121,6 @@ dependencies = [
   dependency ('gobject-2.0', version: '>= 2.44'),
   dependency ('gtk+-3.0', version: '>= 3.22.20'),
   dependency ('gtk-vnc-2.0', version: '>= 0.4.4'),
-  dependency ('gudev-1.0', version: '>= 165'),
   dependency ('libosinfo-1.0', version: '>= 1.1.0'),
   dependency ('libsecret-1'),
   dependency ('libsoup-2.4', version: '>= 2.38'),
@@ -138,18 +137,26 @@ dependencies = [
   valac.find_library ('spice-client-gtk-3.0'),
 ]
 
-if get_option('ovirt')
-  vala_sources += [
-    'ovirt-broker.vala',
-    'ovirt-machine.vala'
+if get_option('flatpak')
+  vala_args += '--define=FLATPAK'
+else
+  dependencies += [
+    dependency ('gudev-1.0', version: '>= 165'),
   ]
 
-  vala_args += '--define=HAVE_OVIRT'
+  if get_option('ovirt')
+    vala_sources += [
+      'ovirt-broker.vala',
+      'ovirt-machine.vala'
+    ]
 
-  dependencies += [
-    dependency ('govirt-1.0', version: '>= 0.3.4'),
-    valac.find_library ('rest-0.7')
-  ]
+    vala_args += '--define=HAVE_OVIRT'
+
+    dependencies += [
+      dependency ('govirt-1.0', version: '>= 0.3.4'),
+      valac.find_library ('rest-0.7')
+    ]
+  endif
 endif
 
 executable ('gnome-boxes', vala_sources + resources,
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index f75e5e7f..e8eefa33 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -91,7 +91,9 @@ public static Domain create_domain_config (InstallerMedia install_media, string
         domain.add_device (webdav_channel);
 
         add_usb_support (domain);
+#if !FLATPAK
         add_smartcard_support (domain);
+#endif
 
         set_video_config (domain, install_media);
         set_sound_config (domain, install_media);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]