godep

package
v0.0.0-...-0a4d78a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package godep contains description of external dependencies of a Go module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	// contains filtered or unexported fields
}

Deps describes external modules and packages the main module depends on.

It describes a transitive set of external dependencies of a **subset** of the main module (i.e. only some of its packages, not all of them). It is a minimal description needed to construct `go.mod` and `vendor/...` sufficient for compiling this preselected subset of the main module in `-mod=vendor` mode (i.e. without downloading any modules).

Note that the set of packages tracked by Deps is similar to what is produced by `go mod vendor`, except Go vendoring considers all packages in the main module, not a subset of them. This results in suboptimal dependency trees.

Deps is additive: given a Deps representing dependencies of some set of packages in the main module it possible to add more entries to it to cover dependencies of some other package (i.e. we never need to remove anything and we don't need to know all "roots" in advance).

In serialized state Deps is represented by generated `go.mod` and `vendor/modules.txt` files. `go.mod` contains module-level dependencies and `vendor/modules.txt` additionally contains package-level dependencies. They both are needed by `go build` in vendor mode.

Note that the generated `go.mod` is pretty minimal and also not "tidy" at all in terms of `go mod tidy`. It is never going to be used for updating dependencies or even downloading them. It doesn't need extra structure that real tidy `go.mod` files have. Maintaining this structure is non-trivial. Since we aren't downloading anything nor contacting module registry at all, we don't need to worry about `go.sum` either.

func NewDeps

func NewDeps(base *modfile.File) *Deps

NewDeps creates a new empty dependency set.

`base` is the parsed `go.mod` of the main module. It will be used to look up versions of dependencies and other necessary information stored there. It is assumed to be valid.

func (*Deps) Add

func (s *Deps) Add(pkg, mod, goVer string) error

Add records a dependency on a package in a non-main module.

`goVer` is the Go version this module wants, if known. This can be obtained from this module's `go.mod`.

func (*Deps) Load

func (s *Deps) Load(blobs SerializedState) error

Load loads the previously save state to allow extending it.

It expects go.mod and modules.txt as produced by Save, based on the same original `go.mod`.

func (*Deps) Save

func (s *Deps) Save() (SerializedState, error)

Save produces minimal `go.mod` and `modules.txt` with added dependencies.

type SerializedState

type SerializedState struct {
	GoMod      []byte // generated `go.mod` body
	ModulesTxt []byte // generated `vendor/modules.txt` body
}

SerializedState is a pair of generated `go.mod` and `modules.txt`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL