diff options
Diffstat (limited to 'pkgtools/pkglint/files/package.go')
-rw-r--r-- | pkgtools/pkglint/files/package.go | 245 |
1 files changed, 135 insertions, 110 deletions
diff --git a/pkgtools/pkglint/files/package.go b/pkgtools/pkglint/files/package.go index 7029931e883..ec9e3175b97 100644 --- a/pkgtools/pkglint/files/package.go +++ b/pkgtools/pkglint/files/package.go @@ -3,7 +3,6 @@ package pkglint import ( "netbsd.org/pkglint/pkgver" "os" - "path" "strconv" "strings" ) @@ -17,12 +16,12 @@ const rePkgname = `^([\w\-.+]+)-(\d[.0-9A-Z_a-z]*)$` // This is necessary because variables in Makefiles may be used before they are defined, // and such dependencies often span multiple files that are included indirectly. type Package struct { - dir string // The directory of the package, for resolving files - Pkgpath string // e.g. "category/pkgdir" - Pkgdir string // PKGDIR from the package Makefile - Filesdir string // FILESDIR from the package Makefile - Patchdir string // PATCHDIR from the package Makefile - DistinfoFile string // DISTINFO_FILE from the package Makefile + dir Path // The directory of the package, for resolving files + Pkgpath Path // e.g. "category/pkgdir" + Pkgdir Path // PKGDIR from the package Makefile + Filesdir Path // FILESDIR from the package Makefile + Patchdir Path // PATCHDIR from the package Makefile + DistinfoFile Path // DISTINFO_FILE from the package Makefile EffectivePkgname string // PKGNAME or DISTNAME from the package Makefile, including nb13, can be empty EffectivePkgbase string // EffectivePkgname without the version EffectivePkgversion string // The version part of the effective PKGNAME, excluding nb13 @@ -32,7 +31,7 @@ type Package struct { vars Scope redundant *RedundantScope - bl3 map[string]*MkLine // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included. + bl3 map[Path]*MkLine // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included. // Remembers the Makefile fragments that have already been included. // The key to the map is the filename relative to the package directory. @@ -50,21 +49,24 @@ type Package struct { // Files from .include lines that are nested inside .if. // They often depend on OPSYS or on the existence of files in the build environment. - conditionalIncludes map[string]*MkLine + conditionalIncludes map[Path]*MkLine // Files from .include lines that are not nested. // These are cross-checked with buildlink3.mk whether they are unconditional there, too. - unconditionalIncludes map[string]*MkLine + unconditionalIncludes map[Path]*MkLine IgnoreMissingPatches bool // In distinfo, don't warn about patches that cannot be found. Once Once } -func NewPackage(dir string) *Package { +func NewPackage(dir Path) *Package { pkgpath := G.Pkgsrc.ToRel(dir) // Package directory must be two subdirectories below the pkgsrc root. - assert(strings.Count(pkgpath, "/") == 1) + // As of November 2019, it is technically possible to create packages + // on different levels, but that is not used at all. Therefore all + // relative directories are in the form "../../category/package". + assert(pkgpath.Count() == 2) pkg := Package{ dir: dir, @@ -75,10 +77,10 @@ func NewPackage(dir string) *Package { DistinfoFile: "${PKGDIR}/distinfo", // TODO: Redundant, see the vars.Fallback below. Plist: NewPlistContent(), vars: NewScope(), - bl3: make(map[string]*MkLine), + bl3: make(map[Path]*MkLine), included: Once{}, - conditionalIncludes: make(map[string]*MkLine), - unconditionalIncludes: make(map[string]*MkLine), + conditionalIncludes: make(map[Path]*MkLine), + unconditionalIncludes: make(map[Path]*MkLine), } pkg.vars.DefineAll(G.Pkgsrc.UserDefinedVars) @@ -97,7 +99,7 @@ func NewPackage(dir string) *Package { return &pkg } -func (pkg *Package) load() ([]string, *MkLines, *MkLines) { +func (pkg *Package) load() ([]Path, *MkLines, *MkLines) { // Load the package Makefile and all included files, // to collect all used and defined variables and similar data. mklines, allLines := pkg.loadPackageMakefile() @@ -110,21 +112,30 @@ func (pkg *Package) load() ([]string, *MkLines, *MkLines) { files = append(files, dirglob(pkg.File(pkg.Pkgdir))...) } files = append(files, dirglob(pkg.File(pkg.Patchdir))...) - if pkg.DistinfoFile != pkg.vars.fallback["DISTINFO_FILE"] { + if pkg.DistinfoFile != NewPath(pkg.vars.fallback["DISTINFO_FILE"]) { files = append(files, pkg.File(pkg.DistinfoFile)) } + isRelevantMk := func(filename Path, basename string) bool { + if !hasPrefix(basename, "Makefile.") && !filename.HasSuffixText(".mk") { + return false + } + if filename.Dir().Base() == "patches" { + return false + } + if pkg.Pkgdir == "." { + return true + } + return !filename.ContainsPath(pkg.Pkgdir) + } + // Determine the used variables and PLIST directories before checking any of the Makefile fragments. // TODO: Why is this code necessary? What effect does it have? pkg.collectConditionalIncludes(mklines) for _, filename := range files { - basename := path.Base(filename) - if (hasPrefix(basename, "Makefile.") || hasSuffix(filename, ".mk")) && - !matches(filename, `patch-`) && - !contains(filename, pkg.Pkgdir+"/") && - !contains(filename, pkg.Filesdir+"/") { + basename := filename.Base() + if isRelevantMk(filename, basename) { fragmentMklines := LoadMk(filename, MustSucceed) - fragmentMklines.collectUsedVariables() pkg.collectConditionalIncludes(fragmentMklines) } if hasPrefix(basename, "PLIST") { @@ -138,7 +149,7 @@ func (pkg *Package) load() ([]string, *MkLines, *MkLines) { func (pkg *Package) loadPackageMakefile() (*MkLines, *MkLines) { filename := pkg.File("Makefile") if trace.Tracing { - defer trace.Call1(filename)() + defer trace.Call(filename)() } mainLines := LoadMk(filename, NotEmpty|LogErrors) @@ -170,10 +181,10 @@ func (pkg *Package) loadPackageMakefile() (*MkLines, *MkLines) { allLines.collectUsedVariables() - pkg.Pkgdir = pkg.vars.LastValue("PKGDIR") - pkg.DistinfoFile = pkg.vars.LastValue("DISTINFO_FILE") - pkg.Filesdir = pkg.vars.LastValue("FILESDIR") - pkg.Patchdir = pkg.vars.LastValue("PATCHDIR") + pkg.Pkgdir = NewPath(pkg.vars.LastValue("PKGDIR")) + pkg.DistinfoFile = NewPath(pkg.vars.LastValue("DISTINFO_FILE")) + pkg.Filesdir = NewPath(pkg.vars.LastValue("FILESDIR")) + pkg.Patchdir = NewPath(pkg.vars.LastValue("PATCHDIR")) // See lang/php/ext.mk if pkg.vars.IsDefinedSimilar("PHPEXT_MK") { @@ -191,19 +202,19 @@ func (pkg *Package) loadPackageMakefile() (*MkLines, *MkLines) { } if trace.Tracing { - trace.Step1("DISTINFO_FILE=%s", pkg.DistinfoFile) - trace.Step1("FILESDIR=%s", pkg.Filesdir) - trace.Step1("PATCHDIR=%s", pkg.Patchdir) - trace.Step1("PKGDIR=%s", pkg.Pkgdir) + trace.Stepf("DISTINFO_FILE=%s", pkg.DistinfoFile) + trace.Stepf("FILESDIR=%s", pkg.Filesdir) + trace.Stepf("PATCHDIR=%s", pkg.Patchdir) + trace.Stepf("PKGDIR=%s", pkg.Pkgdir) } return mainLines, allLines } // TODO: What is allLines used for, is it still necessary? Would it be better as a field in Package? -func (pkg *Package) parse(mklines *MkLines, allLines *MkLines, includingFileForUsedCheck string) bool { +func (pkg *Package) parse(mklines *MkLines, allLines *MkLines, includingFileForUsedCheck Path) bool { if trace.Tracing { - defer trace.Call1(mklines.lines.Filename)() + defer trace.Call(mklines.lines.Filename)() } result := mklines.ForEachEnd( @@ -217,10 +228,10 @@ func (pkg *Package) parse(mklines *MkLines, allLines *MkLines, includingFileForU // For every included buildlink3.mk, include the corresponding builtin.mk // automatically since the pkgsrc infrastructure does the same. filename := mklines.lines.Filename - if path.Base(filename) == "buildlink3.mk" { - builtin := cleanpath(path.Dir(filename) + "/builtin.mk") + if filename.Base() == "buildlink3.mk" { + builtin := cleanpath(filename.Dir().JoinNoClean("builtin.mk")) builtinRel := relpath(pkg.dir, builtin) - if pkg.included.FirstTime(builtinRel) && fileExists(builtin) { + if pkg.included.FirstTime(builtinRel.String()) && builtin.IsFile() { builtinMkLines := LoadMk(builtin, MustSucceed|LogErrors) pkg.parse(builtinMkLines, allLines, "") } @@ -246,8 +257,8 @@ func (pkg *Package) parseLine(mklines *MkLines, mkline *MkLine, allLines *MkLine return false } - filenameForUsedCheck := "" - dir, base := path.Split(includedFile) + filenameForUsedCheck := NewPath("") + dir, base := includedFile.Split() if dir != "" && base == "Makefile.common" && dir != "../../"+pkg.Pkgpath+"/" { filenameForUsedCheck = includingFile } @@ -276,14 +287,14 @@ func (pkg *Package) parseLine(mklines *MkLines, mkline *MkLine, allLines *MkLine // the included file is not processed further for whatever reason. But if // skip is false, the file could not be read and an appropriate error message // has already been logged. -func (pkg *Package) loadIncluded(mkline *MkLine, includingFile string) (includedMklines *MkLines, skip bool) { +func (pkg *Package) loadIncluded(mkline *MkLine, includingFile Path) (includedMklines *MkLines, skip bool) { includedFile := pkg.resolveIncludedFile(mkline, includingFile) if includedFile == "" { return nil, true } - dirname, _ := path.Split(includingFile) + dirname, _ := includingFile.Split() dirname = cleanpath(dirname) fullIncluded := joinPath(dirname, includedFile) relIncludedFile := relpath(pkg.dir, fullIncluded) @@ -292,14 +303,14 @@ func (pkg *Package) loadIncluded(mkline *MkLine, includingFile string) (included return nil, true } - if !pkg.included.FirstTime(relIncludedFile) { + if !pkg.included.FirstTime(relIncludedFile.String()) { return nil, true } pkg.collectSeenInclude(mkline, includedFile) if trace.Tracing { - trace.Step1("Including %q.", fullIncluded) + trace.Stepf("Including %q.", fullIncluded) } includedMklines = LoadMk(fullIncluded, 0) if includedMklines != nil { @@ -330,7 +341,7 @@ func (pkg *Package) loadIncluded(mkline *MkLine, includingFile string) (included } mkline.Notef("The path to the included file should be %q.", - relpath(path.Dir(mkline.Filename), fullIncludedFallback)) + mkline.PathToFile(fullIncludedFallback)) mkline.Explain( "The .include directive first searches the file relative to the including file.", "And if that doesn't exist, falls back to the current directory, which in the", @@ -344,13 +355,15 @@ func (pkg *Package) loadIncluded(mkline *MkLine, includingFile string) (included // resolveIncludedFile resolves Makefile variables such as ${PKGPATH} to // their actual values. -func (pkg *Package) resolveIncludedFile(mkline *MkLine, includingFilename string) string { +func (pkg *Package) resolveIncludedFile(mkline *MkLine, includingFilename Path) Path { // TODO: resolveVariableRefs uses G.Pkg implicitly. It should be made explicit. // TODO: Try to combine resolveVariableRefs and ResolveVarsInRelativePath. - includedFile := resolveVariableRefs(nil /* XXX: or maybe some mklines? */, mkline.ResolveVarsInRelativePath(mkline.IncludedFile())) - if containsVarRef(includedFile) { - if trace.Tracing && !contains(includingFilename, "/mk/") { + resolved := mkline.ResolveVarsInRelativePath(mkline.IncludedFile()) + includedText := resolveVariableRefs(nil /* XXX: or maybe some mklines? */, resolved.String()) + includedFile := NewPath(includedText) + if containsVarRef(includedText) { + if trace.Tracing && !includingFilename.ContainsPath("mk") { trace.Stepf("%s:%s: Skipping unresolvable include file %q.", mkline.Filename, mkline.Linenos(), includedFile) } @@ -358,10 +371,10 @@ func (pkg *Package) resolveIncludedFile(mkline *MkLine, includingFilename string } if mkline.Basename != "buildlink3.mk" { - if hasSuffix(includedFile, "/buildlink3.mk") { + if includedFile.HasSuffixText("/buildlink3.mk") { pkg.bl3[includedFile] = mkline if trace.Tracing { - trace.Step1("Buildlink3 file in package: %q", includedFile) + trace.Step1("Buildlink3 file in package: %q", includedText) } } } @@ -373,28 +386,31 @@ func (pkg *Package) resolveIncludedFile(mkline *MkLine, includingFilename string // // The includingFile is relative to the current working directory, // the includedFile is taken directly from the .include directive. -func (*Package) shouldDiveInto(includingFile string, includedFile string) bool { +func (*Package) shouldDiveInto(includingFile, includedFile Path) bool { - if hasSuffix(includedFile, "/bsd.pkg.mk") || IsPrefs(includedFile) { + if includedFile.HasSuffixPath("bsd.pkg.mk") || IsPrefs(includedFile) { return false } - if contains(includingFile, "/mk/") && !hasPrefix(G.Pkgsrc.ToRel(includingFile), "wip/mk") { - return hasSuffix(includingFile, "buildlink3.mk") && hasSuffix(includedFile, "builtin.mk") + // FIXME: includingFile may be "../../mk/../devel/readline/buildlink.mk" and thus contain "mk" + // even though the resolved file is not part of the pkgsrc infrastructure. + if includingFile.ContainsPath("mk") && !G.Pkgsrc.ToRel(includingFile).HasPrefixPath("wip/mk") { + // TODO: try ".buildlink.mk", ".builtin.mk" instead, see wip/clfswm. + return includingFile.HasSuffixText("buildlink3.mk") && includedFile.HasSuffixText("builtin.mk") } return true } -func (pkg *Package) collectSeenInclude(mkline *MkLine, includedFile string) { +func (pkg *Package) collectSeenInclude(mkline *MkLine, includedFile Path) { if mkline.Basename != "Makefile" { return } - incDir, incBase := path.Split(includedFile) + incDir, incBase := includedFile.Split() switch { case - hasPrefix(incDir, "../../mk/"), + incDir.HasPrefixPath("../../mk"), incBase == "buildlink3.mk", incBase == "builtin.mk", incBase == "options.mk": @@ -402,7 +418,7 @@ func (pkg *Package) collectSeenInclude(mkline *MkLine, includedFile string) { } if trace.Tracing { - trace.Step1("Including %q sets seenInclude.", includedFile) + trace.Stepf("Including %q sets seenInclude.", includedFile) } pkg.seenInclude = true } @@ -412,22 +428,22 @@ func (pkg *Package) collectConditionalIncludes(mklines *MkLines) { if mkline.IsInclude() { mkline.SetConditionalVars(mklines.indentation.Varnames()) - key := pkg.Rel(mkline.IncludedFileFull()) + includedFile := pkg.Rel(mkline.IncludedFileFull()) if mklines.indentation.IsConditional() { - pkg.conditionalIncludes[key] = mkline + pkg.conditionalIncludes[includedFile] = mkline } else { - pkg.unconditionalIncludes[key] = mkline + pkg.unconditionalIncludes[includedFile] = mkline } } }) } -func (pkg *Package) loadPlistDirs(plistFilename string) { +func (pkg *Package) loadPlistDirs(plistFilename Path) { lines := Load(plistFilename, MustSucceed) ck := PlistChecker{ pkg, - make(map[string]*PlistLine), - make(map[string]*PlistLine), + make(map[Path]*PlistLine), + make(map[Path]*PlistLine), "", Once{}, false} @@ -441,19 +457,19 @@ func (pkg *Package) loadPlistDirs(plistFilename string) { } } -func (pkg *Package) check(filenames []string, mklines, allLines *MkLines) { +func (pkg *Package) check(filenames []Path, mklines, allLines *MkLines) { haveDistinfo := false havePatches := false for _, filename := range filenames { - if containsVarRef(filename) { + if containsVarRef(filename.String()) { if trace.Tracing { trace.Stepf("Skipping file %q because the name contains an unresolved variable.", filename) } continue } - st, err := os.Lstat(filename) + st, err := filename.Lstat() switch { case err != nil: // For a missing custom distinfo file, an error message is already generated @@ -463,7 +479,7 @@ func (pkg *Package) check(filenames []string, mklines, allLines *MkLines) { // since all those files come from calls to dirglob. break - case path.Base(filename) == "Makefile" && strings.Count(G.Pkgsrc.ToRel(filename), "/") == 2: + case filename.HasBase("Makefile") && G.Pkgsrc.ToRel(filename).Count() == 3: G.checkExecutable(filename, st.Mode()) pkg.checkfilePackageMakefile(filename, mklines, allLines) @@ -471,9 +487,9 @@ func (pkg *Package) check(filenames []string, mklines, allLines *MkLines) { pkg.checkDirent(filename, st.Mode()) } - if contains(filename, "/patches/patch-") { + if filename.ContainsText("/patches/patch-") { havePatches = true - } else if hasSuffix(filename, "/distinfo") { + } else if filename.HasSuffixPath("distinfo") { haveDistinfo = true } pkg.checkOwnerMaintainer(filename) @@ -491,9 +507,9 @@ func (pkg *Package) check(filenames []string, mklines, allLines *MkLines) { } } -func (pkg *Package) checkfilePackageMakefile(filename string, mklines *MkLines, allLines *MkLines) { +func (pkg *Package) checkfilePackageMakefile(filename Path, mklines *MkLines, allLines *MkLines) { if trace.Tracing { - defer trace.Call1(filename)() + defer trace.Call(filename)() } vars := pkg.vars @@ -506,12 +522,12 @@ func (pkg *Package) checkfilePackageMakefile(filename string, mklines *MkLines, if !want { distinfoFile := pkg.File(pkg.DistinfoFile) - if fileExists(distinfoFile) { + if distinfoFile.IsFile() { NewLineWhole(distinfoFile).Warnf("This file should not exist since NO_CHECKSUM or META_PACKAGE is set.") } } else { distinfoFile := pkg.File(pkg.DistinfoFile) - if !containsVarRef(distinfoFile) && !fileExists(distinfoFile) { + if !containsVarRef(distinfoFile.String()) && !distinfoFile.IsFile() { line := NewLineWhole(distinfoFile) line.Warnf("A package that downloads files should have a distinfo file.") line.Explain( @@ -554,7 +570,7 @@ func (pkg *Package) checkfilePackageMakefile(filename string, mklines *MkLines, if imake := vars.FirstDefinition("USE_IMAKE"); imake != nil { if x11 := vars.FirstDefinition("USE_X11"); x11 != nil { - if !hasSuffix(x11.Filename, "/mk/x11.buildlink3.mk") { + if !x11.Filename.HasSuffixPath("mk/x11.buildlink3.mk") { imake.Notef("USE_IMAKE makes USE_X11 in %s redundant.", imake.RefTo(x11)) } } @@ -592,8 +608,8 @@ func (pkg *Package) checkPlist() { } needsPlist, line := pkg.needsPlist() - hasPlist := fileExists(pkg.File(pkg.Pkgdir+"/PLIST")) || - fileExists(pkg.File(pkg.Pkgdir+"/PLIST.common")) + hasPlist := pkg.File(pkg.Pkgdir.JoinNoClean("PLIST")).IsFile() || + pkg.File(pkg.Pkgdir.JoinNoClean("/PLIST.common")).IsFile() if needsPlist && !hasPlist { line.Warnf("This package should have a PLIST file.") @@ -966,7 +982,7 @@ func (pkg *Package) checkUseLanguagesCompilerMk(mklines *MkLines) { } handleInclude := func(mkline *MkLine) { - _ = seen.FirstTime(pkg.Rel(mkline.IncludedFileFull())) + _ = seen.FirstTime(pkg.Rel(mkline.IncludedFileFull()).String()) } mklines.ForEach(func(mkline *MkLine) { @@ -1103,7 +1119,7 @@ func (pkg *Package) checkPossibleDowngrade() { change := G.Pkgsrc.LastChange[pkg.Pkgpath] if change == nil { if trace.Tracing { - trace.Step1("No change log for package %q", pkg.Pkgpath) + trace.Stepf("No change log for package %q", pkg.Pkgpath) } return } @@ -1147,44 +1163,51 @@ func (pkg *Package) checkUpdate() { } suggver, comment := sugg.Version, sugg.Comment - if comment != "" { - comment = " (" + comment + ")" + + commentSuffix := func() string { + if comment != "" { + return " (" + comment + ")" + } + return "" } - pkgnameLine := pkg.EffectivePkgnameLine + mkline := pkg.EffectivePkgnameLine cmp := pkgver.Compare(pkg.EffectivePkgversion, suggver) + ref := mkline.RefToLocation(sugg.Line) switch { case cmp < 0: - pkgnameLine.Warnf("This package should be updated to %s%s.", - sugg.Version, comment) - pkgnameLine.Explain( - "The wishlist for package updates in doc/TODO mentions that a newer", - "version of this package is available.") + if comment != "" { + mkline.Warnf("This package should be updated to %s (%s; see %s).", + sugg.Version, comment, ref) + } else { + mkline.Warnf("This package should be updated to %s (see %s).", + sugg.Version, ref) + } case cmp > 0: - pkgnameLine.Notef("This package is newer than the update request to %s%s.", - suggver, comment) + mkline.Notef("This package is newer than the update request to %s%s from %s.", + suggver, commentSuffix(), ref) default: - pkgnameLine.Notef("The update request to %s from doc/TODO%s has been done.", - suggver, comment) + mkline.Notef("The update request to %s%s from %s has been done.", + suggver, commentSuffix(), ref) } } } // checkDirent checks a directory entry based on its filename and its mode // (regular file, directory, symlink). -func (pkg *Package) checkDirent(dirent string, mode os.FileMode) { +func (pkg *Package) checkDirent(dirent Path, mode os.FileMode) { // TODO: merge duplicate code in Pkglint.checkMode - basename := path.Base(dirent) + basename := dirent.Base() switch { case mode.IsRegular(): pkgsrcRel := G.Pkgsrc.ToRel(dirent) - depth := strings.Count(pkgsrcRel, "/") + depth := pkgsrcRel.Count() - 1 // FIXME G.checkReg(dirent, basename, depth) case hasPrefix(basename, "work"): @@ -1197,7 +1220,7 @@ func (pkg *Package) checkDirent(dirent string, mode os.FileMode) { switch { case basename == "files", basename == "patches", - matches(dirent, `(?:^|/)files/[^/]*$`), + dirent.Dir().Base() == "files", isEmptyDir(dirent): break @@ -1219,7 +1242,7 @@ func (pkg *Package) checkDirent(dirent string, mode os.FileMode) { // // Pkglint assumes that the local username is the same as the NetBSD // username, which fits most scenarios. -func (pkg *Package) checkOwnerMaintainer(filename string) { +func (pkg *Package) checkOwnerMaintainer(filename Path) { if trace.Tracing { defer trace.Call(filename)() } @@ -1261,7 +1284,7 @@ func (pkg *Package) checkOwnerMaintainer(filename string) { "keyword \"maintainer\", for more information.") } -func (pkg *Package) checkFreeze(filename string) { +func (pkg *Package) checkFreeze(filename Path) { freezeStart := G.Pkgsrc.LastFreezeStart if freezeStart == "" || G.Pkgsrc.LastFreezeEnd != "" { return @@ -1278,8 +1301,8 @@ func (pkg *Package) checkFreeze(filename string) { "See https://www.NetBSD.org/developers/pkgsrc/ for the exact rules.") } -func (pkg *Package) checkFileMakefileExt(filename string) { - base := path.Base(filename) +func (pkg *Package) checkFileMakefileExt(filename Path) { + base := filename.Base() if !hasPrefix(base, "Makefile.") || base == "Makefile.common" { return } @@ -1313,11 +1336,11 @@ func (pkg *Package) checkLinesBuildlink3Inclusion(mklines *MkLines) { } // Collect all the included buildlink3.mk files from the file. - includedFiles := make(map[string]*MkLine) + includedFiles := make(map[Path]*MkLine) for _, mkline := range mklines.mklines { if mkline.IsInclude() { includedFile := mkline.IncludedFile() - if hasSuffix(includedFile, "/buildlink3.mk") { + if includedFile.HasSuffixPath("buildlink3.mk") { includedFiles[includedFile] = mkline if pkg.bl3[includedFile] == nil { mkline.Warnf("%s is included by this file but not by the package.", includedFile) @@ -1329,7 +1352,7 @@ func (pkg *Package) checkLinesBuildlink3Inclusion(mklines *MkLines) { if trace.Tracing { for packageBl3 := range pkg.bl3 { if includedFiles[packageBl3] == nil { - trace.Step1("%s is included by the package but not by the buildlink3.mk file.", packageBl3) + trace.Stepf("%s is included by the package but not by the buildlink3.mk file.", packageBl3) } } } @@ -1405,8 +1428,10 @@ func (pkg *Package) AutofixDistinfo(oldSha1, newSha1 string) { // File returns the (possibly absolute) path to relativeFileName, // as resolved from the package's directory. // Variables that are known in the package are resolved, e.g. ${PKGDIR}. -func (pkg *Package) File(relativeFileName string) string { - return cleanpath(resolveVariableRefs(nil /* XXX: or maybe some mklines? */, joinPath(pkg.dir, relativeFileName))) +func (pkg *Package) File(relativeFileName Path) Path { + joined := pkg.dir.JoinNoClean(relativeFileName) + resolved := resolveVariableRefs(nil /* XXX: or maybe some mklines? */, joined.String()) + return cleanpath(NewPath(resolved)) } // Rel returns the path by which the given filename (as seen from the @@ -1415,13 +1440,13 @@ func (pkg *Package) File(relativeFileName string) string { // // Example: // NewPackage("category/package").Rel("other/package") == "../../other/package" -func (pkg *Package) Rel(filename string) string { +func (pkg *Package) Rel(filename Path) Path { return relpath(pkg.dir, filename) } // Returns whether the given file (relative to the package directory) // is included somewhere in the package, either directly or indirectly. -func (pkg *Package) Includes(filename string) bool { +func (pkg *Package) Includes(filename Path) bool { return pkg.unconditionalIncludes[filename] != nil || pkg.conditionalIncludes[filename] != nil } @@ -1435,12 +1460,12 @@ func (pkg *Package) Includes(filename string) bool { // 2. Ensure that the entries mentioned in the ALTERNATIVES file // also appear in the PLIST files. type PlistContent struct { - Dirs map[string]*PlistLine - Files map[string]*PlistLine + Dirs map[Path]*PlistLine + Files map[Path]*PlistLine } func NewPlistContent() PlistContent { return PlistContent{ - make(map[string]*PlistLine), - make(map[string]*PlistLine)} + make(map[Path]*PlistLine), + make(map[Path]*PlistLine)} } |