mbox series

[bug#49169,00/11] Removing input labels from package definitions

Message ID 20210622090221.15182-1-ludo@gnu.org
Headers show
Series Removing input labels from package definitions | expand

Message

Ludovic Courtès June 22, 2021, 9:02 a.m. UTC
Hello Guix!

This patch series does the ground work to remove input labels
from package definitions.  In other words:

  (package
    ;; …
    (inputs `(("libunistring" ,libunistring)
              ("libffi" ,libffi))))

becomes:

  (package
    ;; …
    (inputs (list libunistring libffi)))

Note that it does not change the value returned by ‘package-inputs’
& co.: that still includes input labels.  Likewise, build-side code
does not see any difference (there are still input alists).

Previous discussions at:

  https://lists.gnu.org/archive/html/guix-devel/2021-05/msg00343.html
  https://lists.gnu.org/archive/html/guix-devel/2021-06/msg00072.html

The main change is the addition of ‘guix style’, based on the script
I posted earlier.  ‘guix style’ is able to systematically preserve
comments (margin comments and line comments).  It recognizes and
“translates” several common idioms.

In the long term, the goal is to remove input labels also from
APIs like ‘package-inputs’.  With an eye on this, I introduced the
‘modify-inputs’ macro as a replacement for idioms such as:

  `(("guile" ,guile-2.2)
    ,@(alist-delete "guile" (package-inputs foo)))

which becomes:

  (modify-inputs (package-inputs foo)
    (replace "guile" guile-2.2))

Code that uses ‘modify-inputs’ does not assume that ‘package-inputs’
returns an alist.  Thus, when we eventually change that, that code
won’t need to be changed.  (‘guix style’ performs this translation,
too.)

‘guix style’ processes all 17K packages in ~3mn, leading to this:

  447 files changed, 33385 insertions(+), 44079 deletions(-)

This does not incur a single rebuild.  Some packages are not
handled by ‘guix style’ because the code pattern is not
recognized or because input labels don’t match package names
(often for no good reason).  I don’t know what fraction of
the packages is left behind; I’d guess less than a third of them.

At this stage we have everything to start the migration and to
even complete it rather quickly.  What’s needed now is to look
at corner cases and idioms that have no obvious translation in
the new style.  But you can help!

  1. Check out the ‘wip-simplified-packages’ branch (based
     on ‘core-updates’).

  2. Run ‘./pre-inst-env guix style’ (you can also list package
     names) and see whether your favorite packages are handled.

  3. If you see packages not handled by ‘guix style’, try to
     convert them by hand.  If you find an idiom that you don’t
     know how to “translate”, let’s discuss it!

Thanks in advance! :-)

Ludo’.

Ludovic Courtès (11):
  records: Support field sanitizers.
  packages: Allow inputs to be plain package lists.
  lint: Add 'input-labels' checker.
  packages: Add 'lookup-package-input' & co.
  packages: Add 'modify-inputs'.
  gnu: Change inputs of core packages to plain lists.
  utils: 'edit-expression' no longer leaks file ports.
  utils: Add 'go-to-location' with source location caching.
  utils: 'edit-expression' modifies the file only if necessary.
  utils: 'edit-expression' copies part of the original source map.
  Add 'guix style'.

 Makefile.am            |   2 +
 doc/guix.texi          | 174 +++++++++++++--
 gnu/packages/base.scm  |  48 ++---
 gnu/packages/guile.scm | 103 +++------
 gnu/packages/mes.scm   |  25 +--
 guix/lint.scm          |  36 ++++
 guix/packages.scm      | 145 ++++++++++++-
 guix/records.scm       |  65 ++++--
 guix/scripts/style.scm | 475 +++++++++++++++++++++++++++++++++++++++++
 guix/utils.scm         | 151 ++++++++++---
 po/guix/POTFILES.in    |   1 +
 tests/lint.scm         |  14 ++
 tests/packages.scm     |  86 ++++----
 tests/records.scm      |  38 ++++
 tests/style.scm        | 328 ++++++++++++++++++++++++++++
 15 files changed, 1455 insertions(+), 236 deletions(-)
 create mode 100644 guix/scripts/style.scm
 create mode 100644 tests/style.scm


base-commit: d1827d5c636adb395153a4ed6064629ed5b7664b

Comments

Ludovic Courtès June 27, 2021, 11 a.m. UTC | #1
Hi!

Ludovic Courtès <ludo@gnu.org> skribis:

> This patch series does the ground work to remove input labels
> from package definitions.  In other words:
>
>   (package
>     ;; …
>     (inputs `(("libunistring" ,libunistring)
>               ("libffi" ,libffi))))
>
> becomes:
>
>   (package
>     ;; …
>     (inputs (list libunistring libffi)))
>
> Note that it does not change the value returned by ‘package-inputs’
> & co.: that still includes input labels.  Likewise, build-side code
> does not see any difference (there are still input alists).

The 2nd phase of this change (could be a year from now) would be to
remove labels entirely from the API: ‘package-inputs’ and related
procedures would return a label-less list.  We’d most likely keep the
‘%build-inputs’ and ‘inputs’ alists on the build side.

However, this phase will be trickier.  Labels currently serve as an
indirection to implement “virtual dependencies”, as in this example:

  (package
    ;; …
    (arguments '(… (assoc-ref inputs "mpi") …))
    (inputs `(("mpi" ,openmpi))))

Here you can replace ‘openmpi’ with ‘mpich’ or ‘my-custom-openmpi’
(through inheritance or with ‘--with-input’) and the build-side code in
‘arguments’ still behaves as expected.

Once labels have fully disappeared, the build-side ‘inputs’ could only
contain the real package name, so either “openmpi” or “mpich”.

We could replace the build-side ‘assoc-ref’ with host-side code like:

  (package
    ;; …
    (arguments
      (list #:phases
            #~(… #$(lookup-package-input this-package "openmpi") …))))

but again, it depends on the actual package name, so it doesn’t help.

So we need… something else.

I don’t think it’s a showstopper for this patch series, but it does mean
that for the time being one has to know about labels to understand what
happens in package variants.

Ludo’.
Ludovic Courtès June 30, 2021, 8:48 p.m. UTC | #2
Hi!

This is an improved version of this patch series, with the following
changes:

  • ‘guix style’ supports -e/--expression and
    --input-simplification=POLICY.  The latter allows users to ask
    for input simplification even when labels don’t match package
    names (this is useful in obvious cases where there’s a “libX11”
    label for the “libx11” package, for instance.)

  • I changed a few importers to emit simplified package inputs.
    We’ll have to take care of the other importers eventually.

I plan to merge this series by the end of the week on ‘core-updates’.

The plan is to run ‘guix style’ (with no arguments: convert all the
packages as long as that does not involve a rebuild) towards the end
of the ‘core-updates’ cycle so as to minimize merge conflicts.

Thanks,
Ludo’.

Ludovic Courtès (16):
  records: Support field sanitizers.
  packages: Allow inputs to be plain package lists.
  lint: Add 'input-labels' checker.
  packages: Add 'lookup-package-input' & co.
  packages: Add 'modify-inputs'.
  gnu: Change inputs of core packages to plain lists.
  utils: 'edit-expression' no longer leaks file ports.
  utils: Add 'go-to-location' with source location caching.
  utils: 'edit-expression' modifies the file only if necessary.
  utils: 'edit-expression' copies part of the original source map.
  Add 'guix style'.
  packages: 'hidden-package' inherits the original package location.
  import: pypi: Emit new-style package inputs.
  import: cran: Emit new-style package inputs.
  import: print: Emit new-style package inputs when possible.
  import: elpa: Emit new-style package inputs.

 .dir-locals.el         |   6 +
 Makefile.am            |   2 +
 doc/guix.texi          | 208 ++++++++++++++--
 gnu/packages/base.scm  |  48 ++--
 gnu/packages/guile.scm | 103 +++-----
 gnu/packages/mes.scm   |  25 +-
 guix/import/cran.scm   |   8 +-
 guix/import/elpa.scm   |   7 +-
 guix/import/print.scm  |  57 +++--
 guix/import/pypi.scm   |  15 +-
 guix/lint.scm          |  36 +++
 guix/packages.scm      | 146 +++++++++++-
 guix/records.scm       |  65 +++--
 guix/scripts/style.scm | 527 +++++++++++++++++++++++++++++++++++++++++
 guix/utils.scm         | 151 +++++++++---
 po/guix/POTFILES.in    |   1 +
 tests/cran.scm         |  10 +-
 tests/lint.scm         |  14 ++
 tests/packages.scm     |  86 ++++---
 tests/print.scm        |   4 +-
 tests/pypi.scm         |  18 +-
 tests/records.scm      |  38 +++
 tests/style.scm        | 366 ++++++++++++++++++++++++++++
 23 files changed, 1643 insertions(+), 298 deletions(-)
 create mode 100644 guix/scripts/style.scm
 create mode 100644 tests/style.scm


base-commit: 4c0cf61afd5ed62e830f2e87ef6b72505f2c303a