[PATCH] Set icon for QEMU binary on Mac OS

Programmingkid posted 1 patch 4 years, 7 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/325BA2AF-B4F5-4134-BF90-63282E0B2A46@gmail.com
There is a newer version of this series
meson.build | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
[PATCH] Set icon for QEMU binary on Mac OS
Posted by Programmingkid 4 years, 7 months ago
Hi Paolo, I was told you were the one who I should send this patch to. Please let me know if you feel otherwise.


Before switching the build system over to Meson, an icon was
added to the QEMU binary on Mac OS. This patch adds back that
feature.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
 meson.build | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/meson.build b/meson.build
index f00b7754fd..7f534f4e75 100644
--- a/meson.build
+++ b/meson.build
@@ -2183,6 +2183,26 @@ foreach target : target_dirs
                link_args: link_args,
                gui_app: exe['gui'])
 
+# set QEMU's icon on Mac OS
+if targetos == 'darwin'
+    newiconpart1 = custom_target('Icon for ' + exe_name + ' - part 1',
+          depends : emulator,
+          input : emulator,
+          output : 'new icon for ' + exe_name + ' - 1',
+          command : ['Rez', '-append',
+           meson.source_root() + '/pc-bios/qemu.rsrc', '-o',
+           meson.current_build_dir() / exe['name']],
+          build_by_default : true)
+
+    custom_target('Icon for ' + exe_name + ' - part 2',
+          depends : newiconpart1,
+          input : emulator,
+          output : 'new icon for ' + exe_name + ' - 2',
+          command : ['SetFile', '-a', 'C',
+           meson.current_build_dir() / exe['name']],
+          build_by_default : true)
+endif
+
     if exe_sign
       emulators += {exe['name'] : custom_target(exe['name'],
                    install: true,
-- 
2.24.3 (Apple Git-128)



Re: [PATCH] Set icon for QEMU binary on Mac OS
Posted by Paolo Bonzini 4 years, 7 months ago
On 05/07/21 15:54, Programmingkid wrote:
> Hi Paolo, I was told you were the one who I should send this patch to. Please let me know if you feel otherwise.

Absolutely, thanks.  Removing the icon was mostly done out of lack of
a machine to test it on, and it's nice to add it back.

> +# set QEMU's icon on Mac OS
> +if targetos == 'darwin'
> +    newiconpart1 = custom_target('Icon for ' + exe_name + ' - part 1',
> +          depends : emulator,
> +          input : emulator,
> +          output : 'new icon for ' + exe_name + ' - 1',
> +          command : ['Rez', '-append',
> +           meson.source_root() + '/pc-bios/qemu.rsrc', '-o',
> +           meson.current_build_dir() / exe['name']],
> +          build_by_default : true)

I think having a command that never actually creates the "new icon for
... - 1" file will cause the command to be run over and over.

We already have scripts/entitlement.sh to do (possibly) in-place changes
to the executable on Darwin.  I suggest something like this:

diff --git a/meson.build b/meson.build
index 380b40ba07..5313cf4a32 100644
--- a/meson.build
+++ b/meson.build
@@ -2505,8 +2505,7 @@ foreach target : target_dirs
    endif
    foreach exe: execs
      exe_name = exe['name']
-    exe_sign = 'CONFIG_HVF' in config_target
-    if exe_sign
+    if targetos == 'darwin'
        exe_name += '-unsigned'
      endif
  
@@ -2520,7 +2519,13 @@ foreach target : target_dirs
                 link_args: link_args,
                 win_subsystem: exe['win_subsystem'])
  
-    if exe_sign
+    if 'CONFIG_HVF' in config_target
+      entitlement = meson.current_source_dir() / 'accel/hvf/entitlements.plist'
+    else
+      entitlement = '/dev/null'
+    endif
+    if targetos == 'darwin'
+      icon = '...'
        emulators += {exe['name'] : custom_target(exe['name'],
                     depends: emulator,
                     output: exe['name'],
@@ -2528,14 +2534,14 @@ foreach target : target_dirs
                       meson.current_source_dir() / 'scripts/entitlement.sh',
                       meson.current_build_dir() / exe_name,
                       meson.current_build_dir() / exe['name'],
-                     meson.current_source_dir() / 'accel/hvf/entitlements.plist'
+                     entitlements, icon
                     ])
        }
  
        meson.add_install_script('scripts/entitlement.sh', '--install',
                                 get_option('bindir') / exe_name,
                                 get_option('bindir') / exe['name'],
-                               meson.current_source_dir() / 'accel/hvf/entitlements.plist')
+                               entitlements, icon)
      else
        emulators += {exe['name']: emulator}
      endif
diff --git a/scripts/entitlement.sh b/scripts/entitlement.sh
index f7aaaf2766..573bed0c2f 100755
--- a/scripts/entitlement.sh
+++ b/scripts/entitlement.sh
@@ -11,6 +11,7 @@ fi
  SRC="$1"
  DST="$2"
  ENTITLEMENT="$3"
+ICON="$4"
  
  if $in_place; then
    trap 'rm "$DST.tmp"' exit
@@ -20,6 +21,9 @@ else
    cd "$MESON_INSTALL_DESTDIR_PREFIX"
  fi
  
-codesign --entitlements "$ENTITLEMENT" --force -s - "$SRC"
+if test "$ENTITLEMENT" != '/dev/null'; then
+  codesign --entitlements "$ENTITLEMENT" --force -s - "$SRC"
+fi
+# icon stuff here
  mv -f "$SRC" "$DST"
  trap '' exit

Paolo