[Exherbo-dev] Providers (and virtuals)

Quentin Glidic sardemff7 at exherbo.org
Tue Feb 18 21:44:37 UTC 2014


Hello Exherbo,

Here is another take on that || ( ) thingy.

You will find attached [any-deps.log] the list of currents (non-virtual) 
|| ( ) dependencies.
It is a light version, I removed from the full list the few cases which 
will disappear in a near future.
All remaining uses (except gcc[ada]) can be solved with the following 
proposal. (We should probably drop the ada option from GCC for know, as 
gnat is ::unwritten so that we cannot install gcc[ada] currently anyway.)

Now let me introduce you “providers”.

Providers is a suboption to select the provider of a feature. Its usage 
is *not* limited to virtuals, they are a special case of package using 
providers.
The attached e-f-s patch should explain the design well enough.

All packages using || ( ) dependencies to let the user choose should use 
providers.

I think we should go in two (or three) steps:
1. Migrate virtuals (cf. attached scripts)
2. Migrate the rest of the || ( ) list
(3. Migrate (“back”) ffmpeg/libav packages, maybe do that with 2.)

Here is the rationale for some design choices:
— Using a suboption avoids name collisions between normal options and 
providers (ffmpeg vs. providers:ffmpeg)
— Having one shared suboption allows to add providers to any package 
without requiring a modification in ::arbor.
— The options’ descriptions: It should be clear what you are enabling 
when you see the option. The option name is a package name, so one can 
simply "cave show" it for a more precise description. Having a shared 
description in a group allows the user to understand which providers are 
about a specific feature in the options summary of a cave resolve. 
Duplicating “Use X as Y feature provider” is IMO counter-productive.

Comments are welcome.

Thanks,

-- 

Quentin “Sardem FF7” Glidic

-------------- next part --------------
A non-text attachment was scrubbed...
Name: any-deps-light.log
Type: text/x-log
Size: 6152 bytes
Desc: not available
URL: <http://lists.exherbo.org/pipermail/exherbo-dev/attachments/20140218/4cba4d78/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-e-f-s-Document-providers-suboption-and-virtuals.patch
Type: text/x-patch
Size: 4691 bytes
Desc: not available
URL: <http://lists.exherbo.org/pipermail/exherbo-dev/attachments/20140218/4cba4d78/attachment-0001.bin>
-------------- next part --------------
#! /bin/bash

usage() {
    cat <<EOF
Usage:
    ${0} <package name> <package version> <package repository> [<package revision>] [OPTIONS...]

Will read the standard input for providers, one per line, using the DEPENDENCIES syntax

Options:
    --header        The full header to use in your file
    --copyright     The copyright to use in your file (with default header)

    --slot          Slot of the virtual
    --platforms     Platforms of the virtual
    --description   Description of the virtual, will be used in SUMMARY and in options’ descriptions

    --myoptions     Additional MYOPTIONS
    --dependencies  Additional DEPENDENCIES
EOF
    exit 0
}

# Defaults
COPYRIGHT="$(date +%Y) <name>"
SUMMARY="Virtual: "
HOMEPAGE=""
SLOT="0"
case "$(uname -m)" in
    x86) PLATFORMS="~x86" ;;
    x86_64) PLATFORMS="~amd64" ;;
esac
MYOPTIONS=""
DEPENDENCIES=""


args=()
while [[ ${#} > 0 ]]; do
    case "${1}" in
        --help|-h) usage ;;

        # Revision
        -r*) revision=${1#-r} ;;

        # Header
        --header) HEADER=${2}; shift ;;
        --copyright) COPYRIGHT=${2}; shift ;;

        # SLOT
        --slot) SLOT=${2}; shift ;;

        # PLATFORMS
        --platforms) PLATFORMS=${2}; shift ;;

        # SUMMARY
        --description) description=${2}; shift ;;

        # MYOPTIONS
        --myoptions) MYOPTIONS=${2}; shift ;;

        # DEPENDENCIES
        --dependencies) DEPENDENCIES=${2}; shift ;;

        *) args+=( "${1}" ) ;;
    esac
    shift
done
set -- "${args[@]}"
name=${1}
version=${2}
repository=${3}
revision=${4}
shift 4

[[ -z "${HEADER}" ]] && HEADER="# Copyright ${COPYRIGHT}
# Distributed under the terms of the GNU General Public License v2"

while read dependency; do
    [[ -z "${dependency}" ]] && continue

    option=${dependency%% *}
    option=${option##*/}
    option=${option%%[*}
    option=${option%%:*}

    PROVIDERS_OPTIONS+="
        ${option}"
    PROVIDERS_DEPENDENCIES+="
    providers:${option}? ( ${dependency} )"
done

PROVIDERS_OPTIONS+=$'\n'
PROVIDERS_DEPENDENCIES+=$'\n'

exheres=${repository}/packages/virtual/${name}/${name}-${version}${revision:+-r}${revision}.exheres-0

mkdir -p $(dirname ${exheres})
cat > ${exheres} <<EOF
${HEADER}

SUMMARY="Virtual: ${description} providers"
HOMEPAGE="${HOMEPAGE}"

SLOT="${SLOT}"
PLATFORMS="${PLATFORMS}"
MYOPTIONS="
    ( providers:${PROVIDERS_OPTIONS}    ) [[
        *description = [ ${description} provider ]
        number-selected = at-least-one
    ]]
${MYOPTIONS}"

DEPENDENCIES="${PROVIDERS_DEPENDENCIES}${DEPENDENCIES}"

EOF
-------------- next part --------------
#! /bin/bash

usage() {
    cat <<EOF
Usage:
    ${0} <package name> <package version> <package repository> [<package revision>] [create-virtual arguments...]
EOF
    exit 0
}

[[ ${1} == --help ]] && usage

name=${1}
version=${2}
repository=${3}
revision=${4#-r}
shift 4

(( new_revision = ${revision} + 1 ))
revision=${revision:+-r}${revision}

spec="virtual/${name}::${repository}[=${version}${revision}]"
dir=${repository}/packages/virtual/${name}
exheres=${name}-${version}${revision}.exheres-0
new_exheres=${name}-${version}-r${new_revision}.exheres-0

description() {
    local d dd l p s
    d="$(cave print-id-metadata --raw-name SUMMARY --format %v ${spec})"

    for p in 'a ' 'virtual ' 'for ' 'providing '; do # strip some prefixes
        dd=${d,,}
        l=${#p}
        [[ "${dd:0:${l}}" == "${p}" ]] && d=${d:${l}}
    done

    for s in ' provider' ' providers'; do # strip some suffixes
        dd=${d,,}
        (( l = ${#d} - ${#s} ))
        [[ "${dd:${l}}" == "${s}" ]] && d=${d:0:${l}}
    done

    echo "${d}"
}

incremental_metadata() {
    local m=${1} d
    d="$(cave print-id-metadata --raw-name ${m} --format %v ${spec})"
    d="${d#( }"
    d="${d% ) \[\[ defined-in = \[ ${exheres} \] \]\]}"
    echo "${d}" | grep -q defined-in && exit 1 # Do not allow virtuals with requires
    echo "${d}" | sed -r \
        -e 's:((\|\| )?\() :\1\n:'\
        -e 's: *([a-z][^ ]+( \[\[( [^ ]+ = (\[[^]]+\]|[^ ]+))+ \]\])?) *:\1\n:g'
}


args=( ${name} ${version} ${repository} ${new_revision} )

args+=( --header "$(sed -n -e '1,/^$/p' ${dir}/${exheres})" )

args+=( --description "$(description)" )
args+=( --homepage "$(cave print-id-metadata --raw-name HOMEPAGE --format %v ${spec})" )

args+=( --slot "$(cave print-id-metadata --raw-name SLOT --format %v ${spec})" )
args+=( --platforms "$(cave print-id-metadata --raw-name PLATFORMS --format %v ${spec})" )


args+=( --myoptions "$(incremental_metadata MYOPTIONS)" )

dependencies="$(incremental_metadata DEPENDENCIES)"
echo "${dependencies}" | grep -q '|| (' || exit 0
DEPENDENCIES="$(echo "${dependencies}" | sed -e '0,/|| (/d' -e '/)/,$d')"
args+=( --dependencies "$(echo "${dependencies}" | sed -e '/|| (/,/)/d')" )

echo "${DEPENDENCIES}" | $(dirname ${0})/create-virtual.bash "${args[@]}" "${@}"
diff -u ${dir}/${exheres} ${dir}/${new_exheres}
-------------- next part --------------
#! /bin/bash
cave print-ids -m virtual/* -f '%p %v %r\n'|grep -v installed|grep -v graveyard|grep -v unavailable|\
while read name full_version repository; do
    version=${full_version%-r*}
    revision=${full_version#${version}}
    ./migrate-virtual.bash ${name} ${version} ${repository} ${revision#-r}
done


More information about the Exherbo-dev mailing list