aboutsummaryrefslogtreecommitdiff
path: root/builder/builder2v1/build_file.go
diff options
context:
space:
mode:
Diffstat (limited to 'builder/builder2v1/build_file.go')
-rw-r--r--builder/builder2v1/build_file.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/builder/builder2v1/build_file.go b/builder/builder2v1/build_file.go
new file mode 100644
index 0000000..c7cc6be
--- /dev/null
+++ b/builder/builder2v1/build_file.go
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+
+package builder2v1
+
+import (
+ "fmt"
+ "path/filepath"
+
+ "github.com/spdx/tools-golang/spdx"
+ "github.com/spdx/tools-golang/utils"
+)
+
+// BuildFileSection2_1 creates an SPDX File (version 2.1), returning that
+// file or error if any is encountered. Arguments:
+// - filePath: path to file, relative to prefix
+// - prefix: relative directory for filePath
+// - fileNumber: integer index (unique within package) to use in identifier
+func BuildFileSection2_1(filePath string, prefix string, fileNumber int) (*spdx.File2_1, error) {
+ // build the full file path
+ p := filepath.Join(prefix, filePath)
+
+ // make sure we can get the file and its hashes
+ ssha1, ssha256, smd5, err := utils.GetHashesForFilePath(p)
+ if err != nil {
+ return nil, err
+ }
+
+ // build the identifier
+ i := fmt.Sprintf("SPDXRef-File%d", fileNumber)
+
+ // now build the File section
+ f := &spdx.File2_1{
+ FileName: filePath,
+ FileSPDXIdentifier: i,
+ FileChecksumSHA1: ssha1,
+ FileChecksumSHA256: ssha256,
+ FileChecksumMD5: smd5,
+ LicenseConcluded: "NOASSERTION",
+ LicenseInfoInFile: []string{},
+ FileCopyrightText: "NOASSERTION",
+ }
+
+ return f, nil
+}