Skip to content

Commit

Permalink
Warn about duplicate DESCR files
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jan 19, 2024
1 parent 79463fa commit 486dfa6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
5 changes: 4 additions & 1 deletion v23/distinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ func (s *Suite) Test_distinfoLinesChecker_checkGlobalDistfileMismatch(c *check.C
"ERROR: ~/category/package1/distinfo:5: "+
"Expected BLAKE2s, SHA512, Size checksums for \"patch-4.2.tar.gz\", got SHA512.",

"WARN: ~/category/package2/DESCR: DESCR file is the same "+
"as \"../../category/package1/DESCR\".",

"ERROR: ~/category/package2/distinfo:3: "+
"Expected BLAKE2s, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.",
"ERROR: ~/category/package2/distinfo:3: "+
Expand All @@ -734,7 +737,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkGlobalDistfileMismatch(c *check.C
"The SHA512 hash for encoding-error.tar.gz contains a non-hex character.",

"WARN: ~/licenses/gnu-gpl-v2: This license seems to be unused.",
"8 errors and 1 warning found.",
"8 errors and 2 warnings found.",
t.Shquote("(Run \"pkglint -e -r -Wall -Call %s\" to show explanations.)", "."))

// Ensure that hex.DecodeString does not waste memory here.
Expand Down
35 changes: 34 additions & 1 deletion v23/pkglint.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkglint

import (
"crypto/sha1"
"fmt"
"github.com/rillig/pkglint/v23/getopt"
"github.com/rillig/pkglint/v23/histogram"
Expand Down Expand Up @@ -635,6 +636,7 @@ func (p *Pkglint) checkReg(filename CurrPath, basename RelPath, depth int, pkg *
case basename.HasPrefixText("DESCR"):
if lines := Load(filename, NotEmpty|LogErrors); lines != nil {
CheckLinesDescr(lines)
G.InterPackage.CheckDuplicateDescr(filename)
}

case basename == "distinfo":
Expand Down Expand Up @@ -864,17 +866,21 @@ func (p *Pkglint) Abs(filename CurrPath) CurrPath {
return filename.Clean()
}

// InterPackage collects data from the inter-package analysis.
// It is most useful when running pkglint on a complete pkgsrc installation.
type InterPackage struct {
hashes map[string]*Hash // Maps "alg:filename" => hash (inter-package check).
usedLicenses map[string]struct{} // Maps "license name" => true (inter-package check).
bl3Names map[string]Location // Maps buildlink3 identifiers to their first occurrence.
descr map[[sha1.Size]byte][]CurrPath
}

func (ip *InterPackage) Enable() {
*ip = InterPackage{
make(map[string]*Hash),
make(map[string]struct{}),
make(map[string]Location)}
make(map[string]Location),
make(map[[sha1.Size]byte][]CurrPath)}

// This is the only license that is added by an infrastructure file,
// mk/djbware.mk. The correct way to handle this situation would be
Expand Down Expand Up @@ -921,3 +927,30 @@ func (ip *InterPackage) Bl3(name string, loc *Location) *Location {
ip.bl3Names[name] = *loc
return nil
}

func (ip *InterPackage) CheckDuplicateDescr(filename CurrPath) {
descr := ip.descr
if descr == nil {
return
}
b, err := os.ReadFile(filename.String())
if err != nil {
return
}
h := sha1.Sum(b)
existing := descr[h]
descr[h] = append(existing, filename)
if len(existing) == 0 {
return
}
line := NewLineWhole(filename)
line.Warnf("DESCR file is the same as %q.",
line.Rel(existing[len(existing)-1]))
line.Explain(
"Each DESCR file should be unique,",
"to help the user choose the most appropriate package.",
"",
"If two packages really need the exact same DESCR file,",
"create a single DESCR file for both",
"and refer to it via DESCR_SRC.")
}
2 changes: 2 additions & 0 deletions v23/pkglint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,8 @@ func (s *Suite) Test_InterPackage_Bl3__same_identifier(c *check.C) {
"can be replaced with the simpler \"S,^,,\".",
"NOTE: category/package1/Makefile:4: The modifier \"@v@${v}@\" "+
"can be replaced with the simpler \"=\".",
"WARN: category/package2/DESCR: DESCR file is "+
"the same as \"../../category/package1/DESCR\".",
"NOTE: category/package2/Makefile:4: The modifier \"@v@${v}@\" "+
"can be replaced with the simpler \"S,^,,\".",
"NOTE: category/package2/Makefile:4: The modifier \"@v@${v}@\" "+
Expand Down
4 changes: 3 additions & 1 deletion v23/pkgsrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,12 @@ func (s *Suite) Test_Pkgsrc_checkToplevelUnusedLicenses(c *check.C) {
t.Main("-r", "-Cglobal", ".")

t.CheckOutputLines(
"WARN: ~/category/package2/DESCR: DESCR file is the same "+
"as \"../../category/package/DESCR\".",
"ERROR: ~/category/package2/Makefile:11: License file ../../licenses/missing does not exist.",
"WARN: ~/licenses/gnu-gpl-v2: This license seems to be unused.", // Added by Tester.SetUpPkgsrc
"WARN: ~/licenses/gnu-gpl-v3: This license seems to be unused.",
"1 error and 2 warnings found.",
"1 error and 3 warnings found.",
t.Shquote("(Run \"pkglint -e -r -Cglobal %s\" to show explanations.)", "."))
}

Expand Down

0 comments on commit 486dfa6

Please sign in to comment.