| 1 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// This file exercises the import parser but also checks that |
| 6 |
// some low-level packages do not have new dependencies added. |
| 7 |
|
| 8 |
package build |
| 9 |
|
| 10 |
import ( |
| 11 |
"bytes" |
| 12 |
"fmt" |
| 13 |
"go/token" |
| 14 |
"internal/dag" |
| 15 |
"internal/testenv" |
| 16 |
"io/fs" |
| 17 |
"os" |
| 18 |
"path/filepath" |
| 19 |
"slices" |
| 20 |
"strings" |
| 21 |
"testing" |
| 22 |
) |
| 23 |
|
| 24 |
// depsRules defines the expected dependencies between packages in |
| 25 |
// the Go source tree. It is a statement of policy. |
| 26 |
// |
| 27 |
// DO NOT CHANGE THIS DATA TO FIX BUILDS. |
| 28 |
// Existing packages should not have their constraints relaxed |
| 29 |
// without prior discussion. |
| 30 |
// Negative assertions should almost never be removed. |
| 31 |
// |
| 32 |
// "a < b" means package b can import package a. |
| 33 |
// |
| 34 |
// See `go doc internal/dag` for the full syntax. |
| 35 |
// |
| 36 |
// All-caps names are pseudo-names for specific points |
| 37 |
// in the dependency lattice. |
| 38 |
var depsRules = ` |
| 39 |
# No dependencies allowed for any of these packages. |
| 40 |
NONE |
| 41 |
< unsafe |
| 42 |
< cmp, |
| 43 |
container/list, |
| 44 |
container/ring, |
| 45 |
internal/byteorder, |
| 46 |
internal/cfg, |
| 47 |
internal/coverage, |
| 48 |
internal/coverage/rtcov, |
| 49 |
internal/coverage/uleb128, |
| 50 |
internal/coverage/calloc, |
| 51 |
internal/cpu, |
| 52 |
internal/goarch, |
| 53 |
internal/godebugs, |
| 54 |
internal/goexperiment, |
| 55 |
internal/goos, |
| 56 |
internal/goversion, |
| 57 |
internal/nettrace, |
| 58 |
internal/platform, |
| 59 |
internal/profilerecord, |
| 60 |
internal/syslist, |
| 61 |
internal/trace/tracev2, |
| 62 |
internal/trace/traceviewer/format, |
| 63 |
log/internal, |
| 64 |
math/bits, |
| 65 |
structs, |
| 66 |
unicode, |
| 67 |
unicode/utf8, |
| 68 |
unicode/utf16; |
| 69 |
|
| 70 |
internal/goarch < internal/abi; |
| 71 |
internal/byteorder, internal/cpu, internal/goarch < internal/chacha8rand; |
| 72 |
|
| 73 |
# RUNTIME is the core runtime group of packages, all of them very light-weight. |
| 74 |
internal/abi, |
| 75 |
internal/chacha8rand, |
| 76 |
internal/coverage/rtcov, |
| 77 |
internal/cpu, |
| 78 |
internal/goarch, |
| 79 |
internal/godebugs, |
| 80 |
internal/goexperiment, |
| 81 |
internal/goos, |
| 82 |
internal/profilerecord, |
| 83 |
internal/trace/tracev2, |
| 84 |
math/bits, |
| 85 |
structs |
| 86 |
< internal/bytealg |
| 87 |
< internal/stringslite |
| 88 |
< internal/itoa |
| 89 |
< internal/unsafeheader |
| 90 |
< internal/race |
| 91 |
< internal/msan |
| 92 |
< internal/asan |
| 93 |
< internal/runtime/sys |
| 94 |
< internal/runtime/syscall |
| 95 |
< internal/runtime/atomic |
| 96 |
< internal/runtime/exithook |
| 97 |
< internal/runtime/gc |
| 98 |
< internal/runtime/math |
| 99 |
< internal/runtime/maps |
| 100 |
< internal/runtime/strconv |
| 101 |
< internal/runtime/cgroup |
| 102 |
< runtime |
| 103 |
< sync/atomic |
| 104 |
< internal/sync |
| 105 |
< weak |
| 106 |
< internal/synctest |
| 107 |
< sync |
| 108 |
< internal/bisect |
| 109 |
< internal/godebug |
| 110 |
< internal/reflectlite |
| 111 |
< errors |
| 112 |
< internal/oserror; |
| 113 |
|
| 114 |
cmp, runtime, math/bits |
| 115 |
< iter |
| 116 |
< maps, slices; |
| 117 |
|
| 118 |
internal/oserror, maps, slices |
| 119 |
< RUNTIME; |
| 120 |
|
| 121 |
RUNTIME |
| 122 |
< sort |
| 123 |
< container/heap |
| 124 |
< unique; |
| 125 |
|
| 126 |
RUNTIME |
| 127 |
< io; |
| 128 |
|
| 129 |
RUNTIME |
| 130 |
< arena; |
| 131 |
|
| 132 |
syscall !< io; |
| 133 |
reflect !< sort; |
| 134 |
|
| 135 |
RUNTIME, unicode/utf8 |
| 136 |
< path; |
| 137 |
|
| 138 |
unicode !< path; |
| 139 |
|
| 140 |
# SYSCALL is RUNTIME plus the packages necessary for basic system calls. |
| 141 |
RUNTIME, unicode/utf8, unicode/utf16, internal/synctest |
| 142 |
< internal/syscall/windows/sysdll, syscall/js |
| 143 |
< syscall |
| 144 |
< internal/syscall/unix, internal/syscall/windows, internal/syscall/windows/registry |
| 145 |
< internal/syscall/execenv |
| 146 |
< SYSCALL; |
| 147 |
|
| 148 |
# TIME is SYSCALL plus the core packages about time, including context. |
| 149 |
SYSCALL |
| 150 |
< time/tzdata |
| 151 |
< time |
| 152 |
< context |
| 153 |
< TIME; |
| 154 |
|
| 155 |
TIME, io, path, slices |
| 156 |
< io/fs; |
| 157 |
|
| 158 |
# MATH is RUNTIME plus the basic math packages. |
| 159 |
RUNTIME |
| 160 |
< math |
| 161 |
< MATH; |
| 162 |
|
| 163 |
unicode !< math; |
| 164 |
|
| 165 |
MATH |
| 166 |
< math/cmplx; |
| 167 |
|
| 168 |
MATH |
| 169 |
< math/rand, math/rand/v2; |
| 170 |
|
| 171 |
MATH |
| 172 |
< runtime/metrics; |
| 173 |
|
| 174 |
MATH, unicode/utf8 |
| 175 |
< strconv; |
| 176 |
|
| 177 |
unicode !< strconv; |
| 178 |
|
| 179 |
# STR is basic string and buffer manipulation. |
| 180 |
RUNTIME, io, unicode/utf8, unicode/utf16, unicode |
| 181 |
< bytes, strings |
| 182 |
< bufio; |
| 183 |
|
| 184 |
bufio, path, strconv |
| 185 |
< STR; |
| 186 |
|
| 187 |
# OS is basic OS access, including helpers (path/filepath, os/exec, etc). |
| 188 |
# OS includes string routines, but those must be layered above package os. |
| 189 |
# OS does not include reflection. |
| 190 |
io/fs |
| 191 |
< internal/testlog |
| 192 |
< internal/poll |
| 193 |
< internal/filepathlite |
| 194 |
< os |
| 195 |
< os/signal; |
| 196 |
|
| 197 |
io/fs |
| 198 |
< embed; |
| 199 |
|
| 200 |
unicode, fmt !< net, os, os/signal; |
| 201 |
|
| 202 |
os/signal, internal/filepathlite, STR |
| 203 |
< path/filepath |
| 204 |
< io/ioutil; |
| 205 |
|
| 206 |
path/filepath, internal/godebug < os/exec; |
| 207 |
|
| 208 |
io/ioutil, os/exec, os/signal |
| 209 |
< OS; |
| 210 |
|
| 211 |
reflect !< OS; |
| 212 |
|
| 213 |
OS |
| 214 |
< golang.org/x/sys/cpu; |
| 215 |
|
| 216 |
# FMT is OS (which includes string routines) plus reflect and fmt. |
| 217 |
# It does not include package log, which should be avoided in core packages. |
| 218 |
arena, strconv, unicode |
| 219 |
< reflect; |
| 220 |
|
| 221 |
os, reflect |
| 222 |
< internal/fmtsort |
| 223 |
< fmt; |
| 224 |
|
| 225 |
OS, fmt |
| 226 |
< FMT; |
| 227 |
|
| 228 |
log !< FMT; |
| 229 |
|
| 230 |
# Misc packages needing only FMT. |
| 231 |
FMT |
| 232 |
< html, |
| 233 |
internal/dag, |
| 234 |
internal/goroot, |
| 235 |
internal/types/errors, |
| 236 |
mime/quotedprintable, |
| 237 |
net/internal/socktest, |
| 238 |
runtime/trace, |
| 239 |
text/scanner, |
| 240 |
text/tabwriter; |
| 241 |
|
| 242 |
io, reflect |
| 243 |
< internal/saferio; |
| 244 |
|
| 245 |
# encodings |
| 246 |
# core ones do not use fmt. |
| 247 |
io, strconv, slices |
| 248 |
< encoding, encoding/base32, encoding/base64; |
| 249 |
|
| 250 |
encoding, reflect |
| 251 |
< encoding/binary; |
| 252 |
|
| 253 |
FMT, encoding < flag; |
| 254 |
|
| 255 |
fmt !< encoding/base32, encoding/base64; |
| 256 |
|
| 257 |
FMT, encoding, encoding/base32, encoding/base64, encoding/binary, |
| 258 |
internal/saferio |
| 259 |
< encoding/ascii85, encoding/csv, encoding/gob, encoding/hex, |
| 260 |
encoding/pem, encoding/xml, mime; |
| 261 |
|
| 262 |
STR, errors |
| 263 |
< encoding/json/internal |
| 264 |
< encoding/json/internal/jsonflags |
| 265 |
< encoding/json/internal/jsonopts |
| 266 |
< encoding/json/internal/jsonwire |
| 267 |
< encoding/json/jsontext; |
| 268 |
|
| 269 |
FMT, |
| 270 |
encoding/hex, |
| 271 |
encoding/base32, |
| 272 |
encoding/base64, |
| 273 |
encoding/binary, |
| 274 |
encoding/json/jsontext, |
| 275 |
encoding/json/internal, |
| 276 |
encoding/json/internal/jsonflags, |
| 277 |
encoding/json/internal/jsonopts, |
| 278 |
encoding/json/internal/jsonwire |
| 279 |
< encoding/json/v2 |
| 280 |
< encoding/json; |
| 281 |
|
| 282 |
# hashes |
| 283 |
io |
| 284 |
< hash |
| 285 |
< hash/adler32, hash/crc32, hash/crc64, hash/fnv; |
| 286 |
|
| 287 |
# math/big |
| 288 |
FMT, math/rand |
| 289 |
< math/big; |
| 290 |
|
| 291 |
# compression |
| 292 |
FMT, encoding/binary, hash/adler32, hash/crc32, sort |
| 293 |
< compress/bzip2, compress/flate, compress/lzw, internal/zstd |
| 294 |
< archive/zip, compress/gzip, compress/zlib; |
| 295 |
|
| 296 |
# templates |
| 297 |
FMT |
| 298 |
< text/template/parse; |
| 299 |
|
| 300 |
internal/bytealg, internal/itoa, math/bits, slices, strconv, unique |
| 301 |
< net/netip; |
| 302 |
|
| 303 |
FMT, net/netip |
| 304 |
< net/url; |
| 305 |
|
| 306 |
net/url, text/template/parse |
| 307 |
< text/template |
| 308 |
< internal/lazytemplate; |
| 309 |
|
| 310 |
# regexp |
| 311 |
FMT, sort |
| 312 |
< regexp/syntax |
| 313 |
< regexp |
| 314 |
< internal/lazyregexp; |
| 315 |
|
| 316 |
encoding/json, html, text/template, regexp |
| 317 |
< html/template; |
| 318 |
|
| 319 |
# suffix array |
| 320 |
encoding/binary, regexp |
| 321 |
< index/suffixarray; |
| 322 |
|
| 323 |
# executable parsing |
| 324 |
FMT, encoding/binary, compress/zlib, internal/saferio, internal/zstd, sort |
| 325 |
< runtime/debug |
| 326 |
< debug/dwarf |
| 327 |
< debug/elf, debug/gosym, debug/macho, debug/pe, debug/plan9obj, internal/xcoff |
| 328 |
< debug/buildinfo |
| 329 |
< DEBUG; |
| 330 |
|
| 331 |
# go parser and friends. |
| 332 |
FMT, sort |
| 333 |
< internal/gover |
| 334 |
< go/version |
| 335 |
< go/token |
| 336 |
< go/scanner |
| 337 |
< go/ast |
| 338 |
< go/internal/typeparams; |
| 339 |
|
| 340 |
FMT |
| 341 |
< go/build/constraint; |
| 342 |
|
| 343 |
FMT, sort |
| 344 |
< go/doc/comment; |
| 345 |
|
| 346 |
go/internal/typeparams, go/build/constraint |
| 347 |
< go/parser; |
| 348 |
|
| 349 |
go/doc/comment, go/parser, text/tabwriter |
| 350 |
< go/printer |
| 351 |
< go/format; |
| 352 |
|
| 353 |
math/big, go/token |
| 354 |
< go/constant; |
| 355 |
|
| 356 |
FMT, internal/goexperiment |
| 357 |
< internal/buildcfg; |
| 358 |
|
| 359 |
container/heap, go/constant, go/parser, internal/buildcfg, internal/goversion, internal/types/errors |
| 360 |
< go/types; |
| 361 |
|
| 362 |
# The vast majority of standard library packages should not be resorting to regexp. |
| 363 |
# go/types is a good chokepoint. It shouldn't use regexp, nor should anything |
| 364 |
# that is low-enough level to be used by go/types. |
| 365 |
regexp !< go/types; |
| 366 |
|
| 367 |
go/doc/comment, go/parser, internal/lazyregexp, text/template |
| 368 |
< go/doc; |
| 369 |
|
| 370 |
go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform, internal/syslist |
| 371 |
< go/build; |
| 372 |
|
| 373 |
# databases |
| 374 |
FMT |
| 375 |
< database/sql/internal |
| 376 |
< database/sql/driver; |
| 377 |
|
| 378 |
database/sql/driver, math/rand/v2 < database/sql; |
| 379 |
|
| 380 |
# images |
| 381 |
FMT, compress/lzw, compress/zlib |
| 382 |
< image/color |
| 383 |
< image, image/color/palette |
| 384 |
< image/internal/imageutil |
| 385 |
< image/draw |
| 386 |
< image/gif, image/jpeg, image/png; |
| 387 |
|
| 388 |
# cgo, delayed as long as possible. |
| 389 |
# If you add a dependency on CGO, you must add the package |
| 390 |
# to cgoPackages in cmd/dist/test.go as well. |
| 391 |
RUNTIME |
| 392 |
< C |
| 393 |
< runtime/cgo |
| 394 |
< CGO |
| 395 |
< runtime/msan, runtime/asan; |
| 396 |
|
| 397 |
# runtime/race |
| 398 |
NONE < runtime/race/internal/amd64v1; |
| 399 |
NONE < runtime/race/internal/amd64v3; |
| 400 |
CGO, runtime/race/internal/amd64v1, runtime/race/internal/amd64v3 < runtime/race; |
| 401 |
|
| 402 |
# Bulk of the standard library must not use cgo. |
| 403 |
# The prohibition stops at net and os/user. |
| 404 |
C !< fmt, go/types, CRYPTO-MATH, log/slog; |
| 405 |
|
| 406 |
CGO, OS |
| 407 |
< plugin; |
| 408 |
|
| 409 |
CGO, FMT |
| 410 |
< os/user |
| 411 |
< archive/tar; |
| 412 |
|
| 413 |
sync |
| 414 |
< internal/singleflight; |
| 415 |
|
| 416 |
os |
| 417 |
< golang.org/x/net/dns/dnsmessage, |
| 418 |
golang.org/x/net/lif; |
| 419 |
|
| 420 |
os, net/netip |
| 421 |
< internal/routebsd; |
| 422 |
|
| 423 |
# net is unavoidable when doing any networking, |
| 424 |
# so large dependencies must be kept out. |
| 425 |
# This is a long-looking list but most of these |
| 426 |
# are small with few dependencies. |
| 427 |
CGO, |
| 428 |
golang.org/x/net/dns/dnsmessage, |
| 429 |
golang.org/x/net/lif, |
| 430 |
internal/godebug, |
| 431 |
internal/nettrace, |
| 432 |
internal/poll, |
| 433 |
internal/routebsd, |
| 434 |
internal/singleflight, |
| 435 |
net/netip, |
| 436 |
os, |
| 437 |
sort |
| 438 |
< net; |
| 439 |
|
| 440 |
fmt, unicode !< net; |
| 441 |
math/rand !< net; # net uses runtime instead |
| 442 |
|
| 443 |
# NET is net plus net-helper packages. |
| 444 |
FMT, net |
| 445 |
< net/textproto; |
| 446 |
|
| 447 |
mime, net/textproto, net/url |
| 448 |
< NET; |
| 449 |
|
| 450 |
# logging - most packages should not import; http and up is allowed |
| 451 |
FMT, log/internal |
| 452 |
< log; |
| 453 |
|
| 454 |
log, log/slog !< crypto/tls, database/sql, go/importer, testing; |
| 455 |
|
| 456 |
FMT, log, net |
| 457 |
< log/syslog; |
| 458 |
|
| 459 |
RUNTIME |
| 460 |
< log/slog/internal, log/slog/internal/buffer; |
| 461 |
|
| 462 |
FMT, |
| 463 |
encoding, encoding/json, |
| 464 |
log, log/internal, |
| 465 |
log/slog/internal, log/slog/internal/buffer, |
| 466 |
slices |
| 467 |
< log/slog |
| 468 |
< log/slog/internal/slogtest, log/slog/internal/benchmarks; |
| 469 |
|
| 470 |
NET, log |
| 471 |
< net/mail; |
| 472 |
|
| 473 |
# FIPS is the FIPS 140 module. |
| 474 |
# It must not depend on external crypto packages. |
| 475 |
# Package hash is ok as it's only the interface. |
| 476 |
# See also fips140deps.AllowedInternalPackages. |
| 477 |
|
| 478 |
io, math/rand/v2 < crypto/internal/randutil; |
| 479 |
|
| 480 |
STR < crypto/internal/impl; |
| 481 |
|
| 482 |
OS < crypto/internal/sysrand |
| 483 |
< crypto/internal/entropy; |
| 484 |
|
| 485 |
internal/byteorder < crypto/internal/fips140deps/byteorder; |
| 486 |
internal/cpu, internal/goarch < crypto/internal/fips140deps/cpu; |
| 487 |
internal/godebug < crypto/internal/fips140deps/godebug; |
| 488 |
|
| 489 |
STR, hash, |
| 490 |
crypto/internal/impl, |
| 491 |
crypto/internal/entropy, |
| 492 |
crypto/internal/randutil, |
| 493 |
crypto/internal/fips140deps/byteorder, |
| 494 |
crypto/internal/fips140deps/cpu, |
| 495 |
crypto/internal/fips140deps/godebug |
| 496 |
< crypto/internal/fips140 |
| 497 |
< crypto/internal/fips140/alias |
| 498 |
< crypto/internal/fips140/subtle |
| 499 |
< crypto/internal/fips140/sha256 |
| 500 |
< crypto/internal/fips140/sha512 |
| 501 |
< crypto/internal/fips140/sha3 |
| 502 |
< crypto/internal/fips140/hmac |
| 503 |
< crypto/internal/fips140/check |
| 504 |
< crypto/internal/fips140/pbkdf2 |
| 505 |
< crypto/internal/fips140/aes |
| 506 |
< crypto/internal/fips140/drbg |
| 507 |
< crypto/internal/fips140/aes/gcm |
| 508 |
< crypto/internal/fips140/hkdf |
| 509 |
< crypto/internal/fips140/mlkem |
| 510 |
< crypto/internal/fips140/ssh |
| 511 |
< crypto/internal/fips140/tls12 |
| 512 |
< crypto/internal/fips140/tls13 |
| 513 |
< crypto/internal/fips140/bigmod |
| 514 |
< crypto/internal/fips140/nistec/fiat |
| 515 |
< crypto/internal/fips140/nistec |
| 516 |
< crypto/internal/fips140/ecdh |
| 517 |
< crypto/internal/fips140/ecdsa |
| 518 |
< crypto/internal/fips140/edwards25519/field |
| 519 |
< crypto/internal/fips140/edwards25519 |
| 520 |
< crypto/internal/fips140/ed25519 |
| 521 |
< crypto/internal/fips140/rsa |
| 522 |
< FIPS < crypto/fips140; |
| 523 |
|
| 524 |
crypto !< FIPS; |
| 525 |
|
| 526 |
# CRYPTO is core crypto algorithms - no cgo, fmt, net. |
| 527 |
# Mostly wrappers around the FIPS module. |
| 528 |
|
| 529 |
NONE < crypto/internal/boring/sig, crypto/internal/boring/syso; |
| 530 |
sync/atomic < crypto/internal/boring/bcache; |
| 531 |
|
| 532 |
FIPS, internal/godebug, embed, |
| 533 |
crypto/internal/boring/sig, |
| 534 |
crypto/internal/boring/syso, |
| 535 |
crypto/internal/boring/bcache |
| 536 |
< crypto/internal/fips140only |
| 537 |
< crypto |
| 538 |
< crypto/subtle |
| 539 |
< crypto/sha3 |
| 540 |
< crypto/internal/fips140hash |
| 541 |
< crypto/cipher |
| 542 |
< crypto/internal/boring |
| 543 |
< crypto/boring |
| 544 |
< crypto/aes, |
| 545 |
crypto/des, |
| 546 |
crypto/rc4, |
| 547 |
crypto/md5, |
| 548 |
crypto/sha1, |
| 549 |
crypto/sha256, |
| 550 |
crypto/sha512, |
| 551 |
crypto/hmac, |
| 552 |
crypto/hkdf, |
| 553 |
crypto/pbkdf2, |
| 554 |
crypto/ecdh, |
| 555 |
crypto/mlkem |
| 556 |
< CRYPTO; |
| 557 |
|
| 558 |
CGO, fmt, net !< CRYPTO; |
| 559 |
|
| 560 |
# CRYPTO-MATH is crypto that exposes math/big APIs - no cgo, net; fmt now ok. |
| 561 |
|
| 562 |
CRYPTO, FMT, math/big, internal/saferio |
| 563 |
< crypto/internal/boring/bbig |
| 564 |
< crypto/internal/fips140cache |
| 565 |
< crypto/rand |
| 566 |
< crypto/ed25519 # depends on crypto/rand.Reader |
| 567 |
< encoding/asn1 |
| 568 |
< golang.org/x/crypto/cryptobyte/asn1 |
| 569 |
< golang.org/x/crypto/cryptobyte |
| 570 |
< crypto/dsa, crypto/elliptic, crypto/rsa |
| 571 |
< crypto/ecdsa |
| 572 |
< CRYPTO-MATH; |
| 573 |
|
| 574 |
CGO, net !< CRYPTO-MATH; |
| 575 |
|
| 576 |
# TLS, Prince of Dependencies. |
| 577 |
|
| 578 |
crypto/fips140, sync/atomic < crypto/tls/internal/fips140tls; |
| 579 |
|
| 580 |
crypto/internal/boring/sig, crypto/tls/internal/fips140tls < crypto/tls/fipsonly; |
| 581 |
|
| 582 |
CRYPTO, golang.org/x/sys/cpu, encoding/binary, reflect |
| 583 |
< golang.org/x/crypto/internal/alias |
| 584 |
< golang.org/x/crypto/internal/subtle |
| 585 |
< golang.org/x/crypto/chacha20 |
| 586 |
< golang.org/x/crypto/internal/poly1305 |
| 587 |
< golang.org/x/crypto/chacha20poly1305; |
| 588 |
|
| 589 |
CRYPTO-MATH, NET, container/list, encoding/hex, encoding/pem, |
| 590 |
golang.org/x/crypto/chacha20poly1305, crypto/tls/internal/fips140tls |
| 591 |
< crypto/internal/hpke |
| 592 |
< crypto/x509/internal/macos |
| 593 |
< crypto/x509/pkix |
| 594 |
< crypto/x509 |
| 595 |
< crypto/tls; |
| 596 |
|
| 597 |
# crypto-aware packages |
| 598 |
|
| 599 |
DEBUG, go/build, go/types, text/scanner, crypto/sha256 |
| 600 |
< internal/pkgbits, internal/exportdata |
| 601 |
< go/internal/gcimporter, go/internal/gccgoimporter, go/internal/srcimporter |
| 602 |
< go/importer; |
| 603 |
|
| 604 |
NET, crypto/rand, mime/quotedprintable |
| 605 |
< mime/multipart; |
| 606 |
|
| 607 |
crypto/tls |
| 608 |
< net/smtp; |
| 609 |
|
| 610 |
crypto/rand |
| 611 |
< hash/maphash; # for purego implementation |
| 612 |
|
| 613 |
# HTTP, King of Dependencies. |
| 614 |
|
| 615 |
FMT |
| 616 |
< golang.org/x/net/http2/hpack |
| 617 |
< net/http/internal, net/http/internal/ascii, net/http/internal/testcert; |
| 618 |
|
| 619 |
FMT, NET, container/list, encoding/binary, log |
| 620 |
< golang.org/x/text/transform |
| 621 |
< golang.org/x/text/unicode/norm |
| 622 |
< golang.org/x/text/unicode/bidi |
| 623 |
< golang.org/x/text/secure/bidirule |
| 624 |
< golang.org/x/net/idna |
| 625 |
< golang.org/x/net/http/httpguts, golang.org/x/net/http/httpproxy; |
| 626 |
|
| 627 |
NET, crypto/tls |
| 628 |
< net/http/httptrace; |
| 629 |
|
| 630 |
compress/gzip, |
| 631 |
golang.org/x/net/http/httpguts, |
| 632 |
golang.org/x/net/http/httpproxy, |
| 633 |
golang.org/x/net/http2/hpack, |
| 634 |
net/http/internal, |
| 635 |
net/http/internal/ascii, |
| 636 |
net/http/internal/testcert, |
| 637 |
net/http/httptrace, |
| 638 |
mime/multipart, |
| 639 |
log |
| 640 |
< net/http/internal/httpcommon |
| 641 |
< net/http; |
| 642 |
|
| 643 |
# HTTP-aware packages |
| 644 |
|
| 645 |
encoding/json, net/http |
| 646 |
< expvar; |
| 647 |
|
| 648 |
net/http, net/http/internal/ascii |
| 649 |
< net/http/cookiejar, net/http/httputil; |
| 650 |
|
| 651 |
net/http, flag |
| 652 |
< net/http/httptest; |
| 653 |
|
| 654 |
net/http, regexp |
| 655 |
< net/http/cgi |
| 656 |
< net/http/fcgi; |
| 657 |
|
| 658 |
# Profiling |
| 659 |
FMT, compress/gzip, encoding/binary, sort, text/tabwriter |
| 660 |
< runtime/pprof; |
| 661 |
|
| 662 |
OS, compress/gzip, internal/lazyregexp |
| 663 |
< internal/profile; |
| 664 |
|
| 665 |
html, internal/profile, net/http, runtime/pprof, runtime/trace |
| 666 |
< net/http/pprof; |
| 667 |
|
| 668 |
# RPC |
| 669 |
encoding/gob, encoding/json, go/token, html/template, net/http |
| 670 |
< net/rpc |
| 671 |
< net/rpc/jsonrpc; |
| 672 |
|
| 673 |
# System Information |
| 674 |
bufio, bytes, internal/cpu, io, os, strings, sync |
| 675 |
< internal/sysinfo; |
| 676 |
|
| 677 |
# Test-only |
| 678 |
log |
| 679 |
< testing/iotest |
| 680 |
< testing/fstest; |
| 681 |
|
| 682 |
FMT, flag, math/rand |
| 683 |
< testing/quick; |
| 684 |
|
| 685 |
FMT, DEBUG, flag, runtime/trace, internal/sysinfo, math/rand |
| 686 |
< testing; |
| 687 |
|
| 688 |
log/slog, testing |
| 689 |
< testing/slogtest; |
| 690 |
|
| 691 |
FMT, crypto/sha256, encoding/binary, encoding/json, |
| 692 |
go/ast, go/parser, go/token, |
| 693 |
internal/godebug, math/rand, encoding/hex |
| 694 |
< internal/fuzz; |
| 695 |
|
| 696 |
OS, flag, testing, internal/cfg, internal/platform, internal/goroot |
| 697 |
< internal/testenv; |
| 698 |
|
| 699 |
OS, encoding/base64 |
| 700 |
< internal/obscuretestdata; |
| 701 |
|
| 702 |
CGO, OS, fmt |
| 703 |
< internal/testpty; |
| 704 |
|
| 705 |
NET, testing, math/rand |
| 706 |
< golang.org/x/net/nettest; |
| 707 |
|
| 708 |
syscall |
| 709 |
< os/exec/internal/fdtest; |
| 710 |
|
| 711 |
FMT, sort |
| 712 |
< internal/diff; |
| 713 |
|
| 714 |
FMT |
| 715 |
< internal/txtar; |
| 716 |
|
| 717 |
internal/synctest, testing |
| 718 |
< testing/synctest; |
| 719 |
|
| 720 |
testing |
| 721 |
< internal/testhash; |
| 722 |
|
| 723 |
CRYPTO-MATH, testing, internal/testenv, internal/testhash, encoding/json |
| 724 |
< crypto/internal/cryptotest; |
| 725 |
|
| 726 |
CGO, FMT |
| 727 |
< crypto/internal/sysrand/internal/seccomp; |
| 728 |
|
| 729 |
FIPS |
| 730 |
< crypto/internal/fips140/check/checktest; |
| 731 |
|
| 732 |
# v2 execution trace parser. |
| 733 |
FMT, io, internal/trace/tracev2 |
| 734 |
< internal/trace/version; |
| 735 |
|
| 736 |
FMT, encoding/binary, internal/trace/version |
| 737 |
< internal/trace/raw; |
| 738 |
|
| 739 |
FMT, internal/trace/version, io, sort, encoding/binary |
| 740 |
< internal/trace/internal/tracev1; |
| 741 |
|
| 742 |
FMT, encoding/binary, internal/trace/version, internal/trace/internal/tracev1, container/heap, math/rand |
| 743 |
< internal/trace; |
| 744 |
|
| 745 |
regexp, internal/trace, internal/trace/raw, internal/txtar |
| 746 |
< internal/trace/testtrace; |
| 747 |
|
| 748 |
regexp, internal/txtar, internal/trace, internal/trace/raw |
| 749 |
< internal/trace/internal/testgen; |
| 750 |
|
| 751 |
# cmd/trace dependencies. |
| 752 |
FMT, |
| 753 |
embed, |
| 754 |
encoding/json, |
| 755 |
html/template, |
| 756 |
internal/profile, |
| 757 |
internal/trace, |
| 758 |
internal/trace/traceviewer/format, |
| 759 |
net/http |
| 760 |
< internal/trace/traceviewer; |
| 761 |
|
| 762 |
# Coverage. |
| 763 |
FMT, hash/fnv, encoding/binary, regexp, sort, text/tabwriter, |
| 764 |
internal/coverage, internal/coverage/uleb128 |
| 765 |
< internal/coverage/cmerge, |
| 766 |
internal/coverage/pods, |
| 767 |
internal/coverage/slicereader, |
| 768 |
internal/coverage/slicewriter; |
| 769 |
|
| 770 |
internal/coverage/slicereader, internal/coverage/slicewriter |
| 771 |
< internal/coverage/stringtab |
| 772 |
< internal/coverage/decodecounter, internal/coverage/decodemeta, |
| 773 |
internal/coverage/encodecounter, internal/coverage/encodemeta; |
| 774 |
|
| 775 |
internal/coverage/cmerge |
| 776 |
< internal/coverage/cformat; |
| 777 |
|
| 778 |
internal/coverage, crypto/sha256, FMT |
| 779 |
< cmd/internal/cov/covcmd; |
| 780 |
|
| 781 |
encoding/json, |
| 782 |
runtime/debug, |
| 783 |
internal/coverage/calloc, |
| 784 |
internal/coverage/cformat, |
| 785 |
internal/coverage/decodecounter, internal/coverage/decodemeta, |
| 786 |
internal/coverage/encodecounter, internal/coverage/encodemeta, |
| 787 |
internal/coverage/pods |
| 788 |
< internal/coverage/cfile |
| 789 |
< runtime/coverage; |
| 790 |
|
| 791 |
internal/coverage/cfile, internal/fuzz, internal/testlog, runtime/pprof, regexp |
| 792 |
< testing/internal/testdeps; |
| 793 |
|
| 794 |
# Test-only packages can have anything they want |
| 795 |
FMT, compress/gzip, embed, encoding/binary < encoding/json/internal/jsontest; |
| 796 |
CGO, internal/syscall/unix < net/internal/cgotest; |
| 797 |
FMT < math/big/internal/asmgen; |
| 798 |
|
| 799 |
FMT, testing < internal/cgrouptest; |
| 800 |
` |
| 801 |
|
| 802 |
// listStdPkgs returns the same list of packages as "go list std". |
| 803 |
func listStdPkgs(goroot string) ([]string, error) { |
| 804 |
// Based on cmd/go's matchPackages function. |
| 805 |
var pkgs []string |
| 806 |
|
| 807 |
src := filepath.Join(goroot, "src") + string(filepath.Separator) |
| 808 |
walkFn := func(path string, d fs.DirEntry, err error) error { |
| 809 |
if err != nil || !d.IsDir() || path == src { |
| 810 |
return nil |
| 811 |
} |
| 812 |
|
| 813 |
base := filepath.Base(path) |
| 814 |
if strings.HasPrefix(base, ".") || strings.HasPrefix(base, "_") || base == "testdata" { |
| 815 |
return filepath.SkipDir |
| 816 |
} |
| 817 |
|
| 818 |
name := filepath.ToSlash(path[len(src):]) |
| 819 |
if name == "builtin" || name == "cmd" { |
| 820 |
return filepath.SkipDir |
| 821 |
} |
| 822 |
|
| 823 |
pkgs = append(pkgs, strings.TrimPrefix(name, "vendor/")) |
| 824 |
return nil |
| 825 |
} |
| 826 |
if err := filepath.WalkDir(src, walkFn); err != nil { |
| 827 |
return nil, err |
| 828 |
} |
| 829 |
return pkgs, nil |
| 830 |
} |
| 831 |
|
| 832 |
func TestDependencies(t *testing.T) { |
| 833 |
testenv.MustHaveSource(t) |
| 834 |
|
| 835 |
ctxt := Default |
| 836 |
all, err := listStdPkgs(ctxt.GOROOT) |
| 837 |
if err != nil { |
| 838 |
t.Fatal(err) |
| 839 |
} |
| 840 |
slices.Sort(all) |
| 841 |
|
| 842 |
sawImport := map[string]map[string]bool{} // from package => to package => true |
| 843 |
policy := depsPolicy(t) |
| 844 |
|
| 845 |
for _, pkg := range all { |
| 846 |
imports, err := findImports(pkg) |
| 847 |
if err != nil { |
| 848 |
t.Error(err) |
| 849 |
continue |
| 850 |
} |
| 851 |
if sawImport[pkg] == nil { |
| 852 |
sawImport[pkg] = map[string]bool{} |
| 853 |
} |
| 854 |
var bad []string |
| 855 |
for _, imp := range imports { |
| 856 |
sawImport[pkg][imp] = true |
| 857 |
if !policy.HasEdge(pkg, imp) { |
| 858 |
bad = append(bad, imp) |
| 859 |
} |
| 860 |
} |
| 861 |
if bad != nil { |
| 862 |
t.Errorf("unexpected dependency: %s imports %v", pkg, bad) |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
var buildIgnore = []byte("\n//go:build ignore") |
| 868 |
|
| 869 |
func findImports(pkg string) ([]string, error) { |
| 870 |
vpkg := pkg |
| 871 |
if strings.HasPrefix(pkg, "golang.org") { |
| 872 |
vpkg = "vendor/" + pkg |
| 873 |
} |
| 874 |
dir := filepath.Join(Default.GOROOT, "src", vpkg) |
| 875 |
files, err := os.ReadDir(dir) |
| 876 |
if err != nil { |
| 877 |
return nil, err |
| 878 |
} |
| 879 |
var imports []string |
| 880 |
var haveImport = map[string]bool{} |
| 881 |
if pkg == "crypto/internal/boring" { |
| 882 |
haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports |
| 883 |
} |
| 884 |
fset := token.NewFileSet() |
| 885 |
for _, file := range files { |
| 886 |
name := file.Name() |
| 887 |
if name == "slice_go14.go" || name == "slice_go18.go" { |
| 888 |
// These files are for compiler bootstrap with older versions of Go and not built in the standard build. |
| 889 |
continue |
| 890 |
} |
| 891 |
if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { |
| 892 |
continue |
| 893 |
} |
| 894 |
info := fileInfo{ |
| 895 |
name: filepath.Join(dir, name), |
| 896 |
fset: fset, |
| 897 |
} |
| 898 |
f, err := os.Open(info.name) |
| 899 |
if err != nil { |
| 900 |
return nil, err |
| 901 |
} |
| 902 |
err = readGoInfo(f, &info) |
| 903 |
f.Close() |
| 904 |
if err != nil { |
| 905 |
return nil, fmt.Errorf("reading %v: %v", name, err) |
| 906 |
} |
| 907 |
if info.parsed.Name.Name == "main" { |
| 908 |
continue |
| 909 |
} |
| 910 |
if bytes.Contains(info.header, buildIgnore) { |
| 911 |
continue |
| 912 |
} |
| 913 |
for _, imp := range info.imports { |
| 914 |
path := imp.path |
| 915 |
if !haveImport[path] { |
| 916 |
haveImport[path] = true |
| 917 |
imports = append(imports, path) |
| 918 |
} |
| 919 |
} |
| 920 |
} |
| 921 |
slices.Sort(imports) |
| 922 |
return imports, nil |
| 923 |
} |
| 924 |
|
| 925 |
// depsPolicy returns a map m such that m[p][d] == true when p can import d. |
| 926 |
func depsPolicy(t *testing.T) *dag.Graph { |
| 927 |
g, err := dag.Parse(depsRules) |
| 928 |
if err != nil { |
| 929 |
t.Fatal(err) |
| 930 |
} |
| 931 |
return g |
| 932 |
} |
| 933 |
|
| 934 |
// TestStdlibLowercase tests that all standard library package names are |
| 935 |
// lowercase. See Issue 40065. |
| 936 |
func TestStdlibLowercase(t *testing.T) { |
| 937 |
testenv.MustHaveSource(t) |
| 938 |
|
| 939 |
ctxt := Default |
| 940 |
all, err := listStdPkgs(ctxt.GOROOT) |
| 941 |
if err != nil { |
| 942 |
t.Fatal(err) |
| 943 |
} |
| 944 |
|
| 945 |
for _, pkgname := range all { |
| 946 |
if strings.ToLower(pkgname) != pkgname { |
| 947 |
t.Errorf("package %q should not use upper-case path", pkgname) |
| 948 |
} |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
// TestFindImports tests that findImports works. See #43249. |
| 953 |
func TestFindImports(t *testing.T) { |
| 954 |
imports, err := findImports("go/build") |
| 955 |
if err != nil { |
| 956 |
t.Fatal(err) |
| 957 |
} |
| 958 |
t.Logf("go/build imports %q", imports) |
| 959 |
want := []string{"bytes", "os", "path/filepath", "strings"} |
| 960 |
wantLoop: |
| 961 |
for _, w := range want { |
| 962 |
for _, imp := range imports { |
| 963 |
if imp == w { |
| 964 |
continue wantLoop |
| 965 |
} |
| 966 |
} |
| 967 |
t.Errorf("expected to find %q in import list", w) |
| 968 |
} |
| 969 |
} |