build

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 25 Imported by: 1

Documentation

Overview

Package build contains configuration structures and functions for building Fuchsia packages.

Package build contains configuration structures and functions for building Fuchsia packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMerkleRootLength = errors.New("decoded merkle root does not contain 32 bytes")

ErrInvalidMerkleRootLength indicates a MerkleRoot string did not contain 32 hex bytes

View Source
var RequiredFiles = []string{"meta/contents", "meta/package"}

RequiredFiles is a list of files that are required before a package can be sealed.

View Source
var TestFiles = []string{"a", "b", "dir/c", "rand1", "rand2", "meta/test/t"}

TestFiles is the list of files created by the default factories in this package.

Functions

func Archive

func Archive(cfg *Config, outputPath string) error

func BuildTestPackage

func BuildTestPackage(cfg *Config)

func Init

func Init(cfg *Config) error

Init initializes package metadata in the output directory. A manifest is generated with a name matching the output directory name.

func Seal

func Seal(cfg *Config) (string, error)

Seal archives meta/ into a FAR archive named meta.far.

func TestPackage

func TestPackage(cfg *Config)

TestPackage initializes a set of files into a package directory next to the config manifest

func Update

func Update(cfg *Config) error

Update walks the contents of the package and updates the merkle root values within the contents file.

func Validate

func Validate(cfg *Config) error

Validate ensures that the package contains the required files.

Types

type BlobInfo

type BlobInfo struct {
	Size uint64 `json:"size"`
}

BlobInfo contains metadata about a single blob

type Config

type Config struct {
	OutputDir      string
	ManifestPath   string
	KeyPath        string
	TempDir        string
	PkgName        string
	PkgVersion     string
	PkgABIRevision uint64
	// contains filtered or unexported fields
}

Config contains global build configuration for other build commands

func NewConfig

func NewConfig() *Config

NewConfig initializes a new configuration with conventional defaults

func TestConfig

func TestConfig() *Config

TestConfig produces a configuration suitable for testing. It creates a temporary directory as a parent of the returned config.OutputDir and config.TempDir. Callers should remove this directory.

func (*Config) BlobInfo

func (c *Config) BlobInfo() ([]PackageBlobInfo, error)

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

InitFlags adds flags to a flagset for altering Config defaults

func (*Config) Manifest

func (c *Config) Manifest() (*Manifest, error)

Manifest initializes and returns the configured manifest. The manifest may be modified during the build process to add/remove files.

func (*Config) MetaFAR

func (c *Config) MetaFAR() string

MetaFAR returns the path to the meta.far that build.Seal generates

func (*Config) MetaFARMerkle

func (c *Config) MetaFARMerkle() string

MetaFARMerkle returns the path to the meta.far.merkle that build.Seal generates

func (*Config) OutputManifest

func (c *Config) OutputManifest() (*PackageManifest, error)

func (*Config) Package

func (c *Config) Package() (pkg.Package, error)

type DeltaBlobStats

type DeltaBlobStats struct {
	Merkle     MerkleRoot       `json:"merkle"`
	Size       uint64           `json:"size"`
	References []PackageFileRef `json:"references"`
}

DeltaBlobStats contains the size of a blob, its hash, and all paths to it from all packages.

type DeltaPackageBlobStats

type DeltaPackageBlobStats struct {
	Merkle MerkleRoot `json:"merkle"`
	Size   uint64     `json:"size"`
	Paths  []string   `json:"paths"`
}

DeltaPackageBlobStats contains the size of a blob, its hash, and all paths to it within a particular package.

func (*DeltaPackageBlobStats) PathsDisplay

func (d *DeltaPackageBlobStats) PathsDisplay() string

PathsDisplay produces a string representation of DeltaPackageBlobStats.Paths suitable for display.

type DeltaPackageStats

