From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +G1+OdUW32HYAgEAgWs5BA (envelope-from ) for ; Wed, 12 Jan 2022 18:58:45 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id OJI/MtUW32EhkgAAG6o9tA (envelope-from ) for ; Wed, 12 Jan 2022 18:58:45 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 89B0A22B3F for ; Wed, 12 Jan 2022 18:58:45 +0100 (CET) Received: from localhost ([::1]:59752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7htU-0001VL-LZ for larch@yhetil.org; Wed, 12 Jan 2022 12:58:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7ht4-0001Uv-Ip for guix-devel@gnu.org; Wed, 12 Jan 2022 12:58:18 -0500 Received: from flashner.co.il ([178.62.234.194]:32906) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7ht2-00053u-RV for guix-devel@gnu.org; Wed, 12 Jan 2022 12:58:18 -0500 Received: from localhost (unknown [141.226.10.247]) by flashner.co.il (Postfix) with ESMTPSA id 62BAA4013B; Wed, 12 Jan 2022 17:57:35 +0000 (UTC) Date: Wed, 12 Jan 2022 19:56:57 +0200 From: Efraim Flashner To: Ricardo Wurmus Subject: Re: RFC: new syntax for inline patches Message-ID: Mail-Followup-To: Ricardo Wurmus , guix-devel@gnu.org References: <87ee5ne7z5.fsf@elephly.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fFlc4Egn6MgoiuhA" Content-Disposition: inline In-Reply-To: <87ee5ne7z5.fsf@elephly.net> X-PGP-Key-ID: 0x41AAE7DCCA3D8351 X-PGP-Key: https://flashner.co.il/~efraim/efraim_flashner.asc X-PGP-Fingerprint: A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Received-SPF: pass client-ip=178.62.234.194; envelope-from=efraim@flashner.co.il; helo=flashner.co.il X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1642010325; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=v4/TzFJCYq0SFNCkqxybLTlBrkhaoyM/9RLN4G4w7iU=; b=H2k6OWonyf/m2O4XenQ6rBvwbzfvFQ1WANDiNOE5k5fwaBpp12cocRUd9+dk9jpiFEB0B7 zW9+tNJ6iBFsr0kEYQn52gDfqMjoHGvnYNDpCId3QfFc0/pRxtEyrIENXfUvq1FF+1ojK/ +86qun0thtaG+4rAa8miNr1r+pHTkBTzXw9IvUv69UVo/2GbOZ/EqroS+fNmKnTa1TaMh5 UVqNQpngS9q1yy8tqp8yI7bKkEhX8jze0/yscozZ4k0ifZ3b7JU0DN5fmheOhYNu4UOs1g F/2L6zcMvizXQ8AxDZq1feCyIYKdMlnMm4c/8BqhML1W6RNiyhCNPYwIuSQaQw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642010325; a=rsa-sha256; cv=none; b=THXlCIWmv29egbCu+x/cvar2n5GsK+pQkO7ikGc5rO7jwwFaXZMetj8KeJLwbpiy13MDcW taSmlqQhtwpTbRAFcmmGHFWRegOniX77GOPrQRpHRgDOs3Nkv79ztN2mFmwMEctI53C6Lq YD6dgqW5a5uGPDjkDRccbgUEzQEuLIC7m8lSOagsWlMAPvnRR0SyqEH0oUc3bmN3VjgWqE zgaV6i0ovKm6HTxeF+gECxs0p+nrBuEAsempKlPZlBSf7WemLlqr3jv6MTQxhLskFBKE8E 6fP0aY0WGBrzqbexOgmPIparI0sHiKznCuLqMdM6IiDvFTct9cvNP592hGmTRA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.02 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 89B0A22B3F X-Spam-Score: -5.02 X-Migadu-Scanner: scn0.migadu.com X-TUID: Gad1hoQHPzTE --fFlc4Egn6MgoiuhA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 04, 2022 at 05:50:31PM +0100, Ricardo Wurmus wrote: > Hi Guix, >=20 > does this pattern look familiar to you? >=20 > (arguments > (list > #:phases > '(modify-phases %standard-phases > (add-after 'unpack 'i-dont-care > (lambda _ > (substitute* "this-file" > (("^# some unique string, oh, careful! gotta \\(escape\\) thi= s\\." m) > (string-append m "\nI ONLY WANTED TO ADD THIS LINE!\n"))))))= )) >=20 > This is a lot of boilerplate just to add a line to a file. I=E2=80=99m u= sing > =E2=80=9Csubstitute*=E2=80=9D but actually I don=E2=80=99t want to substi= tute anything. I just > know that I need to add a line somewhere in =E2=80=9Cthis-file=E2=80=9D. >=20 > Or maybe it=E2=80=99s a CMakeLists.txt file that inexplicably wants to do= wnload > stuff? I should patch that file but it=E2=80=99s a multi-line change. S= o I=E2=80=99m > trying to do the same as above with several different anchor strings to > comment out lines. >=20 > We have a lot of packages like that. And while this boilerplate pattern > looks familiar to most of us now, it is really unclear. It is > imperative and abuses regular expression matching when really it should > have been a patch. >=20 > There are a few reasons why we don=E2=80=99t use patches as often: >=20 > 1. the source code is precious and we prefer to modify the original > sources as little as necessary, so that users can get the source code as > upstream intended with =E2=80=9Cguix build -S foo=E2=80=9D. We patch the= sources > primarily to get rid of bundled source code, pre-built binaries, or > code that encroaches on users=E2=80=99 freedom. >=20 > 2. the (patches =E2=80=A6) field uses patch files. These are annoying and > inflexible. They have to be added to dist_patch_DATA in gnu/local.mk, > and they cannot contain computed store locations. They are separate > from the package definition, which is inconvenient. It also feels wrong to add a 30 line patch, taking into account the header bits, to make a 3 line change. > 3. snippets feel like less convenient build phases. Snippets are not > thunked, so we can=E2=80=99t do some things that we would do in a build p= hase > substitution. We also can=E2=80=99t access %build-inputs or %outputs. (= I don=E2=80=99t > know if we can use Gexps there.) I believe you can leave out the modules line and use a gexp in the snippet (without the "'(begin" portion ) > I feel that the first point is perhaps a little overvalued. I have > often felt annoyed that I had to manually apply all this build phase > patching to source code obtained with =E2=80=9Cguix build -S=E2=80=9D, bu= t I never felt > that source code I got from =E2=80=9Cguix build -S=E2=80=9D was too far r= emoved from > upstream. >=20 > It may not be possible to apply patches with computed store locations =E2= =80=94 > because when we compute the source derivation (which is an input to the > package derivation) we don=E2=80=99t yet know the outputs of the package > derivation. But perhaps we can still agree on a more declarative way to > express patches that are to be applied before the build starts; syntax > that would be more declarative than a serious of brittle substitute* > expressions that latch onto hopefully unique strings in the target > files. >=20 > (We have something remotely related in etc/committer.scm.in, where we > define a record describing a diff hunk.) >=20 > Here=E2=80=99s a colour sample for the new bikeshed: >=20 > (arguments > (list > #:patches > #~(patch "the-file" > ((line 10) > (+ "I ONLY WANTED TO ADD THIS LINE")) > ((line 3010) > (- "maybe that=E2=80=99s better") > (+ (string-append #$guix " is better")) > (+ "but what do you think?"))))) I have on at least one occasion stopped myself from trying to use ed (it IS the standard editor) to apply something that SHOULD BE trivial to change. --=20 Efraim Flashner =D7=A8=D7=A0=D7=A9=D7=9C=D7=A4 = =D7=9D=D7=99=D7=A8=D7=A4=D7=90 GPG key =3D A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted --fFlc4Egn6MgoiuhA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmHfFmYACgkQQarn3Mo9 g1FIAxAAgOqylQrLk33L+oi90+vD5ZwpjYvrkvWoCtC1E6dkCzzzQvjrcFXryABn czv+UPVpwUAo1zFlFi08znUqtezOFgnlog89IDPdc5A2H+GCHTpn/ELG24sXLnDA zPfypZjIKamsVro7PNIAXs9FD+CjvGCYVUSKq5ELeOwU1ZQPwQswTygQrtzbc7vA X6AqZTb0H3OHbquZOrrgF33abMunj3UrgKCpKNZdmjMRJFYzstOUnOlxNtZDBmXC mDHLg3Id5n0EHGymVvBax6gkNU++errtrKhtdaquq6IrJISp4ITauZ4ZyClzJMLa 37MNSy0f6SKguOshTMyr5mPhrTo4J4Gu7bddbZ3phnyvZrGbA7PCw8UVeLsooQ7e e5ytelLxj9Kh/OM2W3cFZOl3s5b7FDFym1yJkgq6UNU7q3TIndVYNa197WE4xrRu H/bURJygtWT9BuFcLDkmQqM8fStzkpm6L1ZOvFRyXArWmBjIfSQ0F5nkqjJBFAFF zK3GV2xLIiKpLFRpY7xyBM+OgOU69V1f0tG3sSFBXSnNN04WAMXKOd3zlDQ67Ukl 3XGVxp8uGVgGdiHovWasK64kcLm5NgCLqv63r98QtpzVfZvgbeqPWSAifZK1lEd4 pqFiQgNaO/pfeXV2kvCVSVIizMXwYxaLLr0JBlJuIi0BPcdPAzU= =Dsnd -----END PGP SIGNATURE----- --fFlc4Egn6MgoiuhA--