Skip to content

license-report: Support prefix #109

@hseg

Description

@hseg

In trying to figure out how to use license-report for packaging, I've run into
the problem that typically, one wants to write the report to a different path
than where it will end up on the end-user's machine.

In particular, the links to the dependencies' licenses will break if the report
is moved out of licensedir.

Three solutions suggest themselves:

  • Add another path argument prefix that will be prepended to licensedir when
    it comes to writing the dependencies' licenses (i.e. the report will link to
    the licenses as if they're saved under licensedir, but they actually will be
    saved to prefix/licensedir)

  • Use relative paths in the report. To avoid desynchronization, perhaps have
    licensedir imply writing the report to licensedir/$target.md or
    licensedir/index.md?

  • Do nothing, and have the end-user fudge the paths. One possible way to do this
    (note the readarray targets line is due to
    Add a cabal target command haskell/cabal#9744)

    licensedir="$prefix/usr/share/licenses/$pkgname/"
    install -Dm644 LICENSE* -t "$licensedir"
    mkdir "$licensedir/dependencies"
    readarray -t targets < <(jq -r '."install-plan"[] |
        {style, target: (
            ."component-name" +
                if ."component-name" | contains(":")? | not then
                    ":\(."pkg-name")" else "" end)
        } | select(.style == "local") | .target')
    for trg in "${targets[@]}"; do
        tmpprefix="$(mktemp -dp .)"
    
        pushd "$tmpprefix"
        cabal-plan license-report --licensedir . > "$trg.md"
        popd
        # alternatively, if absolute paths are desired
        cabal-plan license-report --licensedir "$tmpprefix" | \
          sed "s#$tmpprefix#/usr/share/licenses/$pkgname/#" \
          > "$tmpprefix/$trg.md"
    done
    cp -r "$tmpprefix"/* "$licensedir"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions