profiles

package
v0.0.0-...-abfb8b1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: BSD-3-Clause Imports: 16 Imported by: 9

README

Profiles

Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager. A profile is a named collection of software required for a given system component or application. The name of the profile refers to all of the required software, which may a single library or a collection of libraries or SDKs. Current example profiles include 'syncbase' which consists of the leveldb and snappy libraries or 'android' which consists of all of the android components and downloads needed to build android applications.

Targets

Profiles generally refer to uncompiled source code that needs to be compiled for a specific "target". Targets hence represent compiled code and consist of:

  1. A 'tag' that can be used a short hand for refering to a target
  2. An 'architecture' that refers to the CPU to be generate code for
  3. An 'operating system' that refers to the operating system to generate code for
  4. An 'environment' which is a set of environment variables to use when compiling the profile

Targets thus provide the basic support needed for cross compilation.

The Supported Commands

Profiles may be installed, updated or removed. When doing so, the name of the profile is required, but the other components of the target are optional and will default to the values of the system that the commands are run on (so-called native builds). Once a profile is installed it may be referred to by its tag for subsequent updates and removals.

Adding Profiles

Profiles are intended to be provided as go packages that register themselves with the profile command line tools via the v.io/jiri/profiles package. They must implement the interfaces defined by that package and be imported (e.g. import _ "myprofile") by the command line tools that are to use them.

The Manifest

The profiles package manages a manifest that tracks the installed profiles and their configurations. Other command line tools and packages are expected to read information about the currently installed profiles from this manifest via the profiles package.

Documentation

Overview

Package profiles and its subdirectoris implement support for managing external sofware dependencies. They offer a balance between providing no support at all and a full blown package manager. A profile is a named collection of software required for a given system component or application. The name of the profile refers to all of the required software, which may a single library or a collection of libraries or SDKs. Profiles thus refer to uncompiled source code that needs to be compiled for a specific "target". Targets represent compiled code and consist of:

1. An 'architecture' that refers to the CPU to be generate code for.

2. An 'operating system' that refers to the operating system to generate code for.

3. An 'environment' which is a set of environment variables to use when compiling and using the profile.

Targets provide the essential support for cross compilation.

The profiles package provides the data types to support its sub-packages, including a database format (in XML) that is used to store the state of the currently installed profiles.

The profilesmanager sub-package provides a registry for profile implementations to register themselves (by calling manager.Register from an init function for example).

The profilesreader sub-package provides support for reading the profiles database and performing common operations on it. profiles/commandline provides an easy to use command line environment for tools that need to read and/or write profiles.

The profilescmdline sub-package provides support for implementing command line clients that implement profile installation and for reading profile information. It also provides support for invoking sub-commands to manage families of profiles which uses the notion of a 'qualified' profile name where the profile name includes a prefix (separated by InstallSeparator) which identifies the sub-command responsible for managing that profile.

The profilesutil sub-package provides some utility routines intended for use by profile implementers.

Profiles may be installed, updated or removed. When doing so, the name of the profile is required, but the other components of the target are optional and will default to the values of the system that the commands are run on (so-called native builds). These operations are defined by the profiles/manager.Manager interface.

Index

Constants

View Source
const InstallerSeparator = ":"

InstallerSeparator is the string used to separate the installer and profile name for qualified profile names.

Variables

This section is empty.

Functions

func QualifiedProfileName

func QualifiedProfileName(installer, name string) string

QualifiedProfileName returns the name of a profile qualified by the name of its installer, if any. If the installer is "myproject" and the profile name is "bar" then then returned string is "myproject" + InstallerSeparator + "bar". If the installer is not specified then the unqualified name, without InstallerSeparator is returned. If the supplied name is already qualified then the existing qualifier will be removed and the supplied one used instead. Any leading colons in name will be stripped.

func RegisterTargetAndEnvFlags

func RegisterTargetAndEnvFlags(flags *flag.FlagSet, target *Target)

RegisterTargetAndEnvFlags registers the commonly used --target and --env flags with the supplied FlagSet

func RegisterTargetFlag

func RegisterTargetFlag(flags *flag.FlagSet, target *Target)

RegisterTargetFlag registers the commonly used --target flag with the supplied FlagSet.

func SplitProfileName

func SplitProfileName(name string) (string, string)

SplitProfileName returns the installer and profile name in the case where the name is qualified (see QualifiedProfileName) or just the profile name if it is not so qualified.

Types

type Action

type Action int
const (
	Install Action = iota
	Uninstall
)

type DB

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

func NewDB

func NewDB() *DB

NewDB returns a new instance of a profile database.

func (*DB) AddProfileTarget

func (pdb *DB) AddProfileTarget(installer, name string, target Target) error

AddProfileTarget adds the specified target to the named profile. The UpdateTime of the newly installed target will be set to time.Now()

func (*DB) EnvFromProfile

func (pdb *DB) EnvFromProfile(installer, name string, target Target) []string

EnvFromProfile obtains the environment variable settings from the specified profile and target. It returns nil if the target and/or profile could not be found.

func (*DB) InstallProfile

func (pdb *DB) InstallProfile(installer, name, root string) *Profile

InstallProfile will create a new profile to the profiles database, it has no effect if the profile already exists. It returns the profile that was either newly created or already installed.

func (*DB) LookupProfile

func (pdb *DB) LookupProfile(installer, name string) *Profile

LookupProfile returns the profile for the supplied installer and profile name or nil if one is not found.

func (*DB) LookupProfileTarget

func (pdb *DB) LookupProfileTarget(installer, name string, target Target) *Target

LookupProfileTarget returns the target information stored for the supplied installer, profile name and target.

func (*DB) Names

func (pdb *DB) Names() []string

Names returns the names, in lexicographic order, of all of the currently available profiles.

func (*DB) Path

func (pdb *DB) Path() string

Path returns the directory or filename that this database was read from.

func (*DB) Profiles

func (pdb *DB) Profiles() []*Profile

Profiles returns all currently installed the profiles, in lexicographic order.

func (*DB) Read

func (pdb *DB) Read(jirix *jiri.X, path string) error

Read reads the specified database directory or file to obtain the current set of installed profiles into the receiver database. It is not an error if the database does not exist, instead, an empty database is returned.

func (*DB) RemoveProfileTarget

func (pdb *DB) RemoveProfileTarget(installer, name string, target Target) bool

RemoveProfileTarget removes the specified target from the named profile. If this is the last target for the profile then the profile will be deleted from the database. It returns true if the profile was so deleted or did not originally exist.

func (*DB) SchemaVersion

func (pdb *DB) SchemaVersion() Version

SchemaVersion returns the version of the xml schema used to implement the database.

func (*DB) UpdateProfileTarget

func (pdb *DB) UpdateProfileTarget(installer, name string, target Target) error

UpdateProfileTarget updates the specified target from the named profile. The UpdateTime of the updated target will be set to time.Now()

func (*DB) Write

func (pdb *DB) Write(jirix *jiri.X, installer, path string) error

Write writes the current set of installed profiles to the specified database location. No data will be written and an error returned if the path is a directory and installer is an empty string.

type Environment

type Environment struct {
	Vars []string `xml:"var"`
}

func (*Environment) Get

func (e *Environment) Get() interface{}

Set implements flag.Getter.

func (*Environment) Set

func (e *Environment) Set(val string) error

Set implements flag.Value.

func (Environment) String

func (e Environment) String() string

String implements flag.Getter.

func (Environment) Usage

func (e Environment) Usage() string

Usage returns the usage string for Environment.

type Manager

type Manager interface {
	// Name returns the unqualified name of this profile.
	Name() string

	// Installer returns the installer for this profile.
	Installer() string

	// Info returns an informative description of the profile.
	Info() string

	// VersionInfo returns the VersionInfo instance for this profile.
	VersionInfo() *VersionInfo

	// String returns a string representation of the profile, conventionally
	// this is its qualified name and version.
	String() string

	// AddFlags allows the profile manager to add profile specific flags
	// to the supplied FlagSet for the specified Action.
	// They should be named <profile-name>.<flag>.
	AddFlags(*flag.FlagSet, Action)

	// OSPackages returns the set of operating system packages required by the
	// specified profile and target.
	OSPackages(jirix *jiri.X, pdb *DB, root jiri.RelPath, target Target) ([]string, error)

	// Install installs the profile for the specified build target.
	Install(jirix *jiri.X, pdb *DB, root jiri.RelPath, target Target) error

	// Uninstall uninstalls the profile for the specified build target.
	Uninstall(jirix *jiri.X, pdb *DB, root jiri.RelPath, target Target) error
}

Manager is the interface that must be implemented in order to manage (i.e. install/uninstall) and describe a profile.

type Profile

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

Profile represents an installed profile and its associated targets.

func (*Profile) Name

func (p *Profile) Name() string

Name returns the qualified name of this profile.

func (*Profile) Root

func (p *Profile) Root() string

Root returns the directory, relative to the jiri root, that this profile is installed at.

func (*Profile) Targets

func (p *Profile) Targets() Targets

Targets returns the currently installed set of targets for this profile. Note that Targets is ordered by architecture, operating system and descending versions.

type Target

type Target struct {

	// The environment as modified by a profile implementation
	Env             Environment
	InstallationDir string // where this target is installed.
	UpdateTime      time.Time
	// contains filtered or unexported fields
}

Target represents specification for the environment that the profile is to be built for. Targets include a version string to allow for upgrades and for the simultaneous existence of incompatible versions.

Target and Environment implement flag.Getter so that they may be used with the flag package. Two flags are required, one to specify the target in <arch>-<os>@<version> format and a second to specify environment variables either as comma separated values or as repeated arguments.

func DefaultTarget

func DefaultTarget() Target

DefaultTarget returns a default value for a Target. Use this function to initialize Targets that are expected to set from the command line via the flags package.

func FindTarget

func FindTarget(targets Targets, target *Target) *Target

FindTarget returns the first target that matches the requested target from the slice of Targets. If target has not been explicitly set and there is only a single target available in targets then that one target is considered as matching.

func FindTargetWithDefault

func FindTargetWithDefault(targets Targets, target *Target) *Target

FindTargetWithDefault is like FindTarget except that if there is only one target in the slice and the requested target has not been explicitly set (IsSet is false) then that one target is returned by default.

func NativeTarget

func NativeTarget() Target

NativeTarget returns a value for Target for the host on which it is running. Use this function for Target values that are passed into other functions and libraries where a native target is specifically required.

func NewTarget

func NewTarget(target string, env ...string) (Target, error)

NewTarget creates a new target using the supplied target and environment parameters specified in command line format.

func (*Target) Arch

func (pt *Target) Arch() string

Arch returns the archiecture of this target.

func (Target) CommandLineEnv

func (pt Target) CommandLineEnv() Environment

CommandLineEnv returns the environment variables set on the command line for this target.

func (Target) CrossCompiling

func (pt Target) CrossCompiling() bool

CrossCompiling returns true if the target differs from that of the runtime.

func (Target) DebugString

func (pt Target) DebugString() string

DebugString returns a pretty-printed representation of pt.

func (Target) Get

func (t Target) Get() interface{}

Get implements flag.Getter.

func (Target) IsSet

func (pt Target) IsSet() bool

IsSet returns true if this target has had its value set.

func (*Target) Less

func (pt *Target) Less(pt2 *Target) bool

Less returns true if pt2 is considered less than pt. The ordering takes into account only the architecture, operating system and version of the target. The architecture and operating system are ordered lexicographically in ascending order, then the version is ordered but in descending lexicographic order except that the empty string is considered the 'highest' value. Thus, (targets in <arch>-<os>[@<version>] format), are all true: b-c < c-c b-c@3 < b-c@2

func (Target) Match

func (pt Target) Match(pt2 *Target) bool

Match returns true if pt and pt2 meet the following criteria in the order they are listed:

  • if the Arch and OS fields are exactly the same
  • if pt has a non-zero length Version field, then it must be the same as that in pt2

Match is used by the various methods and functions in this package when looking up Targets unless otherwise specified.

func (*Target) OS

func (pt *Target) OS() string

OS returns the operating system of this target.

func (*Target) Set

func (t *Target) Set(val string) error

Set implements flag.Value.

func (*Target) SetVersion

func (pt *Target) SetVersion(v string)

SetVersion sets the version for the target.

func (Target) String

func (pt Target) String() string

String implements flag.Getter.

