[PATCH 5/5] meson: add NSIS building

marcandre.lureau@redhat.com posted 5 patches 5 years, 5 months ago
There is a newer version of this series
[PATCH 5/5] meson: add NSIS building
Posted by marcandre.lureau@redhat.com 5 years, 5 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 Makefile        | 56 -----------------------------------------------
 meson.build     | 24 ++++++++++++++++++++
 scripts/nsis.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 56 deletions(-)
 create mode 100755 scripts/nsis.sh

diff --git a/Makefile b/Makefile
index 81794d5c34..3ebd6929b4 100644
--- a/Makefile
+++ b/Makefile
@@ -294,62 +294,6 @@ endif
 		"$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
 	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
 
-ifdef CONFIG_WIN32
-
-INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
-
-nsisflags = -V2 -NOCD
-
-ifneq ($(wildcard $(SRC_PATH)/dll),)
-ifeq ($(ARCH),x86_64)
-# 64 bit executables
-DLL_PATH = $(SRC_PATH)/dll/w64
-nsisflags += -DW64
-else
-# 32 bit executables
-DLL_PATH = $(SRC_PATH)/dll/w32
-endif
-endif
-
-.PHONY: installer
-installer: $(INSTALLER)
-
-INSTDIR=/tmp/qemu-nsis
-
-$(INSTALLER): $(SRC_PATH)/qemu.nsi
-	$(MAKE) install DESTDIR=${INSTDIR}
-ifdef SIGNCODE
-	(cd ${INSTDIR}/${bindir}; \
-         for i in *.exe; do \
-           $(SIGNCODE) $${i}; \
-         done \
-        )
-endif # SIGNCODE
-	(cd ${INSTDIR}/${bindir}; \
-         for i in qemu-system-*.exe; do \
-           arch=$${i%.exe}; \
-           arch=$${arch#qemu-system-}; \
-           echo Section \"$$arch\" Section_$$arch; \
-           echo SetOutPath \"\$$INSTDIR\"; \
-           echo File \"\$${BINDIR}\\$$i\"; \
-           echo SectionEnd; \
-         done \
-        ) >${INSTDIR}/${bindir}/system-emulations.nsh
-	makensis $(nsisflags) \
-                $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
-                $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
-                -DBINDIR="${INSTDIR}/${bindir}" \
-                $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
-                -DSRCDIR="$(SRC_PATH)" \
-                -DOUTFILE="$(INSTALLER)" \
-                -DDISPLAYVERSION="$(VERSION)" \
-                $(SRC_PATH)/qemu.nsi
-	rm -r ${INSTDIR}
-ifdef SIGNCODE
-	$(SIGNCODE) $(INSTALLER)
-endif # SIGNCODE
-endif # CONFIG_WIN
-
 # Add a dependency on the generated files, so that they are always
 # rebuilt before other object files
 ifneq ($(wildcard config-host.mak),)
diff --git a/meson.build b/meson.build
index 0720a7d684..4ee8ef1e9d 100644
--- a/meson.build
+++ b/meson.build
@@ -1217,6 +1217,30 @@ if build_docs
   endif
 endif
 
+if host_machine.system() == 'windows'
+  nsis_cmd = [
+    find_program('scripts/nsis.sh'),
+    '@OUTPUT@',
+    get_option('prefix'),
+    meson.current_source_dir(),
+    host_machine.cpu_family(),
+    '-DDISPLAYVERSION=' + meson.project_version(),
+  ]
+  if build_docs
+    nsis_cmd += '-DCONFIG_DOCUMENTATION=y'
+  endif
+  if 'CONFIG_GTK' in config_host
+    nsis_cmd += '-DCONFIG_GTK=y'
+  endif
+
+  nsis = custom_target('nsis',
+                       output: 'qemu-setup-' + meson.project_version() + '.exe',
+                       input: files('qemu.nsi'),
+                       build_always_stale: true,
+                       command: nsis_cmd + ['@INPUT@'])
+  alias_target('installer', nsis)
+endif
+
 summary_info = {}
 summary_info += {'Install prefix':    config_host['prefix']}
 summary_info += {'BIOS directory':    config_host['qemu_datadir']}
diff --git a/scripts/nsis.sh b/scripts/nsis.sh
new file mode 100755
index 0000000000..d7d8b39b04
--- /dev/null
+++ b/scripts/nsis.sh
@@ -0,0 +1,58 @@
+#!/bin/bash -e
+
+OUTFILE="$1"
+shift
+PREFIX="$1"
+shift
+SRCDIR="$1"
+shift
+CPU="$1"
+shift
+
+DESTDIR=$(mktemp -d)
+trap 'rm -rf $DESTDIR' EXIT
+make DESTDIR="$DESTDIR/" install
+
+do_signcode() {
+    if [ -z "$SIGNCODE" ]; then
+        return
+    fi
+    "$SIGNCODE" "$@"
+}
+
+shopt -s nullglob
+
+(
+    cd "$DESTDIR$PREFIX"
+    for i in qemu-system-*.exe; do
+        arch=${i%.exe}
+        arch=${arch#qemu-system-}
+        echo Section \""$arch"\" "Section_$arch"
+        echo SetOutPath \"\$INSTDIR\"
+        echo File \"\${BINDIR}\\$i\"
+        echo SectionEnd
+    done
+) > "$DESTDIR$PREFIX/system-emulations.nsh"
+
+(
+    cd "$DESTDIR$PREFIX"
+    for i in *.exe; do
+        do_signcode "$i"
+    done
+)
+
+if [ "$CPU" = "x86_64" ]; then
+    CPUARG="-DW64"
+    DLLDIR="w64"
+else
+    DLLDIR="w32"
+fi
+
+if [ -d "$SRCDIR/dll" ]; then
+   DLLARG="-DDLLDIR=$SRCDIR/dll/$DLLDIR"
+fi
+
+makensis -V2 -NOCD -DSRCDIR="$SRCDIR" -DBINDIR="$DESTDIR$PREFIX" \
+         $CPUARG $DLLARG -DOUTFILE="$OUTFILE" "$@"
+
+do_signcode "$OUTFILE"
-- 
2.26.2


Re: [PATCH 5/5] meson: add NSIS building
Posted by Daniel P. Berrangé 5 years, 5 months ago
On Tue, Aug 25, 2020 at 07:04:09PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  Makefile        | 56 -----------------------------------------------
>  meson.build     | 24 ++++++++++++++++++++
>  scripts/nsis.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 82 insertions(+), 56 deletions(-)
>  create mode 100755 scripts/nsis.sh

I feel like one of the bug improvements of Meson over a traditional
configure+make type approach is that we get much improved platform
portability by default in the build system, largely for free from
Meson and in turn Python.

With this in mind, I think that as a general goal, we should strive
to eliminate any and all use of shell in the build system, standardizing
on Python for any helper programs we need to run from Meson.

This is a verbose way of saying I think you should create a
nsis.py, not nsis.sh, to avoid the inherant portability problems of
shell that hit us over and over and over again.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH 5/5] meson: add NSIS building
Posted by Peter Maydell 5 years, 5 months ago
On Tue, 25 Aug 2020 at 16:14, Daniel P. Berrangé <berrange@redhat.com> wrote:
> This is a verbose way of saying I think you should create a
> nsis.py, not nsis.sh, to avoid the inherant portability problems of
> shell that hit us over and over and over again.

Does it have to be a separate script, or can we just write inline
Python in the meson file? The main reason the current code is
written in shell is because that's what you need to write it in
so you can write it inline in a Makefile, and because half of
it is "invoke this other command ($(SIGNCODE), makensis, etc)",
which is what build systems are good at.

thanks
-- PMM

Re: [PATCH 5/5] meson: add NSIS building
Posted by Daniel P. Berrangé 5 years, 5 months ago
On Tue, Aug 25, 2020 at 05:03:41PM +0100, Peter Maydell wrote:
> On Tue, 25 Aug 2020 at 16:14, Daniel P. Berrangé <berrange@redhat.com> wrote:
> > This is a verbose way of saying I think you should create a
> > nsis.py, not nsis.sh, to avoid the inherant portability problems of
> > shell that hit us over and over and over again.
> 
> Does it have to be a separate script, or can we just write inline
> Python in the meson file? The main reason the current code is
> written in shell is because that's what you need to write it in
> so you can write it inline in a Makefile, and because half of
> it is "invoke this other command ($(SIGNCODE), makensis, etc)",
> which is what build systems are good at.

Meson just wants to have a command path + list of arguments.

So if you want to have the python code inline you can do that by passing
it as an arg by telling meson to run "python -e <codeblob>".

I think that's only sensible for one-liner scripts though. Otherwise it
is nicer to have a separate script that you can invoke directly for
testing / debugging purposes separately from meson.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH 5/5] meson: add NSIS building
Posted by Peter Maydell 5 years, 5 months ago
On Tue, 25 Aug 2020 at 16:09, <marcandre.lureau@redhat.com> wrote:
> diff --git a/scripts/nsis.sh b/scripts/nsis.sh
> new file mode 100755
> index 0000000000..d7d8b39b04
> --- /dev/null
> +++ b/scripts/nsis.sh
> @@ -0,0 +1,58 @@
> +#!/bin/bash -e
> +

Copyright and license header comment for all new files, please.

thanks
-- PMM