aboutsummaryrefslogtreecommitdiff
path: root/src/go/build/deps_test.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-08-04 10:12:28 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-08-04 10:12:28 -0700
commitd558507db42d600e5ad82748bda0cb91df57b97d (patch)
tree169457500d42144774eb68c5ab2ef70ad67aa673 /src/go/build/deps_test.go
parentc9f2150cfb3c1db87f6434f727c25403d985a6e4 (diff)
parent85d87b9c7507628144db51bd1e7e80cc3afed128 (diff)
downloadgo-dev.unified.tar.gz
go-dev.unified.zip
[dev.unified] all: merge master (85d87b9) into dev.unifieddev.unified
Merge List: + 2022-08-04 85d87b9c75 all: update vendored golang.org/x dependencies for Go 1.20 development + 2022-08-04 fb1bfd4d37 all: remove pre-Go 1.17 workarounds + 2022-08-04 44ff9bff0c runtime: clean up panic and deadlock lock ranks + 2022-08-04 f42dc0de74 runtime: make the lock rank DAG make more sense + 2022-08-04 d29a0282e9 runtime: add mayAcquire annotation for finlock + 2022-08-04 c5be4ed7df runtime: add missing trace lock edges + 2022-08-04 2b8a9a484f runtime: generate the lock ranking from a DAG description + 2022-08-04 ddfd639408 runtime: delete unused lock ranks + 2022-08-04 426ea5702b internal/dag: add a Graph type and make node order deterministic + 2022-08-04 d37cc9a8cd go/build, internal/dag: lift DAG parser into an internal package + 2022-08-04 ab0a94c6d3 cmd/dist: require Go 1.17 for building Go + 2022-08-04 1e3c19f3fe runtime: support riscv64 SV57 mode + 2022-08-03 f28fa952b5 make.bat, make.rc: show bootstrap toolchain version + 2022-08-03 87384801dc cmd/asm: update package doc to describe "-p" option + 2022-08-03 c6a2dada0d net: disable TestIPv6WriteMsgUDPAddrPortTargetAddrIPVersion [sic] on DragonflyBSD + 2022-08-02 29b9a328d2 runtime: trivial replacements of g in remaining files + 2022-08-02 c647264619 runtime: trivial replacements of g in signal_unix.go + 2022-08-02 399f50c9d7 runtime: tricky replacements of g in traceback.go + 2022-08-02 4509e951ec runtime: tricky replacements of g in proc.go + 2022-08-02 4400238ec8 runtime: trivial replacements of _g_ in remaining files + 2022-08-02 5999a28de8 runtime: trivial replacements of _g_ in os files + 2022-08-02 0e18cf6d09 runtime: trivial replacements of _g_ in GC files + 2022-08-02 4358a53a97 runtime: trivial replacements of _g_ in proc.go + 2022-08-02 b486518964 runtime: tricky replacements of _g_ in os3_solaris.go + 2022-08-02 54a0ab3f7b runtime: tricky replacements of _g_ in os3_plan9.go + 2022-08-02 4240ff764b runtime: tricky replacements of _g_ in signal_windows.go + 2022-08-02 8666d89ca8 runtime: tricky replacements of _g_ in signal_unix.go + 2022-08-02 74cee276fe runtime: tricky replacements of _g_ in trace.go + 2022-08-02 222799fde6 runtime: tricky replacements of _g_ in mgc.go + 2022-08-02 e9d7f54a1a runtime: tricky replacements of _g_ in proc.go + 2022-08-02 5e8d261918 runtime: rename _p_ to pp + 2022-08-02 0ad2ec6596 runtime: clean up dopanic_m + 2022-08-02 7e952962df runtime: clean up canpanic + 2022-08-02 9dbc0f3556 runtime: fix outdated g.m comment in traceback.go + 2022-08-02 d723df76da internal/goversion: update Version to 1.20 + 2022-08-02 1b7e71e8ae all: disable tests that fail on Alpine + 2022-08-01 f2a9f3e2e0 test: improve generic type assertion test + 2022-08-01 27038b70f8 cmd/compile: fix wrong dict pass condition for type assertions + 2022-08-01 e99f53fed9 doc: move Go 1.19 release notes to x/website + 2022-08-01 8b13a073a1 doc: mention removal of cmd/compile's -importmap and -installsuffix flags + 2022-08-01 e95fd4c238 doc/go1.19: fix typo: EM_LONGARCH -> EM_LOONGARCH + 2022-08-01 dee3efd9f8 doc/go1.19: fix a few links that were missing trailing slashes + 2022-07-30 f32519e5fb runtime: fix typos + 2022-07-29 9a2001a8cc cmd/dist: always pass -short=true with -quick + 2022-07-28 5c8ec89cb5 doc/go1.19: minor adjustments and links + 2022-07-28 417be37048 doc/go1.19: improve the loong64 release notes + 2022-07-28 027855e8d8 os/exec: add GODEBUG setting to opt out of ErrDot changes Change-Id: Idc0fbe93978c0dff7600b90a2c3ecc067fd9f5f2
Diffstat (limited to 'src/go/build/deps_test.go')
-rw-r--r--src/go/build/deps_test.go233
1 files changed, 15 insertions, 218 deletions
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index 84cc9de8e7..e5f343a185 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -11,6 +11,7 @@ import (
"bytes"
"fmt"
"go/token"
+ "internal/dag"
"internal/testenv"
"io/fs"
"os"
@@ -29,40 +30,9 @@ import (
// without prior discussion.
// Negative assertions should almost never be removed.
//
-// The general syntax of a rule is:
+// "a < b" means package b can import package a.
//
-// a, b < c, d;
-//
-// which means c and d come after a and b in the partial order
-// (that is, c and d can import a and b),
-// but doesn't provide a relative order between a vs b or c vs d.
-//
-// The rules can chain together, as in:
-//
-// e < f, g < h;
-//
-// which is equivalent to
-//
-// e < f, g;
-// f, g < h;
-//
-// Except for the special bottom element "NONE", each name
-// must appear exactly once on the right-hand side of a rule.
-// That rule serves as the definition of the allowed dependencies
-// for that name. The definition must appear before any uses
-// of the name on the left-hand side of a rule. (That is, the
-// rules themselves must be ordered according to the partial
-// order, for easier reading by people.)
-//
-// Negative assertions double-check the partial order:
-//
-// i !< j
-//
-// means that it must NOT be the case that i < j.
-// Negative assertions may appear anywhere in the rules,
-// even before i and j have been defined.
-//
-// Comments begin with #.
+// See `go doc internal/dag' for the full syntax.
//
// All-caps names are pseudo-names for specific points
// in the dependency lattice.
@@ -177,7 +147,11 @@ var depsRules = `
os/signal, STR
< path/filepath
- < io/ioutil, os/exec;
+ < io/ioutil;
+
+ os < internal/godebug;
+
+ path/filepath, internal/godebug < os/exec;
io/ioutil, os/exec, os/signal
< OS;
@@ -187,8 +161,6 @@ var depsRules = `
OS
< golang.org/x/sys/cpu;
- os < internal/godebug;
-
# FMT is OS (which includes string routines) plus reflect and fmt.
# It does not include package log, which should be avoided in core packages.
strconv, unicode
@@ -206,6 +178,7 @@ var depsRules = `
# Misc packages needing only FMT.
FMT
< html,
+ internal/dag,
internal/goroot,
mime/quotedprintable,
net/internal/socktest,
@@ -624,11 +597,10 @@ func TestDependencies(t *testing.T) {
if sawImport[pkg] == nil {
sawImport[pkg] = map[string]bool{}
}
- ok := policy[pkg]
var bad []string
for _, imp := range imports {
sawImport[pkg][imp] = true
- if !ok[imp] {
+ if !policy.HasEdge(pkg, imp) {
bad = append(bad, imp)
}
}
@@ -697,187 +669,12 @@ func findImports(pkg string) ([]string, error) {
}
// depsPolicy returns a map m such that m[p][d] == true when p can import d.
-func depsPolicy(t *testing.T) map[string]map[string]bool {
- allowed := map[string]map[string]bool{"NONE": {}}
- disallowed := [][2][]string{}
-
- parseDepsRules(t, func(deps []string, op string, users []string) {
- if op == "!<" {
- disallowed = append(disallowed, [2][]string{deps, users})
- return
- }
- for _, u := range users {
- if allowed[u] != nil {
- t.Errorf("multiple deps lists for %s", u)
- }
- allowed[u] = make(map[string]bool)
- for _, d := range deps {
- if allowed[d] == nil {
- t.Errorf("use of %s before its deps list", d)
- }
- allowed[u][d] = true
- }
- }
- })
-
- // Check for missing deps info.
- for _, deps := range allowed {
- for d := range deps {
- if allowed[d] == nil {
- t.Errorf("missing deps list for %s", d)
- }
- }
- }
-
- // Complete transitive allowed deps.
- for k := range allowed {
- for i := range allowed {
- for j := range allowed {
- if i != k && k != j && allowed[i][k] && allowed[k][j] {
- if i == j {
- // Can only happen along with a "use of X before deps" error above,
- // but this error is more specific - it makes clear that reordering the
- // rules will not be enough to fix the problem.
- t.Errorf("deps policy cycle: %s < %s < %s", j, k, i)
- }
- allowed[i][j] = true
- }
- }
- }
- }
-
- // Check negative assertions against completed allowed deps.
- for _, bad := range disallowed {
- deps, users := bad[0], bad[1]
- for _, d := range deps {
- for _, u := range users {
- if allowed[u][d] {
- t.Errorf("deps policy incorrect: assertion failed: %s !< %s", d, u)
- }
- }
- }
- }
-
- if t.Failed() {
- t.FailNow()
- }
-
- return allowed
-}
-
-// parseDepsRules parses depsRules, calling save(deps, op, users)
-// for each deps < users or deps !< users rule
-// (op is "<" or "!<").
-func parseDepsRules(t *testing.T, save func(deps []string, op string, users []string)) {
- p := &depsParser{t: t, lineno: 1, text: depsRules}
-
- var prev []string
- var op string
- for {
- list, tok := p.nextList()
- if tok == "" {
- if prev == nil {
- break
- }
- p.syntaxError("unexpected EOF")
- }
- if prev != nil {
- save(prev, op, list)
- }
- prev = list
- if tok == ";" {
- prev = nil
- op = ""
- continue
- }
- if tok != "<" && tok != "!<" {
- p.syntaxError("missing <")
- }
- op = tok
- }
-}
-
-// A depsParser parses the depsRules syntax described above.
-type depsParser struct {
- t *testing.T
- lineno int
- lastWord string
- text string
-}
-
-// syntaxError reports a parsing error.
-func (p *depsParser) syntaxError(msg string) {
- p.t.Fatalf("deps:%d: syntax error: %s near %s", p.lineno, msg, p.lastWord)
-}
-
-// nextList parses and returns a comma-separated list of names.
-func (p *depsParser) nextList() (list []string, token string) {
- for {
- tok := p.nextToken()
- switch tok {
- case "":
- if len(list) == 0 {
- return nil, ""
- }
- fallthrough
- case ",", "<", "!<", ";":
- p.syntaxError("bad list syntax")
- }
- list = append(list, tok)
-
- tok = p.nextToken()
- if tok != "," {
- return list, tok
- }
- }
-}
-
-// nextToken returns the next token in the deps rules,
-// one of ";" "," "<" "!<" or a name.
-func (p *depsParser) nextToken() string {
- for {
- if p.text == "" {
- return ""
- }
- switch p.text[0] {
- case ';', ',', '<':
- t := p.text[:1]
- p.text = p.text[1:]
- return t
-
- case '!':
- if len(p.text) < 2 || p.text[1] != '<' {
- p.syntaxError("unexpected token !")
- }
- p.text = p.text[2:]
- return "!<"
-
- case '#':
- i := strings.Index(p.text, "\n")
- if i < 0 {
- i = len(p.text)
- }
- p.text = p.text[i:]
- continue
-
- case '\n':
- p.lineno++
- fallthrough
- case ' ', '\t':
- p.text = p.text[1:]
- continue
-
- default:
- i := strings.IndexAny(p.text, "!;,<#\n \t")
- if i < 0 {
- i = len(p.text)
- }
- t := p.text[:i]
- p.text = p.text[i:]
- p.lastWord = t
- return t
- }
+func depsPolicy(t *testing.T) *dag.Graph {
+ g, err := dag.Parse(depsRules)
+ if err != nil {
+ t.Fatal(err)
}
+ return g
}
// TestStdlibLowercase tests that all standard library package names are