checklicenses

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 25 Imported by: 0

README

The check-licenses tool checks for compliance with Fuchsia's open source policy.

For information regarding Fuchsia's OSS policy, see public documentation at https://fuchsia.dev/fuchsia-src/contribute/governance/policy/open-source-licensing-policies or, for Googlers, http://go/fuchsia-oss-policy.

For information on adding new third party code to Fuchsia, see https://fuchsia.dev/fuchsia-src/contribute/governance/policy/osrb-process.

Support:

  • For policy issues, e.g. regarding compliance, reach out to the contacts listed in the OSS policy docs. Please do not contact the tool owners for legal support.
  • For help resolving common check-licenses errors, see http://go/fuchsia-licenses-playbook.
  • For technical issues with the check-licenses tool, see the OWNERS file.

Run:

$ fx build tools/check-licenses:host
$ fx check-licenses

Test:

$ fx set <PRODUCT>.<BOARD> --with //tools/check-licenses:tests
$ fx test check-licenses

Documentation

Index

Constants

View Source
const (
	ParserStateLibraryName = iota
	ParserStateLicense     = iota
)

Variables

This section is empty.

Functions

func LabelToDirectory

func LabelToDirectory(label string) (string, error)

Converts a GN label string (such as those returned by Dependencies) and strips any target names and toolchains, thereby returning the directory of the label.

func Run

func Run(ctx context.Context, config *Config) error

Run executes the license verification according to the provided config file.

Types

type Config

type Config struct {
	DontSkipDirs []string `json:"dontSkipDirs"`
	SkipDirs     []string `json:"skipDirs"`
	SkipFiles    []string `json:"skipFiles"`

	TextExtensionList       []string `json:"textExtensionList"`
	StrictTextExtensionList []string `json:"strictTextExtensionList"`
	StrictAnalysis          bool     `json:"strictAnalysis"`
	SingleLicenseFiles      []string `json:"singleLicenseFiles"`
	NoticeFiles             []string `json:"noticeFiles"`
	StopLicensePropagation  []string `json:"stopLicensePropagation"`

	ProhibitedLicenseTypes       []string `json:"prohibitedLicenseTypes"`
	ExitOnDirRestrictedLicense   bool     `json:"exitOnDirRestrictedLicense"`
	ExitOnProhibitedLicenseTypes bool     `json:"exitOnProhibitedLicenseTypes"`
	ExitOnUnlicensedFiles        bool     `json:"exitOnUnlicensedFiles"`

	LicensePatternDir     string                 `json:"licensePatternDir"`
	CustomProjectLicenses []CustomProjectLicense `json:"customProjectLicenses"`
	FlutterLicenses       []string               `json:"flutterLicenses"`
	ChromiumLicenses      []string               `json:"chromiumLicenses"`
	NoticeTxtFiles        []string               `json:"noticeTxtFiles"`
	LicenseAllowList      map[string][]string    `json:"licenseAllowList"`

	PrintFiles           bool     `json:"printFiles"`
	PrintProjects        bool     `json:"printProjects"`
	OutputLicenseFile    bool     `json:"outputLicenseFile"`
	OutputFilePrefix     string   `json:"outputFilePrefix"`
	OutputFileExtensions []string `json:"outputFileExtensions"`

	LogLevel    string `json:"logLevel"`
	MaxReadSize int    `json:"maxReadSize"`
	BaseDir     string `json:"baseDir"`
	OutDir      string `json:"outDir"`
	BuildDir    string `json:"buildDir"`
	Target      string `json:"target"`
	GnPath      string `json:"gnPath"`
}

Config values are populated from the the json file at the default or user-specified path

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig returns a config file representing the values found in the json file.

func NewConfigJson

func NewConfigJson(configJson string) (*Config, error)

NewConfigJson allows us to modify the content of the config before using it in tests.

func (*Config) Merge

func (c *Config) Merge(other *Config)

Merge two Config struct objects into one.

  • List fields are concatenated together.
  • boolean fields will be true if either one is true. (left || right)
  • Regular fields will be equal to the left struct field ("c") if it's not equal to the default value ("" for strings, 0 for ints), otherwise they will be set to the right struct field.

type CustomProjectLicense

type CustomProjectLicense struct {
	Name            string
	ProjectRoot     string
	LicenseLocation string
}

type File

type File struct {
	Name     string
	Path     string     `json:"path"`
	Symlink  string     `json:"symlink"`
	Parent   *FileTree  `json:"-"`
	Licenses []*License `json:"licenses"`
}

func NewFile

func NewFile(path string, parent *FileTree) (*File, error)

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

Use a custom Marshal function to make Files easier to read in JSON: reduce associated license information down to a string list.

func (*File) String

func (f *File) String() string

type FileTree

type FileTree struct {
	Name               string                `json:"name"`
	Path               string                `json:"path"`
	SingleLicenseFiles map[string][]*License `json:"project licenses"`
	LicenseMatches     map[string][]*Match   `json:"project license matches"`
	Files              []*File               `json:"files"`
	Children           []*FileTree           `json:"children"`
	Parent             *FileTree             `json:"-"`
	GnTarget           string                `json:"target"`
	StrictAnalysis     bool                  `json:"strict analysis"`

	sync.RWMutex
}

FileTree is an in memory representation of the state of the repository.

func NewFileTree

func NewFileTree(ctx context.Context, root string, parent *FileTree, config *Config, metrics *Metrics) (*FileTree, error)

NewFileTree returns an instance of FileTree, given the input configuration file.

type Gn

type Gn struct {
	// contains filtered or unexported fields
}

func NewGn

func NewGn(ctx context.Context, config *Config) (*Gn, error)

NewGn returns a GN object that is used to interface with the external GN tool. It can be used to discover the dependendcies of a GN target. The path to the external binary is taken from the config argument (config.GnPath.) NewGn will return an error if config.GnPath is not a valid executable, or if config.BuildDir does not exist.

func (*Gn) Dependencies

func (gn *Gn) Dependencies(ctx context.Context, target string) ([]string, error)

Return the dependencies of the given GN target. Calls out to the external GN executable. Dependencies are returned as an array of GN label strings, e.g. //root/dir:target_name(toolchain) Both the target name and toolchain are optional. See https://gn.googlesource.com/gn/+/HEAD/docs/reference.md#labels for more information.

type License

type License struct {
	Category        string `json:"category"`
	ValidType       bool   `json:"valid license"`
	AllowedDirs     []string
	BadLicenseUsage []string

	sync.Mutex
	// contains filtered or unexported fields
}

License contains a searchable regex pattern for finding license text in source files and LICENSE files across the repository.

func NewCustomLicense

func NewCustomLicense(name string) *License

NOTICE files currently need to be processed differently compared to regular single-license files. This custom license type allows us to collect and present them properly in the final output file.

func NewLicense

func NewLicense(path string, config *Config) (*License, error)

NewLicense returns a License object with the regex pattern loaded from the .lic folder. Some preprocessing is done to the pattern (e.g. removing code comment characters).

func (*License) CheckAllowList

func (l *License) CheckAllowList(path string) bool

func (*License) Search

func (l *License) Search(data []byte, file string) (bool, *Match)

Search the given data slice for text that matches this License pattern.

type Licenses

type Licenses struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Licenses is an object that facilitates operations on each License object in bulk.

func NewLicenses

func NewLicenses(ctx context.Context, config *Config) (*Licenses, error)

NewLicenses returns a Licenses object with each license pattern loaded from the .lic folder location specified in the config file.

func (*Licenses) GetFilesWithBadLicenseUsage

func (l *Licenses) GetFilesWithBadLicenseUsage() []string

func (*Licenses) GetFilesWithProhibitedLicenses

func (l *Licenses) GetFilesWithProhibitedLicenses() []string

func (*Licenses) MatchFile

func (l *Licenses) MatchFile(data []byte, path string, metrics *Metrics) (bool, *License, *Match)

MatchFile returns true if any License matches input data along with the license that matched. It returns false and nil if there were no matches.

func (*Licenses) MatchNoticeFile

func (l *Licenses) MatchNoticeFile(data []byte, path string, metrics *Metrics, ft *FileTree)

func (*Licenses) MatchSingleLicenseFile

func (l *Licenses) MatchSingleLicenseFile(data []byte, path string, metrics *Metrics, ft *FileTree)

type Match

type Match struct {
	Copyrights            map[string]bool
	Text                  string
	Projects              []string
	Files                 []string
	LicenseAppliesToFiles []string
	Used                  bool

	sync.RWMutex
}

Match is used to combine Copyright information, license text and the list of files where they occur all in one data struct.

func NewMatch

func NewMatch(data [][]byte, file string, pattern *regexp.Regexp) *Match

NewMatch creates a new match data struct from the result of regex.FindSubMatch().

type Metrics

type Metrics struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Metrics is used for instrumentation

func NewMetrics

func NewMetrics() *Metrics

type Output

type Output struct {
	Unused UnusedLicenses `json:"unused"`
	Used   []UsedLicense  `json:"used"`
}

The following structs are used to serialize data to JSON.

type Project

type Project struct {
	Name               string
	Root               string
	LicenseFiles       []string
	LicenseFileMatches []*Match
}

func NewProjectFromCustomEntry

func NewProjectFromCustomEntry() *Project

func NewProjectFromLicenseFile

func NewProjectFromLicenseFile() *Project

func NewProjectFromReadme

func NewProjectFromReadme() *Project

type UnlicensedFiles

type UnlicensedFiles struct {
	// contains filtered or unexported fields
}

type UnusedLicenses

type UnusedLicenses struct {
	Categories []string `json:"categories"`
}

type UsedLicense

type UsedLicense struct {
	Copyrights []string `json:"copyrights"`
	Category   string   `json:"category"`
	Files      string   `json:"files"`
	Text       string   `json:"text"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL