aboutsummaryrefslogtreecommitdiff
path: root/spdxconv.go
diff options
context:
space:
mode:
Diffstat (limited to 'spdxconv.go')
-rw-r--r--spdxconv.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/spdxconv.go b/spdxconv.go
index 466b0ee..778ec51 100644
--- a/spdxconv.go
+++ b/spdxconv.go
@@ -26,6 +26,9 @@ var suffixLicense = `.license`
// SPDXConv the main type for converting files to SPDX format.
type SPDXConv struct {
+ // reuse contains the REUSE.toml configuration.
+ reuse *reuseConfig
+
scm sourceCodeManagement
// curDir contains the current working directory.
@@ -65,6 +68,8 @@ func Scan(path string) (err error) {
return fmt.Errorf(`%s: %w`, logp, err)
}
+ conv.loadReuseConfig()
+
var listFile []string
if conv.name == `` {
listFile, err = conv.scanDir([]string{path})
@@ -218,6 +223,16 @@ func (conv *SPDXConv) loadConfig(dir string) (err error) {
return nil
}
+// loadReuseConfig load the REUSE.toml configuration from current directory.
+func (conv *SPDXConv) loadReuseConfig() {
+ path := filepath.Join(conv.curDir, ReuseConfigFile)
+ var err error
+ conv.reuse, err = loadReuseConfig(path)
+ if err != nil {
+ return
+ }
+}
+
// scanForSCM scan for source-code management (SCM) from directory `dir` until
// the current working directory.
// Currently, only support git.
@@ -267,14 +282,15 @@ func (conv *SPDXConv) scanFile(dir, name string) (listFile []string, err error)
func (conv *SPDXConv) scanDir(listDir []string) (listFile []string, err error) {
var logp = `scanDir`
var commonIgnore = map[string]struct{}{
- `.git`: struct{}{},
- ConfigFile: struct{}{},
- `COPYING`: struct{}{},
- `LICENSE`: struct{}{},
- `LICENSES`: struct{}{}, // Directory contains licenses.
- `node_modules`: struct{}{},
- ReportFile: struct{}{},
- `vendor`: struct{}{},
+ `.git`: struct{}{},
+ ConfigFile: struct{}{},
+ `COPYING`: struct{}{},
+ `LICENSE`: struct{}{},
+ `LICENSES`: struct{}{}, // Directory contains licenses.
+ `node_modules`: struct{}{},
+ ReportFile: struct{}{},
+ ReuseConfigFile: struct{}{},
+ `vendor`: struct{}{},
}
var dir string
@@ -309,6 +325,9 @@ func (conv *SPDXConv) scanDir(listDir []string) (listFile []string, err error) {
if conv.scm.IsIgnored(relpath) {
continue
}
+ if conv.reuse != nil && conv.reuse.isAnnotated(relpath) {
+ continue
+ }
if de.IsDir() {
listDir = append(listDir, relpath)
continue