Annotation of pkgsrc/pkgtools/pkglint/files/toplevel.go, Revision 1.10
1.1 rillig 1: package main
2:
1.7 rillig 3: import (
4: "netbsd.org/pkglint/trace"
5: )
1.6 rillig 6:
1.1 rillig 7: type Toplevel struct {
8: previousSubdir string
9: subdirs []string
10: }
11:
1.3 rillig 12: func CheckdirToplevel() {
1.6 rillig 13: if trace.Tracing {
14: defer trace.Call1(G.CurrentDir)()
1.3 rillig 15: }
1.1 rillig 16:
17: ctx := new(Toplevel)
1.3 rillig 18: fname := G.CurrentDir + "/Makefile"
1.1 rillig 19:
20: lines := LoadNonemptyLines(fname, true)
21: if lines == nil {
22: return
23: }
24:
25: for _, line := range lines {
1.8 rillig 26: if m, commentedOut, indentation, subdir, comment := match4(line.Text, `^(#?)SUBDIR\s*\+=(\s*)(\S+)\s*(?:#\s*(.*?)\s*|)$`); m {
1.1 rillig 27: ctx.checkSubdir(line, commentedOut == "#", indentation, subdir, comment)
28: }
29: }
30:
1.3 rillig 31: NewMkLines(lines).Check()
1.1 rillig 32:
33: if G.opts.Recursive {
34: if G.opts.CheckGlobal {
1.10 ! rillig 35: G.Pkgsrc.UsedLicenses = make(map[string]bool)
! 36: G.Pkgsrc.Hashes = make(map[string]*Hash)
1.1 rillig 37: }
1.9 rillig 38: G.Todo = append(append([]string(nil), ctx.subdirs...), G.Todo...)
1.1 rillig 39: }
40: }
41:
1.8 rillig 42: func (ctx *Toplevel) checkSubdir(line Line, commentedOut bool, indentation, subdir, comment string) {
1.1 rillig 43: if commentedOut && comment == "" {
1.5 rillig 44: line.Warnf("%q commented out without giving a reason.", subdir)
1.1 rillig 45: }
46:
47: if indentation != "\t" {
1.5 rillig 48: line.Warnf("Indentation should be a single tab character.")
1.1 rillig 49: }
50:
1.3 rillig 51: if contains(subdir, "$") || !fileExists(G.CurrentDir+"/"+subdir+"/Makefile") {
1.1 rillig 52: return
53: }
54:
55: prev := ctx.previousSubdir
56: switch {
57: case subdir > prev:
58: // Correctly ordered
59: case subdir == prev:
1.5 rillig 60: line.Errorf("Each subdir must only appear once.")
1.1 rillig 61: case subdir == "archivers" && prev == "x11":
62: // This exception is documented in the top-level Makefile.
63: default:
1.5 rillig 64: line.Warnf("%s should come before %s", subdir, prev)
1.1 rillig 65: }
66: ctx.previousSubdir = subdir
67:
68: if !commentedOut {
1.3 rillig 69: ctx.subdirs = append(ctx.subdirs, G.CurrentDir+"/"+subdir)
1.1 rillig 70: }
71: }
CVSweb <webmaster@jp.NetBSD.org>