All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Bin Meng <bin.meng@windriver.com>,
	 Cleber Rosa <crosa@redhat.com>, John Snow <jsnow@redhat.com>
Subject: Re: [PATCH 3/7] scripts/nsis.py: Automatically package required DLLs of QEMU executables
Date: Sat, 10 Sep 2022 08:37:36 +0800	[thread overview]
Message-ID: <CAEUhbmVmKhJJk0pQcVJKryie+V4uZEznZCu0dzjftYCycBtD8w@mail.gmail.com> (raw)
In-Reply-To: <556496df-4362-6780-8379-e14bf4269e3f@ilande.co.uk>

On Sat, Sep 10, 2022 at 12:49 AM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> On 08/09/2022 14:28, Bin Meng wrote:
>
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > At present packaging the required DLLs of QEMU executables is a
> > manual process, and error prone.
> >
> > Actually build/config-host.mak contains a GLIB_BINDIR variable
> > which is the directory where glib and other DLLs reside. This
> > works for both Windows native build and cross-build on Linux.
> > We can use it as the search directory for DLLs and automate
> > the whole DLL packaging process.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >   meson.build     |  1 +
> >   scripts/nsis.py | 46 ++++++++++++++++++++++++++++++++++++++++++----
> >   2 files changed, 43 insertions(+), 4 deletions(-)
> >
> > diff --git a/meson.build b/meson.build
> > index c2adb7caf4..4c03850f9f 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -3657,6 +3657,7 @@ if host_machine.system() == 'windows'
> >       '@OUTPUT@',
> >       get_option('prefix'),
> >       meson.current_source_dir(),
> > +    config_host['GLIB_BINDIR'],
> >       host_machine.cpu(),
> >       '--',
> >       '-DDISPLAYVERSION=' + meson.project_version(),
> > diff --git a/scripts/nsis.py b/scripts/nsis.py
> > index baa6ef9594..03ed7608a2 100644
> > --- a/scripts/nsis.py
> > +++ b/scripts/nsis.py
> > @@ -18,12 +18,36 @@ def signcode(path):
> >           return
> >       subprocess.run([cmd, path])
> >
> > +def find_deps(exe_or_dll, search_path, analyzed_deps):
> > +    deps = [exe_or_dll]
> > +    output = subprocess.check_output(["objdump", "-p", exe_or_dll], text=True)
> > +    output = output.split("\n")
> > +    for line in output:
> > +        if not line.startswith("\tDLL Name: "):
> > +            continue
> > +
> > +        dep = line.split("DLL Name: ")[1].strip()
> > +        if dep in analyzed_deps:
> > +            continue
> > +
> > +        dll = os.path.join(search_path, dep)
> > +        if not os.path.exists(dll):
> > +            # assume it's a Windows provided dll, skip it
> > +            continue
> > +
> > +        analyzed_deps.add(dep)
> > +        # locate the dll dependencies recursively
> > +        rdeps = find_deps(dll, search_path, analyzed_deps)
> > +        deps.extend(rdeps)
> > +
> > +    return deps
> >
> >   def main():
> >       parser = argparse.ArgumentParser(description="QEMU NSIS build helper.")
> >       parser.add_argument("outfile")
> >       parser.add_argument("prefix")
> >       parser.add_argument("srcdir")
> > +    parser.add_argument("dlldir")
> >       parser.add_argument("cpu")
> >       parser.add_argument("nsisargs", nargs="*")
> >       args = parser.parse_args()
> > @@ -63,9 +87,26 @@ def main():
> >                   !insertmacro MUI_DESCRIPTION_TEXT ${{Section_{0}}} "{1}"
> >                   """.format(arch, desc))
> >
> > +        search_path = args.dlldir
> > +        print("Searching '%s' for the dependent dlls ..." % search_path)
> > +        dlldir = os.path.join(destdir + prefix, "dll")
> > +        os.mkdir(dlldir)
> > +
> >           for exe in glob.glob(os.path.join(destdir + prefix, "*.exe")):
> >               signcode(exe)
> >
> > +            # find all dll dependencies
> > +            deps = set(find_deps(exe, search_path, set()))
> > +            deps.remove(exe)
> > +
> > +            # copy all dlls to the DLLDIR
> > +            for dep in deps:
> > +                dllfile = os.path.join(dlldir, os.path.basename(dep))
> > +                if (os.path.exists(dllfile)):
> > +                    continue
> > +                print("Copying '%s' to '%s'" % (dep, dllfile))
> > +                shutil.copy(dep, dllfile)
> > +
> >           makensis = [
> >               "makensis",
> >               "-V2",
> > @@ -73,12 +114,9 @@ def main():
> >               "-DSRCDIR=" + args.srcdir,
> >               "-DBINDIR=" + destdir + prefix,
> >           ]
> > -        dlldir = "w32"
> >           if args.cpu == "x86_64":
> > -            dlldir = "w64"
> >               makensis += ["-DW64"]
> > -        if os.path.exists(os.path.join(args.srcdir, "dll")):
> > -            makensis += ["-DDLLDIR={0}/dll/{1}".format(args.srcdir, dlldir)]
> > +        makensis += ["-DDLLDIR=" + dlldir]
> >
> >           makensis += ["-DOUTFILE=" + args.outfile] + args.nsisargs
> >           subprocess.run(makensis)
>
> FWIW I wrote a similar script a while back to help package a custom Windows build for
> a client, however I used ldd instead of objdump since it provided the full paths for
> DLLs installed in the msys2/mingw-w64 environment via pacman which were outside the
> QEMU build tree.
>

Yep, ldd also works, but only on Windows native build. objdump can
work on both Windows native and Linux cross builds.

> Once the complete list of DLLs was obtained, it was simple matter of filtering out
> those DLLs that started with the %WINDIR% prefix before copying them to the final
> distribution directory.
>

Regards,
Bin


  reply	other threads:[~2022-09-10  0:38 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 13:28 [PATCH 0/7] nsis: gitlab-ci: Improve QEMU Windows installer packaging Bin Meng
2022-09-08 13:28 ` [PATCH 1/7] scripts/nsis.py: Drop the unnecessary path separator Bin Meng
2022-09-17 21:18   ` Philippe Mathieu-Daudé via
2022-10-29  7:44   ` Stefan Weil via
2022-09-08 13:28 ` [PATCH 2/7] scripts/nsis.py: Fix destination directory name when invoked on Windows Bin Meng
2022-09-08 13:46   ` Marc-André Lureau
2022-09-17 21:20   ` Philippe Mathieu-Daudé via
2022-10-29  7:58   ` Stefan Weil via
2022-09-08 13:28 ` [PATCH 3/7] scripts/nsis.py: Automatically package required DLLs of QEMU executables Bin Meng
2022-09-08 13:56   ` Marc-André Lureau
2022-09-09 16:49   ` Mark Cave-Ayland
2022-09-10  0:37     ` Bin Meng [this message]
2024-02-25 17:37       ` Stefan Weil via
2024-02-26  4:35         ` Bin Meng
2024-02-26  6:30           ` Stefan Weil via
2024-03-10  8:02             ` Mark Cave-Ayland
2022-10-29  9:04   ` Stefan Weil via
2022-09-08 13:28 ` [PATCH 4/7] .gitlab-ci.d/windows.yml: Drop the sed processing in the 64-bit build Bin Meng
2022-09-08 14:04   ` Marc-André Lureau
2022-09-09 16:30     ` Thomas Huth
2022-09-17 21:22   ` Philippe Mathieu-Daudé via
2022-09-08 13:28 ` [PATCH 5/7] block/nfs: Fix 32-bit Windows build Bin Meng
2022-09-17 21:32   ` Philippe Mathieu-Daudé via
2022-09-21 12:10     ` Meng, Bin
2022-09-24  1:19       ` Bin Meng
2022-10-27  2:45         ` Bin Meng
2022-10-27  7:54           ` Kevin Wolf
2022-10-27  8:16             ` Bin Meng
2022-10-29 15:57   ` Stefan Weil via
2022-09-08 13:28 ` [PATCH 6/7] .gitlab-ci.d/windows.yml: Unify the prerequisite packages Bin Meng
2022-09-09 16:32   ` Thomas Huth
2022-09-10  0:32     ` Bin Meng
2022-09-10  5:09       ` 罗勇刚(Yonggang Luo)
2022-09-24  9:20       ` Bin Meng
2022-10-29 13:06         ` Bin Meng
2022-10-29 16:19           ` Stefan Weil via
2022-10-31  6:43           ` Thomas Huth
2022-09-08 13:28 ` [PATCH 7/7] .gitlab-ci.d/windows.yml: Test 'make installer' in the CI Bin Meng
2022-09-17 21:31   ` Philippe Mathieu-Daudé via
2022-10-29 16:39   ` Stefan Weil via
2022-10-30  3:21     ` Bin Meng
2022-10-31  7:01       ` Thomas Huth
2022-09-16  0:35 ` [PATCH 0/7] nsis: gitlab-ci: Improve QEMU Windows installer packaging Bin Meng
2022-09-21 12:18 ` Bin Meng
2022-09-21 12:24   ` Thomas Huth
2022-09-23  2:28     ` Bin Meng
2022-10-29 13:45     ` Bin Meng
2022-10-31  6:52       ` Thomas Huth
2022-10-31  9:26         ` Stefan Weil via
2022-10-31  9:29           ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEUhbmVmKhJJk0pQcVJKryie+V4uZEznZCu0dzjftYCycBtD8w@mail.gmail.com \
    --to=bmeng.cn@gmail.com \
    --cc=bin.meng@windriver.com \
    --cc=crosa@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.