N3: a Go import set names each package of the import closure, not its module (issue 721)
A module path digested a whole module and brought back the cascade the import set exists to end; ModuleImports reports the import path of every package the build resolved, still with no prefix filter, the standard library and the module's own packages left out. Builds: design 47 H2 H-A-541, H-A-517, H-A-539
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package main
|
||||
|
||||
// The imports step (novox/hq ADR 0593 §2): at a build's end the module says which Go modules the module's Go programs
|
||||
// The imports step (novox/hq ADR 0593 §2): at a build's end the module says which packages the module's Go programs
|
||||
// import, so the indexer can take the fingerprint over the ones a module of the module graph publishes and no other. It
|
||||
// is `go list -deps` of each Go bundle artifact's program and of the packages each Go package artifact's paths hold
|
||||
// (design 47 H2 H-A-532 DQ-5), the tests left out: the module path of every package but the standard library's, with no
|
||||
// prefix telling a mesh module apart (H-A-539: mesh modules come from the seat go-package-registry), and none of the
|
||||
// module's own (its main module, or a module that lies under its own directory, which comes with its tree).
|
||||
// (design 47 H2 H-A-532 DQ-5), the tests left out: the import path of every package of the import closure (H-A-517,
|
||||
// H-A-541) but the standard library's, with no prefix telling a mesh package apart (H-A-539: mesh modules come from the
|
||||
// seat go-package-registry), and none of the module's own (its main module, or a module that lies under its own
|
||||
// directory, which comes with its tree).
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -27,8 +28,8 @@ type ImportsResult struct {
|
||||
func (m *Module) importsTool() StepTool {
|
||||
return StepTool{
|
||||
Name: ImportsTool,
|
||||
Description: "Read the Go modules the Go programs of a module of a fetched workspace import: `go list -deps` of each Go " +
|
||||
"bundle artifact and of the packages each Go package artifact's paths hold, without tests, the module path of every " +
|
||||
Description: "Read the packages the Go programs of a module of a fetched workspace import: `go list -deps` of each Go " +
|
||||
"bundle artifact and of the packages each Go package artifact's paths hold, without tests, the import path of every " +
|
||||
"package but the standard library's and the module's own, sorted and each once. " +
|
||||
"It is what a build says at its end for the fingerprint (ADR 0593 §2). Read-only.",
|
||||
Input: map[string]any{
|
||||
@@ -69,8 +70,8 @@ func (m *Module) imports(ctx context.Context, args map[string]any) (any, error)
|
||||
return ModuleImports(ctx, run, m.buildEnv(dir), dir, manifest)
|
||||
}
|
||||
|
||||
// ModuleImports are the Go modules the Go bundle and package artifacts of manifest, in the module directory dir, import:
|
||||
// one sorted union of module paths (design 47 H2 H-A-518, H-A-539), the standard library, the tests and the module's
|
||||
// ModuleImports are the packages the Go bundle and package artifacts of manifest, in the module directory dir, import:
|
||||
// one sorted union of import paths (design 47 H2 H-A-518, H-A-541), the standard library, the tests and the module's
|
||||
// own left out.
|
||||
func ModuleImports(ctx context.Context, run forgekey.Runner, env []string, dir string, manifest catalogue.Manifest) (ImportsResult, error) {
|
||||
seen := map[string]bool{}
|
||||
@@ -105,7 +106,7 @@ func ModuleImports(ctx context.Context, run forgekey.Runner, env []string, dir s
|
||||
if len(f) != 4 || f[3] == "true" || ownedBy(dir, f[1]) {
|
||||
continue
|
||||
}
|
||||
seen[f[2]] = true
|
||||
seen[f[0]] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
||||
)
|
||||
|
||||
// ADR 0593 §2 (C3), design 47 H2 H-A-539: a fixture whose program imports packages of other Go modules reports the
|
||||
// module path of each, whatever its host (a mesh module comes from the seat go-package-registry, never told apart by a
|
||||
// forge prefix): a sibling module of its own repository and an outside module count, each once; the standard library
|
||||
// (no module), the module's own packages (its main module, or a module under its own directory) and a test's import
|
||||
// (go list runs without -test) are left out.
|
||||
// ADR 0593 §2 (C3), design 47 H2 H-A-517, H-A-539, H-A-541: a fixture whose program imports packages of other Go
|
||||
// modules reports the import path of each package, whatever its host (a mesh module comes from the seat
|
||||
// go-package-registry, never told apart by a forge prefix): a sibling module's package and an outside package count,
|
||||
// each once; the standard library (no module), the module's own packages (its main module, or a module under its own
|
||||
// directory) and a test's import (go list runs without -test) are left out.
|
||||
func TestModuleImportsAreTheModulesItsBuildResolved(t *testing.T) {
|
||||
dir := "/w/ws1/tree/modules/demo"
|
||||
var line string
|
||||
@@ -40,7 +40,8 @@ func TestModuleImportsAreTheModulesItsBuildResolved(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"git.novox.be/novox/mesh-catalog/modules/sibling/lib", "git.novox.be/novox/mesh-sdk/go", "github.com/nats-io/nats.go"}
|
||||
want := []string{"git.novox.be/novox/mesh-catalog/modules/sibling/lib", "git.novox.be/novox/mesh-sdk/go/announce",
|
||||
"git.novox.be/novox/mesh-sdk/go/busstate", "github.com/nats-io/nats.go"}
|
||||
if !slices.Equal(got.Imports, want) {
|
||||
t.Errorf("imports %v, want %v", got.Imports, want)
|
||||
}
|
||||
@@ -64,7 +65,7 @@ func TestImportsStepReadsTheWorkspace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// G2 (design 47 H2 H-A-532 DQ-5, H-A-518, H-A-539): a Go package artifact reports the modules the packages its paths
|
||||
// G2 (design 47 H2 H-A-532 DQ-5, H-A-518, H-A-541): a Go package artifact reports the packages the packages its paths
|
||||
// hold import, listed in the Go module each path is, without tests and without the module's own directory; a module
|
||||
// with both kinds reports one sorted union.
|
||||
func TestAPackageArtifactReportsItsImportSet(t *testing.T) {
|
||||
@@ -84,9 +85,9 @@ func TestAPackageArtifactReportsItsImportSet(t *testing.T) {
|
||||
want []string
|
||||
}{
|
||||
// G2/AC1: a contracts module whose artifact is of kind package.
|
||||
{"package", pkg, []string{"git.novox.be/novox/mesh-sdk/go"}},
|
||||
{"package", pkg, []string{"git.novox.be/novox/mesh-sdk/go/stdio"}},
|
||||
// G2/AC2: a module with a bundle and a package reports one sorted union.
|
||||
{"both", goBundle + "," + pkg, []string{"git.novox.be/novox/mesh-sdk/go", "github.com/nats-io/nats.go"}},
|
||||
{"both", goBundle + "," + pkg, []string{"git.novox.be/novox/mesh-sdk/go/stdio", "github.com/nats-io/nats.go"}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
run := func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
|
||||
|
||||
Reference in New Issue
Block a user