blob: 7937e23653f618d299bd740053cfaa70b20eaf6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package pkglint
type Toplevel struct {
dir Path
previousSubdir Path
subdirs []Path
}
func CheckdirToplevel(dir Path) {
if trace.Tracing {
defer trace.Call(dir)()
}
ctx := Toplevel{dir, "", nil}
filename := dir + "/Makefile"
mklines := LoadMk(filename, NotEmpty|LogErrors)
if mklines == nil {
return
}
for _, mkline := range mklines.mklines {
if mkline.IsVarassignMaybeCommented() && mkline.Varname() == "SUBDIR" {
ctx.checkSubdir(mkline)
}
}
mklines.Check()
if G.Opts.Recursive {
if G.Opts.CheckGlobal {
G.InterPackage.Enable()
}
G.Todo.PushFront(ctx.subdirs...)
}
}
func (ctx *Toplevel) checkSubdir(mkline *MkLine) {
subdir := NewPath(mkline.Value())
if mkline.IsCommentedVarassign() {
if !mkline.HasComment() || mkline.Comment() == "" {
mkline.Warnf("%q commented out without giving a reason.", subdir)
}
}
if containsVarRef(subdir.String()) || !ctx.dir.JoinNoClean(subdir).JoinNoClean("Makefile").IsFile() {
return
}
prev := ctx.previousSubdir
switch {
case subdir > prev:
// Correctly ordered
case subdir == prev:
mkline.Errorf("Each subdir must only appear once.")
case subdir == "archivers" && prev == "x11":
// This exception is documented in the top-level Makefile.
default:
mkline.Warnf("%s should come before %s.", subdir, prev)
}
ctx.previousSubdir = subdir
if !mkline.IsCommentedVarassign() {
ctx.subdirs = append(ctx.subdirs, joinPath(ctx.dir, subdir))
}
}
|