From 9d98617c1a4ccfea12a1653019d0f06e4249570c Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 15 Apr 2024 22:28:11 +0200 Subject: [PATCH 1/4] Update debugging with vscode section - We have ssh-generator now, so need for mkosi's Ssh= option anymore. - By enabling RuntimeBuildSources= by default, we don't need the gdb config file in the image anymore, since the build and source directories will be mounted at the expected locations. --- docs/HACKING.md | 27 ++++--------------- mkosi.conf | 1 + .../share/factory/mkosi/gdbinit.d/systemd.gdb | 3 --- mkosi.images/system/mkosi.finalize | 1 + 4 files changed, 7 insertions(+), 25 deletions(-) delete mode 100644 mkosi.images/system/mkosi.extra/usr/share/factory/mkosi/gdbinit.d/systemd.gdb diff --git a/docs/HACKING.md b/docs/HACKING.md index 2a58780fbf..569f81ab0b 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -276,22 +276,9 @@ To simplify debugging systemd when testing changes using mkosi, we're going to s QEMU. To allow VSCode's debugger to attach to systemd running in a mkosi image, we have to make sure it can access -the virtual machine spawned by mkosi where systemd is running. mkosi makes this possible via a handy SSH -option that makes the generated image accessible via SSH when booted. Thus you must build the image with -`mkosi --ssh`. The easiest way to set the option is to create a file `mkosi.local.conf` in the root of the -repository and add the following contents: - -``` -[Host] -Ssh=yes -RuntimeTrees=. -``` - -Also make sure that the SSH agent is running on your system and that you've added your SSH key to it with -`ssh-add`. Also make sure that `virtiofsd` is installed. - -After rebuilding the image and booting it with `mkosi qemu`, you should now be able to connect to it by -running `mkosi ssh` from the same directory in another terminal window. +the virtual machine spawned by mkosi where systemd is running. After booting the image with `mkosi qemu`, you +should now be able to connect to it by running `mkosi ssh` from the same directory in another terminal +window. Now we need to configure VSCode. First, make sure the C/C++ extension is installed. If you're already using a different extension for code completion and other IDE features for C in VSCode, make sure to disable the @@ -320,16 +307,12 @@ the directory, and add the following contents: "name": "systemd", "pipeTransport": { "pipeProgram": "mkosi", - "pipeArgs": [ - "-C", - "/path/to/systemd/repo/directory/on/host/system/", - "ssh" - ], + "pipeArgs": ["-C", "${workspaceFolder}", "ssh"], "debuggerPath": "/usr/bin/gdb" }, "MIMode": "gdb", "sourceFileMap": { - "/root/src/systemd": { + "/work/src": { "editorPath": "${workspaceFolder}", "useForBreakpoints": false }, diff --git a/mkosi.conf b/mkosi.conf index 96843db488..ee7fa6e2a4 100644 --- a/mkosi.conf +++ b/mkosi.conf @@ -20,6 +20,7 @@ BuildSourcesEphemeral=yes [Host] @Incremental=yes @RuntimeSize=8G +@RuntimeBuildSources=yes ToolsTreePackages=virtiofsd KernelCommandLineExtra=systemd.crash_shell systemd.log_level=debug,console:info diff --git a/mkosi.images/system/mkosi.extra/usr/share/factory/mkosi/gdbinit.d/systemd.gdb b/mkosi.images/system/mkosi.extra/usr/share/factory/mkosi/gdbinit.d/systemd.gdb deleted file mode 100644 index 26f882bc2b..0000000000 --- a/mkosi.images/system/mkosi.extra/usr/share/factory/mkosi/gdbinit.d/systemd.gdb +++ /dev/null @@ -1,3 +0,0 @@ -set debuginfod enabled off -set build-id-verbose 0 -set substitute-path ../src /root/src/systemd diff --git a/mkosi.images/system/mkosi.finalize b/mkosi.images/system/mkosi.finalize index 74b810c152..6da35e5138 100755 --- a/mkosi.images/system/mkosi.finalize +++ b/mkosi.images/system/mkosi.finalize @@ -1,4 +1,5 @@ #!/bin/sh # SPDX-License-Identifier: LGPL-2.1-or-later +mkdir -p "$BUILDROOT"/usr/share/factory/mkosi cp --archive --recursive --no-target-directory --reflink=auto "$BUILDROOT"/etc "$BUILDROOT"/usr/share/factory/mkosi From 2400b3a59020448d9d4ba67bf69056c522acacd6 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 16 Apr 2024 13:58:07 +0200 Subject: [PATCH 2/4] mkosi: Install which in image gdb-headless in Fedora is missing a dependency on which: https://bugzilla.redhat.com/show_bug.cgi?id=2275274 This happens all the time so let's make sure which is always installed in the image. --- mkosi.images/system/mkosi.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/mkosi.images/system/mkosi.conf b/mkosi.images/system/mkosi.conf index 303af4acb1..ed09d841b8 100644 --- a/mkosi.images/system/mkosi.conf +++ b/mkosi.images/system/mkosi.conf @@ -40,6 +40,7 @@ Packages= udev util-linux valgrind + which wireguard-tools xfsprogs zsh From f1884281a01cfd6da0d61d7befb88dedfca5c669 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 16 Apr 2024 13:59:20 +0200 Subject: [PATCH 3/4] mkosi: Add --noclean when running rpmbuild The entire build environment is ephemeral anyway so everything is cleaned regardless. By specifying --noclean, we make debugging easier as the rpm build root can be inspected when using --debug-shell. --- .../system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot | 1 + mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot | 1 + 2 files changed, 2 insertions(+) diff --git a/mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot b/mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot index 242fc4aa40..371af8f4b9 100755 --- a/mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot +++ b/mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot @@ -48,6 +48,7 @@ rpmbuild \ --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \ --define "__script_requires %{nil}" \ --undefine _lto_cflags \ + --noclean \ "pkg/$ID/systemd.spec" cp "$OUTPUTDIR"/*.rpm "$PACKAGEDIR" diff --git a/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot b/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot index 62b329998d..5bc78aee3b 100755 --- a/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot +++ b/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot @@ -49,6 +49,7 @@ build() { --define "__os_install_post /usr/lib/rpm/brp-suse %{nil}" \ --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \ --define "__script_requires %{nil}" \ + --noclean \ "$@" \ "pkg/$ID/systemd.spec" } From 4980ae0fbc9dca90f8476950cdacd7bdcf3fefac Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 16 Apr 2024 11:24:56 +0200 Subject: [PATCH 4/4] mkosi: Add support for building debug packages This allows building debug packages by setting WITH_DEBUG=1. This slows down the build a lot so it's opt in. We don't yet install these but can do so in a future commit. --- .../mkosi.conf.d/10-arch/mkosi.build.chroot | 12 +++++++++++- .../10-centos-fedora/mkosi.build.chroot | 15 +++++++++++++-- .../10-debian-ubuntu/mkosi.build.chroot | 14 ++++++++++++-- .../mkosi.conf.d/10-opensuse/mkosi.build.chroot | 11 ++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot b/mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot index 807823205f..fb85580360 100755 --- a/mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot +++ b/mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot @@ -26,7 +26,17 @@ mount --mkdir --rbind "$PWD/pkg/$ID" "pkg/$ID/src/" # tmpfs during the build script so these changes don't end up in the image itself. tee --append /etc/makepkg.conf >/dev/null <>debian/changelog.new mv debian/changelog.new debian/changelog build() { - DEB_BUILD_OPTIONS="$( ((WITH_TESTS)) || echo nocheck) $( ((WITH_DOCS)) || echo nodoc) nostrip terse optimize=-lto" \ - DEB_BUILD_PROFILES="$( ((WITH_TESTS)) || echo nocheck) $( ((WITH_DOCS)) || echo nodoc) pkg.systemd.upstream" \ + DEB_BUILD_OPTIONS="\ + $( ((WITH_TESTS)) || echo nocheck) \ + $( ((WITH_DOCS)) || echo nodoc) \ + $( ((WITH_DEBUG)) || echo nostrip) \ + terse + optimize=-lto \ + " \ + DEB_BUILD_PROFILES="\ + $( ((WITH_TESTS)) || echo nocheck) \ + $( ((WITH_DOCS)) || echo nodoc) \ + pkg.systemd.upstream \ + " \ DEB_CFLAGS_APPEND="-Og" \ DPKG_FORCE="unsafe-io" \ DPKG_DEB_COMPRESSOR_TYPE="none" \ diff --git a/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot b/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot index 5bc78aee3b..fe89611e36 100755 --- a/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot +++ b/mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot @@ -22,7 +22,15 @@ fi # extension. find "pkg/$ID" -name "files.*" -exec sed --in-place 's/\.gz$//' {} \; +# Fix the %install override so debuginfo packages are generated. +tee --append /usr/lib/rpm/suse/macros <<'EOF' +%install %{debug_package}\ +%%install\ +%{nil} +EOF + build() { + IFS= # TODO: Replace meson_build and meson_install overrides with "--undefine __meson_verbose" once # https://github.com/mesonbuild/meson/pull/12835 is available. # shellcheck disable=SC2046 @@ -38,7 +46,8 @@ build() { ${BUILDDIR:+"_vpath_builddir $BUILDDIR"} \ --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \ --define "_binary_payload w.ufdio" \ - --define "debug_package %{nil}" \ + $( ((WITH_DEBUG)) || echo --define) \ + $( ((WITH_DEBUG)) || echo "debug_package %{nil}") \ --define "vendor openSUSE" \ --define "version_override $(cat meson.version)" \ --define "release_override $(date "+%Y%m%d%H%M%S" --date "@$TS")" \