func (*Target) TargetSpecificDirname

func (pt *Target) TargetSpecificDirname() string

TargetSpecificDirname returns a directory name that is specific to that target taking account the architecture, operating system and command line environment variables, if relevant, into account (e.g GOARM={5,6,7}).

func (*Target) Usage

func (pt *Target) Usage() string

Usage returns the usage string for Target.

func (*Target) UseCommandLineEnv

func (pt *Target) UseCommandLineEnv()

UseCommandLineEnv copies the command line supplied environment variables into the mutable environment of the Target. It should be called as soon as all command line parsing has been completed and before the target is otherwise used.

func (*Target) Version

func (pt *Target) Version() string

Version returns the version of this target.

type Targets

type Targets []*Target

Targets is a list of *Target's ordered by architecture, operating system and descending versions.

func InsertTarget

func InsertTarget(targets Targets, target *Target) Targets

InsertTarget inserts the given target into Targets if it's not already there and returns a new slice.

func RemoveTarget

func RemoveTarget(targets Targets, target *Target) Targets

RemoveTarget removes the given target from a slice of Target and returns a slice.

func (Targets) Len

func (tl Targets) Len() int

Implements sort.Len

func (Targets) Less

func (tl Targets) Less(i, j int) bool

Implements sort.Less

func (Targets) Sort

func (tl Targets) Sort()

func (Targets) Swap

func (tl Targets) Swap(i, j int)

Implements sort.Swap

type Version

type Version int
const (
	// Original, old-style profiles without a version #
	Original Version = 0
	// First version of new-style profiles.
	V2 Version = 2
	// V3 added support for recording the options that were used to install profiles.
	V3 Version = 3
	// V4 adds support for relative path names in profiles and environment variable.
	V4 Version = 4
	// V5 adds support for multiple profile installers.
	V5 Version = 5
)

type VersionInfo

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

VersionInfo represents the supported and default versions offered by a profile and a map of versions to arbitrary metadata used internally by the profile implementation.

func NewVersionInfo

func NewVersionInfo(name string, supported map[string]interface{}, defaultVersion string) *VersionInfo

NewVersionInfo creates a new instance of VersionInfo from the supplied map of supported versions and their associated metadata. The keys for this map are the supported version strings. The supplied defaultVersion will be used whenever a specific version is not requested.

func (*VersionInfo) Default

func (vi *VersionInfo) Default() string

Default returns the default version.

func (*VersionInfo) IsTargetNewerThanDefault

func (vi *VersionInfo) IsTargetNewerThanDefault(version string) bool

IsTargetNewerThanDefault returns true if the supplied version is newer than the default.

func (*VersionInfo) IsTargetOlderThanDefault

func (vi *VersionInfo) IsTargetOlderThanDefault(version string) bool

IsTargetOlderThanDefault returns true if the supplied version is older than the default.

func (*VersionInfo) Lookup

func (vi *VersionInfo) Lookup(version string, to interface{}) error

Lookup returns the metadata associated with the requested version.

func (*VersionInfo) Select

func (vi *VersionInfo) Select(requested string) (string, error)

Select selects a version from the available ones that best matches the requested one. If requested is the emtpy string then the default version is returned, otherwise an exact match is required.

func (*VersionInfo) String

func (vi *VersionInfo) String() string

String returns a string representation of the VersionInfo, in particular it lists all of the supported versions with an asterisk next to the default.

func (*VersionInfo) Supported

func (vi *VersionInfo) Supported() []string

Supported returns the set of supported versions.

Directories

Path Synopsis
Package profilescmdline provides a command line driver (for v.io/x/lib/cmdline) for implementing jiri 'profile' subcommands.
Package profilescmdline provides a command line driver (for v.io/x/lib/cmdline) for implementing jiri 'profile' subcommands.
internal/i1
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
internal/i2
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
Package profilesmanager provides support for managing jiri profiles.
Package profilesmanager provides support for managing jiri profiles.
Package profilesreader provides support for reading and processing jiri profiles.
Package profilesreader provides support for reading and processing jiri profiles.
package profilesutil provides utility routines for implementing profiles.
package profilesutil provides utility routines for implementing profiles.

Jump to

Keyboard shortcuts

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