Documentation
¶
Index ¶
- Constants
- func LabelToDirectory(label string) (string, error)
- func Run(ctx context.Context, config *Config) error
- type Config
- type CustomProjectLicense
- type File
- type FileTree
- type Gn
- type License
- type Licenses
- func (l *Licenses) GetFilesWithBadLicenseUsage() []string
- func (l *Licenses) GetFilesWithProhibitedLicenses() []string
- func (l *Licenses) MatchFile(data []byte, path string, metrics *Metrics) (bool, *License, *Match)
- func (l *Licenses) MatchNoticeFile(data []byte, path string, metrics *Metrics, ft *FileTree)
- func (l *Licenses) MatchSingleLicenseFile(data []byte, path string, metrics *Metrics, ft *FileTree)
- type Match
- type Metrics
- type Output
- type Project
- type UnlicensedFiles
- type UnusedLicenses
- type UsedLicense
Constants ¶
const ( ParserStateLibraryName = iota ParserStateLicense = iota )
Variables ¶
This section is empty.
Functions ¶
func LabelToDirectory ¶
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.
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 NewConfigJson ¶
NewConfigJson allows us to modify the content of the config before using it in tests.
func (*Config) Merge ¶
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 File ¶
type File struct { Name string Path string `json:"path"` Symlink string `json:"symlink"` Parent *FileTree `json:"-"` Licenses []*License `json:"licenses"` }
func (*File) MarshalJSON ¶
Use a custom Marshal function to make Files easier to read in JSON: reduce associated license information down to a string list.
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.
type Gn ¶
type Gn struct {
// contains filtered or unexported fields
}
func NewGn ¶
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 ¶
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 ¶
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 ¶
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 ¶
type Licenses ¶
Licenses is an object that facilitates operations on each License object in bulk.
func NewLicenses ¶
NewLicenses returns a Licenses object with each license pattern loaded from the .lic folder location specified in the config file.
func (*Licenses) GetFilesWithBadLicenseUsage ¶
func (*Licenses) GetFilesWithProhibitedLicenses ¶
func (*Licenses) MatchFile ¶
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 ¶
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.
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 ¶
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"`
}