[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A plan for parameterized packages
From: |
zimoun |
Subject: |
Re: A plan for parameterized packages |
Date: |
Sun, 15 Nov 2020 18:37:33 +0100 |
Hi Lduo,
On Sun, 15 Nov 2020 at 17:33, Ludovic Courtès <ludo@gnu.org> wrote:
> That said, this message is about a possible implementation of package
> parameters, so here we go. :-)
Cool!
> To me the requirements for package parameters are:
>
> 1. it must be possible to discover them and choose them from the UI;
>
> 2. they must contain on-line internationalized documentation such that
> the UI can list a package’s parameters and their type;
Except ’boolean’, which kind of type do you have in mind? Aside that
you did not find examples of packages requiring parameters. ;-)
The answer leads to your point #4.
> 3. the chosen parameters when installing a package in a profile must
> be preserved;
You mean track the parameters with ’properties’ in <profile>/manifest,
right?
> 4. it must be possible to enumerate all the possible values of a
> parameter, and thus to build the Cartesian product of all the
> possible parameter combinations of a package (or of a package
> graph!), so we can test those combinations as much as possible.
The values of the option are therefore known at package time, right?
However, this implies restricted possibility for the type, right?
> Subject: [PATCH 1/4] DRAFT Add (guix parameters).
>
> DRAFT: Missing tests & doc.
>
> * guix/parameters.scm: New file.
> * Makefile.am (MODULES): Add it.
> ---
[...]
> diff --git a/guix/parameters.scm b/guix/parameters.scm
> +
> +;; Type of a package parameter.
> +(define-record-type* <parameter-type> parameter-type
> + make-parameter-type
> + parameter-type?
> + (name parameter-type-name) ;debugging purposes only!
> + (string->value parameter-type-string->value)
> + (value->string parameter-type-value->string)
> + (universe parameter-type-universe))
> +
> +(define boolean
> + ;; The Boolean parameter type.
> + (parameter-type (name 'boolean)
> + (universe '(#true #false))
> + (value->string
> + (match-lambda
> + (#f "false")
> + (#t "true")))
> + (string->value
> + (lambda (str)
> + (cond ((string-ci=? str "true")
> + #t)
> + ((string-ci=? str "false")
> + #f)
> + (else
> + (raise (condition
> + (&message (message "wrong
> value"))))))))))
The types will be “hard-coded“ here, right? Boolean being the simplest
example and imagination just needs to be released, right? :-)
> Subject: [PATCH 2/4] DRAFT transformations: Add '--with-parameter'.
>
> DRAFT: Missing tests & doc.
>
> * guix/transformations.scm (evaluate-parameter-specs)
> (transform-package-parameters): New procedures.
> (%transformations, %transformation-options): Add 'with-parameter'.
> ---
> guix/transformations.scm | 39 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
>
> diff --git a/guix/transformations.scm b/guix/transformations.scm
[...]
> +(define (evaluate-parameter-specs specs proc)
> + "Parse SPECS, a list of strings like \"bitlbee=purple=true\", and return a
> +list of spec/procedure pairs, where (PROC PACKAGE PARAMETER VALUE) is called
> +to return the replacement package. Raise an error if an element of SPECS
> uses
> +invalid syntax, or if a package it refers to could not be found."
> + (map (lambda (spec)
> + (match (string-tokenize spec %not-equal)
> + ((spec name value)
> + (define (replace old)
> + (proc old name value))
> +
> + (cons spec replace))
> + (_
> + (raise
> + (formatted-message
> + (G_ "invalid package parameter specification: ~s")
> + spec)))))
> + specs))
Here ’proc’ could be anything, right? But then…
> +(define (transform-package-parameters replacement-specs)
> + "Return a procedure that, when passed a package, replaces its direct
> +dependencies according to REPLACEMENT-SPECS. REPLACEMENT-SPECS is a list of
> +strings like \"guile-next=stable-3.0\" meaning that packages are built using
> +'guile-next' from the latest commit on its 'stable-3.0' branch."
> + (define (replace old name value)
> + (set-package-parameter-value old name value))
> +
> + (let* ((replacements (evaluate-parameter-specs replacement-specs
> + replace))
> + (rewrite (package-input-rewriting/spec replacements)))
> + (lambda (obj)
> + (if (package? obj)
> + (rewrite obj)
> + obj))))
… it is ’set-package-parameter-value’. It is not clear in my mind.
Does this constrain the hypothetical types?
Cheers,
simon
Re: A plan for parameterized packages,
zimoun <=
Re: A plan for parameterized packages, Taylan Kammer, 2020/11/15
Re: A plan for parameterized packages, Danny Milosavljevic, 2020/11/15
Re: A plan for parameterized packages, raingloom, 2020/11/15