type DeltaPackageStats struct {
	Name string `json:"name"`

	DownloadSize  uint64 `json:"download_size"`
	DiscardSize   uint64 `json:"discard_size"`
	UnchangedSize uint64 `json:"unchanged_size"`

	// AddedBlobs contains all blobs included in the target package that do
	// not exist in the source package, reverse sorted by blob size
	AddedBlobs []DeltaPackageBlobStats `json:"added_blobs"`
}

DeltaPackageStats contains statistics for a package update

type ErrInconsistentSnapshotBlobs

type ErrInconsistentSnapshotBlobs struct {
	Merkle MerkleRoot
	Source BlobInfo
	Target BlobInfo
}

ErrInconsistentSnapshotBlobs indicates that two package snapshots contain blobs with the same hash but different metadata. This situation should require a hash collision and be nearly impossible to encounter.

func (ErrInconsistentSnapshotBlobs) Error

Error generates a display string for ErrInconsistentSnapshotBlobs

type ErrInvalidMetaContentsLine

type ErrInvalidMetaContentsLine struct {
	Line string
}

ErrInvalidMetaContentsLine indicates that a line in a meta/contents file was not valid

func (ErrInvalidMetaContentsLine) Error

type ErrRequiredFileMissing

type ErrRequiredFileMissing struct {
	Path string
}

ErrRequiredFileMissing is returned by operations when the operation depends on a file that was not found on disk.

func (ErrRequiredFileMissing) Error

func (e ErrRequiredFileMissing) Error() string

type Manifest

type Manifest struct {
	// Srcs is a set of manifests and/or directories that are the contents of the package
	Srcs []string
	// Paths is the fully computed contents of a package in the form of "destination": "source"
	Paths map[string]string
}

Manifest describes the list of files that are to become the contents of a package

func NewManifest

func NewManifest(paths []string) (*Manifest, error)

NewManifest initializes a manifest from the given paths. If a path is a directory, it is globbed and the manifest includes all unignored files under that directory. If the path is a manifest file, the file is parsed and all files are mapped as described by the manifest file. Manifest files contain lines with "destination=source". Lines that do not match this pattern are ignored.

func (*Manifest) Content

func (m *Manifest) Content() map[string]string

Content returns the list of files from the manifest that are not to be included in the meta.far.

func (*Manifest) Meta

func (m *Manifest) Meta() map[string]string

Meta provides the list of files from the manifest that are to be included in meta.far.

func (*Manifest) Package

func (m *Manifest) Package() (*pkg.Package, error)

Package loads the package descriptor from the package listed in the manifest and returns it.

type MerkleRoot

type MerkleRoot [32]byte

MerkleRoot is the root hash of a merkle tree

func DecodeMerkleRoot

func DecodeMerkleRoot(text []byte) (MerkleRoot, error)

DecodeMerkleRoot attempts to parse a MerkleRoot from a string

func MustDecodeMerkleRoot

func MustDecodeMerkleRoot(s string) MerkleRoot

MustDecodeMerkleRoot parses a MerkleRoot from a string, or panics

func (MerkleRoot) LessThan

func (m MerkleRoot) LessThan(other MerkleRoot) bool

LessThan provides a sort ordering for MerkleRoot

func (MerkleRoot) MarshalText

func (m MerkleRoot) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (MerkleRoot) String

func (m MerkleRoot) String() string

String encodes a MerkleRoot as a lower case 32 byte hex string

func (*MerkleRoot) UnmarshalText

func (m *MerkleRoot) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type MetaContents

type MetaContents map[string]MerkleRoot

MetaContents maps file paths within a package to their content IDs

func LoadMetaContents

func LoadMetaContents(path string) (MetaContents, error)

LoadMetaContents attempts to parse a meta/contents file from disk

func ParseMetaContents

func ParseMetaContents(r io.Reader) (MetaContents, error)

ParseMetaContents attempts to parse a meta/contents file from an io.Reader

func (MetaContents) String

func (m MetaContents) String() string

String serializes the instance in the manifest file format, which could be parsed by ParseMetaContents.

type Package

type Package struct {
	Files map[string]MerkleRoot `json:"files"`
	Tags  []string              `json:"tags,omitempty"`
}

Package contains metadata about a package, including a list of all files in the package

type PackageBlobInfo

type PackageBlobInfo struct {
	// The path of the blob relative to the output directory
	SourcePath string `json:"source_path"`

	// The path within the package
	Path string `json:"path"`

	// Merkle root for the blob
	Merkle MerkleRoot `json:"merkle"`

	// Size of blob, in bytes
	Size uint64 `json:"size"`
}

PackageBlobInfo contains metadata for a single blob in a package

func LoadBlobs

func LoadBlobs(path string) ([]PackageBlobInfo, error)

LoadBlobs attempts to read and parse a blobs manifest from the given path

type PackageFileRef

type PackageFileRef struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

PackageFileRef is a tuple of a package name and a path within that package

func (PackageFileRef) String

func (r PackageFileRef) String() string

type PackageManifest

type PackageManifest struct {
	Version string            `json:"version"`
	Package pkg.Package       `json:"package"`
	Blobs   []PackageBlobInfo `json:"blobs"`
}

PackageManifest is the json structure representation of a full package manifest.

type Snapshot

type Snapshot struct {
	Packages map[string]Package      `json:"packages"`
	Blobs    map[MerkleRoot]BlobInfo `json:"blobs"`
}

Snapshot contains metadata from one or more packages

func LoadSnapshot

func LoadSnapshot(path string) (Snapshot, error)

LoadSnapshot reads and verifies a JSON formatted Snapshot from the provided path.

func ParseSnapshot

func ParseSnapshot(jsonData []byte) (Snapshot, error)

ParseSnapshot deserializes and verifies a JSON formatted Snapshot from the provided data.

func (*Snapshot) AddPackage

func (s *Snapshot) AddPackage(name string, blobs []PackageBlobInfo, tags []string) error

AddPackage adds the metadata for a single package to the given package snapshot, detecting and reporting any inconsistencies with the provided metadata.

func (*Snapshot) Filter

func (s *Snapshot) Filter(include []string, exclude []string) Snapshot

Filter produces a subset of the Snapshot based on a series of include and exclude filters. In order for a package to be included in the result, its tags (including the package name itself) must match at least one include filter and must not match any exclude filters. Include and exclude filters may contain wildcard characters ("*"), which will match 0 or more characters.

func (*Snapshot) Size

func (s *Snapshot) Size() uint64

Size determines the storage required for all blobs in the snapshot (not including block alignment or filesystem overhead).

func (*Snapshot) Verify

func (s *Snapshot) Verify() error

Verify determines if the snapshot is internally consistent. Specifically, it ensures that no package references a blob that does not have metadata and that the snapshot does not contain blob metadata that is not referenced by any package.

type SnapshotDelta

type SnapshotDelta struct {
	DownloadSize  uint64 `json:"download_size"`
	DiscardSize   uint64 `json:"discard_size"`
	UnchangedSize uint64 `json:"unchanged_size"`
	SourceSize    uint64 `json:"source_size"`
	TargetSize    uint64 `json:"target_size"`

	// AddedBlobs contains all blobs included in target that do not exist
	// in source, reverse sorted by blob size
	AddedBlobs []DeltaBlobStats `json:"added_blobs"`

	// Packages contains per-package update statistics, reverse sorted by
	// update size
	Packages []DeltaPackageStats `json:"packages"`
}

SnapshotDelta contains update statistics from one Snapshot to another.

All slices within a snapshot are canonically ordered as follows: 1. Reverse sorted by download size/file size 2. Sorted alphabetically by path/name/merkle

func DeltaSnapshots

func DeltaSnapshots(source Snapshot, target Snapshot) (SnapshotDelta, error)

DeltaSnapshots compares two Snapshots, producing various statistics about an update from source to target

Jump to

Keyboard shortcuts

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