From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d62Dl-0000Ub-Q7 for guix-patches@gnu.org; Wed, 03 May 2017 17:54:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d62Di-0000vY-Ot for guix-patches@gnu.org; Wed, 03 May 2017 17:54:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:55084) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d62Di-0000vP-Lw for guix-patches@gnu.org; Wed, 03 May 2017 17:54:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d62Di-0006Lg-DP for guix-patches@gnu.org; Wed, 03 May 2017 17:54:02 -0400 Subject: bug#26295: [PATCH] 'Debugging Build Failures' subsection Resent-To: guix-patches@gnu.org Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: Date: Wed, 03 May 2017 23:53:31 +0200 In-Reply-To: (catonano@gmail.com's message of "Wed, 29 Mar 2017 12:06:47 +0200") Message-ID: <874lx1r4is.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Catonano Cc: 26295-done@debbugs.gnu.org Hi Catonano, and apologies for the delay! Catonano skribis: > From 55b9fab0c6f218b73fdf1804c606a4bdcf2ddda4 Mon Sep 17 00:00:00 2001 > From: humanitiesNerd > Date: Wed, 29 Mar 2017 11:43:55 +0200 > Subject: [PATCH 1/1] gnu: Add 'Debugging Build Failures' subsection to > 'Invoking guix build' > > * doc/guix.texi (Debugging Build Failures): New subsection. I ended up editing it somewhat and adding cross-references (hope that=E2=80= =99s OK!) and pushed a revised version of this patch as fc06b15e86d40549dc30097621a2c7c6bcd69f2e (modified text below.) Thank you! Ludo=E2=80=99. When defining a new package (*note Defining Packages::), you will probably find yourself spending some time debugging and tweaking the build until it succeeds. To do that, you need to operate the build commands yourself in an environment as close as possible to the one the build daemon uses. To that end, the first thing to do is to use the =E2=80=98--keep-failed= =E2=80=99 or =E2=80=98-K=E2=80=99 option of =E2=80=98guix build=E2=80=99, which will kee= p the failed build tree in =E2=80=98/tmp=E2=80=99 or whatever directory you specified as =E2=80=98TMPD= IR=E2=80=99 (*note =E2=80=98--keep-failed=E2=80=99: Invoking guix build.). From there on, you can =E2=80=98cd=E2=80=99 to the failed build tree and= source the =E2=80=98environment-variables=E2=80=99 file, which contains all the enviro= nment variable definitions that were in place when the build failed. So let=E2= =80=99s say you=E2=80=99re debugging a build failure in package =E2=80=98foo=E2=80= =99; a typical session would look like this: $ guix build foo -K ... build fails $ cd /tmp/guix-build-foo.drv-0 $ source ./environment-variables $ cd foo-1.2 Now, you can invoke commands as if you were the daemon (almost) and troubleshoot your build process. Sometimes it happens that, for example, a package=E2=80=99s tests pass w= hen you run them manually but they fail when the daemon runs them. This can happen because the daemon runs builds in containers where, unlike in our environment above, network access is missing, =E2=80=98/bin/sh=E2=80=99 doe= s not exist, etc. (*note Build Environment Setup::). In such cases, you may need to run inspect the build process from within a container similar to the one the build daemon creates: $ guix build -K foo ... $ cd /tmp/guix-build-foo.drv-0 $ guix environment -C foo --ad-hoc strace gdb [env]# source ./environment-variables [env]# cd foo-1.2 Here, =E2=80=98guix environment -C=E2=80=99 creates a container and spaw= ns a new shell in it (*note Invoking guix environment::). The =E2=80=98--ad-hoc str= ace gdb=E2=80=99 part adds the =E2=80=98strace=E2=80=99 and =E2=80=98gdb=E2=80= =99 commands to the container, which would may find handy while debugging. To get closer to a container like that used by the build daemon, we can remove =E2=80=98/bin/sh=E2=80=99: [env]# rm /bin/sh (Don=E2=80=99t worry, this is harmless: this is all happening in the throw-away container created by =E2=80=98guix environment=E2=80=99.) The =E2=80=98strace=E2=80=99 command is probably not in the search path,= but we can run: [env]# $GUIX_ENVIRONMENT/bin/strace -f -o log make check In this way, not only you will have reproduced the environment variables the daemon uses, you will also be running the build process in a container similar to the one the daemon uses.