Skip to content

Return declared licence from ParseResult #49

Description

@andrew

ParseResult already carries the package's own Name and Version from the manifest. Most of the same formats also declare a licence in the same document node, and both scancode --package and licensee read it as the primary declared-licence signal.

Proposed fields:

type ParseResult struct {
    // ...
    // Licenses holds the package's declared licence values, verbatim as
    // written in the manifest. Empty when the format has no licence field
    // or none is set. Scalar formats produce a single-element slice.
    Licenses []string
    // LicenseFile is a manifest-relative path to a licence file when the
    // format declares one instead of, or as well as, an expression.
    LicenseFile string
}

Raw values only; callers normalise via github.com/git-pkgs/spdx if they want an SPDX expression. That keeps this package free of the spdx dependency and its regex normaliser.

Formats and their fields:

format licence expression array form licence file
package.json license (string or {type,url}) deprecated licenses: [{type,url}]
Cargo.toml [package].license [package].license-file
pyproject.toml [project].license (PEP 639 string) or {text} [project].classifiers License :: entries [project].license-files, or {file}
setup.cfg / setup.py license classifiers license_files
*.gemspec s.license s.licenses
*.podspec s.license (string or {:type, :file}) :file key
composer.json license (string) license (array)
pom.xml <licenses><license><name> multiple <license> elements <url> when it points at a file
*.nuspec <license type="expression"> <license type="file">
*.cabal license license-file / license-files
DESCRIPTION (R) License: ` `-separated
pubspec.yaml none (Dart uses LICENSE file)
go.mod none
mix.exs licenses: in package/0 list
*.opam license: list
elm.json license
bower.json license array

Cost per manifest is one more field read from a node the parser already decodes; no extra I/O or parse pass. The DSL formats (gemspec, podspec, mix.exs) need one more scrape pattern alongside the existing name/version ones.

Consumers: git pkgs licenses for the declared/detected reconciliation, and git-pkgs/licenses (the scanner) which can read LicenseFile and match its text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions