Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

license-report: Support prefix #109

Open
hseg opened this issue Jan 9, 2025 · 0 comments
Open

license-report: Support prefix #109

hseg opened this issue Jan 9, 2025 · 0 comments

Comments

@hseg
Copy link

hseg commented Jan 9, 2025

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant