buildtools

package
v0.0.0-...-986d24e Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

README

Package cloudeng.io/macos/buildtools

import cloudeng.io/macos/buildtools

Constants

BashInstallPreamble
BashInstallPreamble = `#!/usr/bin/env bash
set -euo pipefail
mount="$1"
installer_pid="$2"
target="$3"

TARGET_USER=$(stat -f "%Su" /dev/console)
TARGET_HOME=$(eval echo ~$TARGET_USER)
`

BashInstallPreamble is the standard preamble for install scripts used in pkgbuild packages.

Functions

Func CWDFromContext
func CWDFromContext(ctx context.Context) string

CWDFromContext retrieves the current working directory from the context, as set by ContextWithCWD. If no directory has been set in the context the function returns the process's current working directory at the time that this package was initialized. Note that this may differ from the actual current working directory of the process if it has changed since the package was initialized or if another package that was initialized earlier has changed the current working directory of the process.

Func ContextWithCWD
func ContextWithCWD(ctx context.Context, cwd string) context.Context

ContextWithCWD returns a new context with the specified current working directory. CommandRunner will use this directory for executing commands.

Func RegisterFlagsOrDie
func RegisterFlagsOrDie(f any, fs *flag.FlagSet)

RegisterFlagsOrDie registers a struct that contains an instance of CommonFlags with the provided FlagSet, panicing on error.

Types

Type AppBundle
type AppBundle struct {
	Path string
	Info InfoPlist
}

AppBundle represents a macOS application bundle. See: https://developer.apple.com/documentation/bundleresources See: https://developer.apple.com/documentation/bundleresources/placing-content-in-a-bundle

Methods
func (b AppBundle) Clean() Step

Clean returns a Step that removes the app bundle directory and all its contents.

func (b AppBundle) Contents(elem ...string) string

Contents returns the path to the specified element within the app bundle's Contents directory.

func (b AppBundle) CopyContents(src string, dst ...string) Step

CopyContents returns the step required to copy a file into the app bundle dst is relative to the bundle Contents root.

func (b AppBundle) CopyExecutable(src string) Step

CopyExecutable returns the step required to copy the executable referenced in the Info.plist into the app bundle.

func (b AppBundle) CopyIcons(icons []IconSet) []Step

CopyIcons returns steps to copy the specified icons into the app bundle's Resources directory. If multiple icons are specified and the icon's BundleIcon field is set or if there is only a single icon then it is copied to the location specified by the bundle's Info.plist CFBundleIconFile field. All other icons are copied to their own directories within the Resources directory.

func (b AppBundle) Create() []Step

Create returns the steps required to create the app bundle directory structure and Info.plist.

func (b AppBundle) ExecutablePath() string

ExecutablePath returns the absolute path to the executable inside the app bundle that is referenced in the Info.plist.

func (b AppBundle) InstallProvisioningProfile(profile string) Step

InstallProvisioningProfile returns a Step that copies the provisioning profile into the app bundle. See https://developer.apple.com/documentation/technotes/tn3125-inside-code-signing-provisioning-profiles for an explanation of provisioning profiles.

func (b AppBundle) Resources(elem ...string) string

Resources returns the path to the specified element within the app bundle's Resources directory.

func (b AppBundle) SPCtlAsses() Step
func (b AppBundle) Sign(signer Signer) Step
func (b AppBundle) SignContents(signer Signer, dst ...string) Step

SignContents returns the step required to sign a file within the app bundle, dst is relative to the bundle Contents root.

func (b AppBundle) SignExecutable(signer Signer) Step

SignExecutable returns the step required to sign the executable within the app bundle.

func (b AppBundle) VerifyContents(signer Signer, dst ...string) Step

VerifyContents returns the step required to sign a file within the app bundle, dst is relative to the bundle Contents root.

func (b AppBundle) VerifySignatures(signer Signer) []Step
func (b AppBundle) WriteInfoPlist() Step

WriteInfoPlist returns the step required to write the Info.plist file for the app bundle.

func (b AppBundle) WriteInfoPlistGitBuild(_ context.Context, git Git) []Step
Type BashScript
type BashScript struct {
	// contains filtered or unexported fields
}

BashScript helps in the construction of bash scripts for any pre and post install operations.

Functions
func NewBashScript(preamble string) *BashScript

NewBashScript creates a new BashScript instance with the specified preamble.

Methods
func (b *BashScript) Append(text string)

Append appends the specified text to the script.

func (b *BashScript) Bytes() []byte

Bytes returns the script as a byte slice.

func (b *BashScript) CreateInstallManifest(systemWide bool, manifest File)

CreateInstallManifest appends the commands to create the install manifest to the script. If the manifest's source path is empty /dev/null is used instead.

func (b *BashScript) InstallFile(systemWide bool, file File, manifest string)

InstallFile appends the commands to install the specified file to the script. If systemWide is true the file is installed to the system location otherwise it is installed to the local user location. The manifest file, if specified, is updated with the installed file's path.

Type Browser
type Browser struct{}

Browser represents a web browser.

Methods
func (b Browser) CreateChromeExtensionID() ([]byte, string, error)

CreateChromeExtensionID generates a stable Chrome Extension ID suitable for development use. Note that this ID is derived from a newly generated RSA key pair each time the function is called, so it will be different on each invocation. For a stable ID, you would need to persist the generated key pair.

func (b Browser) ReadChromeExtensionID(keyFile string) ([]byte, string, error)

ReadChromeExtensionID reads the RSA private key from the specified PEM-encoded file to obtain the public key and corresponding Chrome Extension ID.

Type BrowserType
type BrowserType int
Constants
Chrome, Firefox, Safari, Edge
Chrome BrowserType = iota
Firefox
Safari
Edge

Methods
func (b BrowserType) String() string
Type CommandRunner
type CommandRunner struct {
	// contains filtered or unexported fields
}

CommandRunner executes system commands.

Functions
func NewCommandRunner(opts ...CommandRunnerOption) *CommandRunner

NewCommandRunner creates a new CommandRunner with the provided options.

Methods
func (r *CommandRunner) DryRun() bool
func (r *CommandRunner) Run(ctx context.Context, name string, args ...string) (StepResult, error)

Run executes the specified command with arguments and returns the combined output and any error encountered.

func (r *CommandRunner) WriteFile(ctx context.Context, path string, data []byte, perm uint32) (string, error)
Type CommandRunnerOption
type CommandRunnerOption func(o *commandRunnerOptions)

CommandRunnerOption configures a CommandRunner.

Functions
func WithCommandTiming(timing bool) CommandRunnerOption
func WithDryRun(dryRun bool) CommandRunnerOption

WithDryRun configures the CommandRunner to simulate command execution without actually running commands.

func WithStderr(w io.Writer) CommandRunnerOption

WithStderr configures the CommandRunner to write standard error to the provided io.Writer.

func WithStdout(w io.Writer) CommandRunnerOption

WithStdout configures the CommandRunner to write standard output to the provided io.Writer.

Type CommonFlags
type CommonFlags struct {
	DryRun     bool   `subcmd:"dry-run,false,'if set, execute the commands in dry-run mode'"`
	Timing     bool   `subcmd:"timing,false,'if set, print timing information for each step'"`
	Release    bool   `subcmd:"swift-release,false,'if set, use swift release build, otherwise debug'"`
	BundlePath string `subcmd:"bundle-path,'','path for the output bundle, overrides any specified in a config file'"`
	Signer     string `subcmd:"signer,'','signing identity to use, overrides any specified in a config file'"`
	ConfigFile string `subcmd:"config,'spec.yaml','path to the build specification yaml file'"`
	Verbose    bool   `subcmd:"verbose,false,'if set, print verbose output'"`
}

CommonFlags represents flags commonly used by buildtools command line tools.

Methods
func (f CommonFlags) CommandRunnerOptions() []CommandRunnerOption

CommandRunnerOptions returns options for the CommandRunner based on the flags.

func (f CommonFlags) ParseFile(cfg any) error

ParseFile parses the specified config file into cfg.

func (f CommonFlags) PrintResult(spec any, result RunResult) error
func (f CommonFlags) PrintResultAndExitOnErrorf(spec any, result RunResult)

PrintResultAndExitOnErrorf prints the results of running steps and exits with a non-zero status if any of the steps failed.

func (f CommonFlags) StepRunnerOptions() []StepRunnerOption

StepRunnerOptions returns options for the StepRunner based on the flags.

Type Config
type Config struct {
	AppBundle string        `yaml:"bundle"`
	Signing   SigningConfig `yaml:"signing"`
}

Config represents common configuration options that can be read from a yaml config file.

Type Entitlements
type Entitlements struct {
	// contains filtered or unexported fields
}

Entitlements represents a set of macOS app entitlements that are specified as YAML.

Methods
func (e Entitlements) MarshalIndent(indent string) ([]byte, error)

MarshalIndent returns the XML plist representation of the entitlements with the specified indent.

func (e Entitlements) MarshalPlist() (any, error)
func (e Entitlements) MarshalYAML() (any, error)
func (e *Entitlements) UnmarshalYAML(node *yaml.Node) error
Type File
type File struct {
	Src       string `yaml:"src"`
	DstLocal  string `yaml:"local"`
	DstSystem string `yaml:"system"`
}
Methods
func (f File) OneOf() string

OneOf returns the destination path to use for the file. If both DstLocal and DstSystem are set an empty string is returned, if neither is set the source path is returned, otherwise one of the system or local destination paths is returned.

func (f File) RewriteHOME() File

RewriteHOME rewrites any occurrences of $HOME in the source and destination paths to ${TARGET_HOME} which is set in the bash script preamble. Use this with the BashInstallPreamble to access the current logged in user's home directory since $HOME does not refer to the user's home directory from within the installer environment.

Type Git
type Git struct {
	// contains filtered or unexported fields
}
Functions
func NewGit(dir string) Git

NewGit creates a new Git instance rooted at the specified directory which must be within a git repository.

Methods
func (g Git) GetBranch(version string) string
func (g Git) Hash(ctx context.Context, cmdRunner *CommandRunner, branch string, n int) (StepResult, error)
func (g Git) ReplaceBranch(version, buildID string) string
Type IconSet
type IconSet struct {
	Icon     string           `yaml:"icon"`
	Dir      string           `yaml:"dir"`
	Name     string           `yaml:"name"`       // defaults to AppIcon.icns
	Sizes    []int            `yaml:"sizes,flow"` // optional - defaults to standard sizes if not provided
	Multiple IconSizeMultiple `yaml:"multiple"`   // optional - defaults to 3 (1x, 2x and 3x) if not provided
	Format   string           `yaml:"format"`     // optional - defaults to png if not provided
	// if true, the icon is copied to the bundle Resources directory
	// as the file specified by CFBundleIconFile in the Info.plist
	BundleIcon bool `yaml:"bundle_icon"`
}

IconSet represents a directory that contains the variously sized icons needed to create an .icns file from a single source icon.

Methods
func (i IconSet) CreateIcns() Step
func (i IconSet) CreateIconVariants(src, dir string) []Step

CreateIconVariants creates the variously sized icons needed for the icon set. If no sizes are provided, a default set is used. The highest_multiple parameter indicates the highest scale factor to use, e.g., 2 for 1x and 2x, 3 for 1x, 2x and 3x.

func (i IconSet) IconFormat() string
func (i IconSet) IconSetDir() string
func (i IconSet) IconSetFile() string
func (i IconSet) IconSetName() string
Type IconSetDir
type IconSetDir string

IconSetDir represents a directory for an icon set.

Type IconSizeMultiple
type IconSizeMultiple int

IconSizeMultiple represents the scale factor for icon sizes, e.g., 1x, 2x, 3x.

Constants
IconSize1x, IconSize2x, IconSize3x
IconSize1x IconSizeMultiple = 1
IconSize2x IconSizeMultiple = 2
IconSize3x IconSizeMultiple = 3

Methods
func (m IconSizeMultiple) Suffix() string

Suffix returns the filename suffix appropriate for the icon size multiple.

Type InfoPlist
type InfoPlist struct {
	CFBundleIdentifier     string
	CFBundleName           string
	CFBundleExecutable     string
	CFBundleIconFile       string
	CFBundlePackageType    string
	LSMinimumSystemVersion string
	CFBundleDisplayName    string
	CFBundleVersion        string
	XPCService             *XPCServicePlist
	Raw                    map[string]any
}

InfoPlist represents the contents of a macOS Info.plist file. The struct fields represent common keys found in such files and are extracted from the Raw map for convenience and use within this package.

Methods
func (ipl InfoPlist) MarshalPlist() (any, error)
func (ipl InfoPlist) MarshalYAML() (any, error)
func (ipl *InfoPlist) UnmarshalYAML(node *yaml.Node) error
Type NativeMessagingConfig
type NativeMessagingConfig struct {
	Name              string   `json:"name"`
	Description       string   `json:"description"`
	Path              string   `json:"path"`
	Type              string   `json:"type"`                         // "stdio" or one of the other allowed communication types
	AllowedOrigins    []string `json:"allowed_origins,omitempty"`    // chrome-extension://<extension-id>/
	AllowedExtensions []string `json:"allowed_extensions,omitempty"` // firefox extension ids
}

NativeMessagingConfig represents the configuration for a native messaging host.

Methods
func (nm *NativeMessagingConfig) AppendChromeOrigin(extensionID string)

AppendChromeOrigin appends the specified Chrome extension ID to the list of allowed origins.

func (nm *NativeMessagingConfig) Validate(browser BrowserType) Step

Validate validates the native messaging configuration for the specified browser.

func (nm *NativeMessagingConfig) ValidateChrome() error

ValidateChrome validates the native messaging configuration for Chrome.

Type PerFileEntitlements
type PerFileEntitlements struct {
	// contains filtered or unexported fields
}

PerFileEntitlements represents a set of macOS app entitlements that are specific to individual files within an app bundle. These are specified as YAML. The key should be the file within the bundle and the value is the entitlements dictionary for that file. The file name can be either the base name (eg. "executable") or the full path within the bundle (e.g. "Contents/MacOS/executable").

Methods
func (e PerFileEntitlements) For(path string) (Entitlements, bool)

For returns the entitlements for the specified path or nil if none exist. It will first look for the base name of the path and then the full path.

func (e PerFileEntitlements) MarshalPlist() (any, error)
func (e PerFileEntitlements) MarshalYAML() (any, error)
func (e *PerFileEntitlements) UnmarshalYAML(node *yaml.Node) error
Type PkgBuild
type PkgBuild struct {
	BuildDir        string `yaml:"build_dir"`        // Directory to use for building the package
	Identifier      string `yaml:"identifier"`       // Package identifier, e.g. com.cloudeng.myapp
	Version         string `yaml:"version"`          // Package version, e.g. 1.0.0
	InstallLocation string `yaml:"install_location"` // Installation location, e.g. /Applications/MyApp.app

}

PkgBuild represents the pkgbuild tool and its configuration.

Methods
func (p PkgBuild) Build(outputPath string) Step

Build returns a Step that builds the package using pkgbuild.

func (p PkgBuild) Clean() Step

Clean returns a Step that removes the BuildDir directory.

func (p PkgBuild) CopyApplication(src string) Step

CopyApplication returns a Step that copies the specified application bundle to the Applications directory within the package build root.

func (p PkgBuild) CopyLibrary(src, library string) Step

CopyLibrary returns a Step that copies the specified library directory to the Library directory within the package build root. Note that this is one way of installing files for use by the Installer.

func (p PkgBuild) CopyScripts(src string) Step

CopyScripts returns a Step that copies the specified scripts directory to the scripts directory within the package build root.

func (p PkgBuild) Create() []Step

Create returns the steps required to create the pkgbuild directory structure.

func (p PkgBuild) CreateLibrary(library string) Step

CreateLibrary returns a Step that creates the specified library directory

func (p PkgBuild) Install(outputPath string) Step

Install returns a Step that installs the package using the system installer command using sudo.

func (p PkgBuild) LibraryPath(library string) string

LibraryPath returns the path to the specified library directory within the package build root.

func (p PkgBuild) OutputsPath() string

OutputsPath returns the path to the outputs directory within the package build root.

func (p PkgBuild) ScriptsPath() string

ScriptsPath returns the path to the scripts directory within the package build root.

func (p PkgBuild) WritePlist(cfg []PkgComponentPlist) Step

WritePlist returns a Step that writes the specified component plist configuration to the component.plist file within the package build root.

func (p PkgBuild) WriteScript(data []byte, name string) Step

WriteScript returns a Step that writes the specified script data to a file with the given name in the scripts directory within the package build root.

Type PkgComponentPlist
type PkgComponentPlist struct {
	RootRelativeBundlePath      string `yaml:"RootRelativeBundlePath" plist:"RootRelativeBundlePath"`
	BundleIsRelocatable         bool   `yaml:"BundleIsRelocatable" plist:"BundleIsRelocatable,omitempty"`
	BundleIsVersionChecked      bool   `yaml:"BundleIsVersionChecked" plist:"BundleIsVersionChecked,omitempty"`
	BundleHasStrictIdentifier   bool   `yaml:"BundleHasStrictIdentifier" plist:"BundleHasStrictIdentifier,omitempty"`
	BundleOverwriteAction       string `yaml:"BundleOverwriteAction" plist:"BundleOverwriteAction,omitempty"`
	BundlePreInstallScriptPath  string `yaml:"BundlePreInstallScriptPath" plist:"BundlePreInstallScriptPath,omitempty"`
	BundlePostInstallScriptPath string `yaml:"BundlePostInstallScriptPath" plist:"BundlePostInstallScriptPath,omitempty"`
	BundleInstallScriptTimeout  int    `yaml:"BundleInstallScriptTimeout" plist:"BundleInstallScriptTimeout,omitempty"`
}

PkgConfPkgComponentPlist represents the pkgbuild component plist structure.

Type ProductBuild
type ProductBuild struct {
	PkgBuild
	InstallLocation string // target location for the install, e.g. /
	GUIXML          string // path to the distribution XML file relative to the resources directory
}

ProductBuild represents the productbuild tool.

Methods
func (p ProductBuild) BuildDistribution(outputPkgPath, signingIdentity string) Step

BuildDistribution returns a Step that creates a product archive using productbuild with the specified distribution XML at outputPkgPath.

func (p ProductBuild) CopyResources(src ...string) []Step

CopyResources returns a Step that copies the specified resource to the resources directory within the product build root.

func (p ProductBuild) Create() []Step

Create returns steps that create the product build directory structure in addition to those created by the embedded PkgBuild.

func (p ProductBuild) Install(outputPath string) Step

Install returns a Step that installs the package using the system installer command.

func (p ProductBuild) ResourcesPath() string

ResourcesPath returns the path to the resources directory.

Type ProductBuildResources
type ProductBuildResources struct {
	GUIXML          string   `yaml:"gui_xml"`          // The distribution XML file.
	SigningIdentity string   `yaml:"signing_identity"` // The signing identity to use for signing the product.
	Resources       []string `yaml:"resources"`        // paths to additional resources to include in the product build.
	Packages        []string `yaml:"packages"`         // paths to the component packages to include in the product build.
}

ProductBuildResources represents the resources needed to create a productbuild distribution.

Type ProductPreInstallRequirements
type ProductPreInstallRequirements struct {
	Raw map[string]any
}

ProductPreInstallRequirements represents the productbuild pre-install requirements for synthesized packages.

Methods
func (p ProductPreInstallRequirements) MarshalPlist() (any, error)
func (p ProductPreInstallRequirements) MarshalYAML() (any, error)
func (p *ProductPreInstallRequirements) UnmarshalYAML(node *yaml.Node) error
Type ReformatIcon
type ReformatIcon struct {
	InputPath  string
	OutputPath string
}

ReformatIcon represents a step that reformats an icon to the specified format.

Methods
func (j ReformatIcon) Convert(format string) Step

Convert converts the input image/icon to the specified format.

Type Resources
type Resources struct {
	Executable string    `yaml:"executable"`
	Icons      []IconSet `yaml:"icons"` // multiple icon sets can be specified
}

Resources represents the resources needed to build an app bundle.

Methods
func (r Resources) IconSetSteps() []Step

IconSetSteps returns the steps needed to create the icon sets specified in the Resources.

Type RunResult
type RunResult []StepResult

RunResult captures the outcome of running the steps.

Methods
func (r RunResult) Error() error

Error returns the last error encountered, if any.

Type Signer
type Signer struct {
	// contains filtered or unexported fields
}
Functions
func NewSigner(identity string, entitlements *Entitlements, perFileEntitlements *PerFileEntitlements, arguments []string) Signer

NewSigner creates a new signer. The most specific entitlements for a given path will be used. If no file specific entitlement exists, the global one (if any) is used.

Methods
func (s Signer) SignPath(bundle, path string) Step

SignPath returns a Step that signs the specified path within the specified bundle. If path is empty, the bundle itself is signed.

func (s Signer) VerifyPath(bundle, path string) Step

VerifyPath returns a Step that verifies the signature of the specified path within the specified bundle. If path is empty, the bundle itself is verified.

Type SigningConfig
type SigningConfig struct {
	Identity            string               `yaml:"identity"`
	CodesignArguments   []string             `yaml:"codesign-args"`
	Entitlements        *Entitlements        `yaml:"entitlements"`
	PerFileEntitlements *PerFileEntitlements `yaml:"perfile_entitlements"`
}

SigningConfig represents signing related configuration that can be read from a yaml config file.

Methods
func (s SigningConfig) Signer() Signer

Signer returns a Signer based on the configuration.

Type Step
type Step interface {
	// Run executes the step.
	Run(context.Context, *CommandRunner) (StepResult, error)
}

Step represents a single operation that can be executed by the StepRunner.

Functions
func Copy(oldname, newname string) Step

Copy returns a Step that copies a file using cp.

func CopyDir(srcDir, dstDir string) Step

CopyDir returns a Step that copies a directory recursively using cp -r.

func DirExists(d string) Step

DirExists returns a Step that checks for the existence of the directory.

func ErrorStep(err error, cmd string, args ...string) Step
func FileExists(f string) Step

FileExists returns a Step that checks for the existence of the file.

func IsValidIconSetDir(id IconSetDir) Step

IsValidIsValidIconSetDir returns a Step that checks if the directory has a .iconset extension.

func MkdirAll(d string) Step

MkdirAll returns a Step that creates a directory and all necessary parents using mkdir -p.

func NoopStep(detail string) Step
func RSync(src, dst string, args ...string) Step

RSync returns a Step that synchronizes files and directories using rsync.

func Rename(oldname, newname string) Step

Rename returns a Step that renames a file using mv.

func RmdirAll(d string) Step

RmdirAll returns a Step that removes an app bundle and all its contents using rm -rf.

func StepFunc(f func(context.Context, *CommandRunner) (StepResult, error)) Step

StepFunc is a helper to create Steps from functions.

func WriteFile(data []byte, perm os.FileMode, elems ...string) Step

WriteFile returns a Step that writes data to the specified path with the specified permissions.

func WriteJSONFile(v any, elems ...string) Step

WriteJSONFile returns a Step that marshals v to JSON and writes it to the specified path with the specified permissions.

func WritePlistFile(v any, elems ...string) Step

WritePlistFile returns a Step that marshals v to a plist and writes it to the specified path with the specified permissions.

Type StepResult
type StepResult struct {
	// contains filtered or unexported fields
}
Functions
func NewStepResult(executable string, args []string, output []byte, err error) StepResult
Methods
func (le *StepResult) Args() []string
func (le *StepResult) CommandLine() string
func (le *StepResult) Duration() time.Duration
func (le *StepResult) Error() error
func (le *StepResult) Executable() string
func (le *StepResult) Output() string
func (le *StepResult) String() string
Type StepRunner
type StepRunner struct {
	// contains filtered or unexported fields
}

StepRunner manages and executes a series of Steps.

Functions
func NewRunner(opts ...StepRunnerOption) *StepRunner

NewRunner creates a new StepRunner with the provided options.

Methods
func (r *StepRunner) AddSteps(steps ...Step) *StepRunner

AddSteps adds one or more steps to the StepRunner.

func (r *StepRunner) Run(ctx context.Context, cmdRunner *CommandRunner) RunResult

Run executes all added steps in sequence and returns a RunResult.

Type StepRunnerOption
type StepRunnerOption func(o *stepRunnerOptions)

StepRunnerOption configures a StepRunner.

Functions
func WithStepTiming(timing bool) StepRunnerOption
Type Suffix
type Suffix string
Methods
func (s Suffix) Assert(path string) Step

Assert returns a Step that checks if the provided path has the specified suffix.

Type SwiftApp
type SwiftApp struct {
	// contains filtered or unexported fields
}

SwiftApp represents the swift build tool.

Functions
func NewSwiftApp(ctx context.Context, root string, release bool) SwiftApp

NewSwiftApp creates a new SwiftApp instance rooted at the specified directory.

Methods
func (s SwiftApp) BinDir() string

BinDir returns the directory containing the swift build products.

func (s SwiftApp) Build() Step

Build returns a Step that builds the swift project.

func (s SwiftApp) CopyIcons(icons []IconSet) []Step

CopyIcons returns steps to copy the specified icons into the swift build tree's Resources directory.

func (s SwiftApp) ExecutablePath(name string) string

ExecutablePath returns the path to the specified executable within the swift build tree.

Type XPCServicePlist
type XPCServicePlist struct {
	ServiceName string
}

XPCServicePlist represents the contents of an XPCService dictionary within an Info.plist file. The Raw field contains the full dictionary contents while the ServiceName field is extracted for convenience.

Examples

Example_createAppBundle

This example demonstrates how to create a basic macOS application bundle structure with Info.plist and copy resources into it.

Documentation

Overview

Example (CreateAppBundle)

This example demonstrates how to create a basic macOS application bundle structure with Info.plist and copy resources into it.

// Create a temporary directory for the example
tempDir, err := os.MkdirTemp("", "example_app_bundle_*")
if err != nil {
	log.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tempDir) //nolint:errcheck

// Create a test executable (just a placeholder file for the example)
exeContent := []byte("#!/bin/bash\necho 'Hello from Example App'")
exePath := filepath.Join(tempDir, "ExampleExecutable")
if err := os.WriteFile(exePath, exeContent, 0755); err != nil { //nolint:gosec // G306
	fmt.Printf("Failed to create example executable: %v", err)
	return
}

plistYAML := `
CFBundleIdentifier: io.cloudeng.TestApp
CFBundleName: TestApp
CFBundleVersion: 1.0.0
CFBundleShortVersionString: 1.0
CFBundleExecutable: TestExecutable
CFBundlePackageType: APPL
LSMinimumSystemVersion: "15.0"
CFBundleDisplayName: Swift UI Example
`

var info buildtools.InfoPlist
if err := yaml.Unmarshal([]byte(plistYAML), &info); err != nil {
	fmt.Printf("failed to unmarshal info plist: %v", err)
	return
}

// Define the app bundle with required Info.plist contents
bundle := buildtools.AppBundle{
	Path: filepath.Join(tempDir, "ExampleApp.app"),
	Info: info,
}
ctx := context.Background()

runner := buildtools.NewRunner()

// Get the steps to create the basic bundle structure
runner.AddSteps(bundle.Create()...)
runner.AddSteps(bundle.WriteInfoPlist())
runner.AddSteps(bundle.CopyContents(exePath, "MacOS", "ExampleExecutable"))
results := runner.Run(ctx, buildtools.NewCommandRunner())
if err := results.Error(); err != nil {
	fmt.Printf("Failed to create app bundle: %v\n", err)
}
for _, result := range results {
	fmt.Printf("Step executed: %v %v\n", result.Executable(), result.Error() == nil)
}
Output:

Step executed: mkdir true
Step executed: mkdir true
Step executed: mkdir true
Step executed: write Info.plist true
Step executed: cp true

Index

Examples

Constants

View Source
const BashInstallPreamble = `` /* 162-byte string literal not displayed */

BashInstallPreamble is the standard preamble for install scripts used in pkgbuild packages.

Variables

This section is empty.

Functions

func CWDFromContext

func CWDFromContext(ctx context.Context) string

CWDFromContext retrieves the current working directory from the context, as set by ContextWithCWD. If no directory has been set in the context the function returns the process's current working directory at the time that this package was initialized. Note that this may differ from the actual current working directory of the process if it has changed since the package was initialized or if another package that was initialized earlier has changed the current working directory of the process.

func ContextWithCWD

func ContextWithCWD(ctx context.Context, cwd string) context.Context

ContextWithCWD returns a new context with the specified current working directory. CommandRunner will use this directory for executing commands.

func RegisterFlagsOrDie

func RegisterFlagsOrDie(f any, fs *flag.FlagSet)

RegisterFlagsOrDie registers a struct that contains an instance of CommonFlags with the provided FlagSet, panicing on error.

Types

type AppBundle

type AppBundle struct {
	Path string
	Info InfoPlist
}

AppBundle represents a macOS application bundle. See: https://developer.apple.com/documentation/bundleresources See: https://developer.apple.com/documentation/bundleresources/placing-content-in-a-bundle

func (AppBundle) Clean

func (b AppBundle) Clean() Step

Clean returns a Step that removes the app bundle directory and all its contents.

func (AppBundle) Contents

func (b AppBundle) Contents(elem ...string) string

Contents returns the path to the specified element within the app bundle's Contents directory.

func (AppBundle) CopyContents

func (b AppBundle) CopyContents(src string, dst ...string) Step

CopyContents returns the step required to copy a file into the app bundle dst is relative to the bundle Contents root.

func (AppBundle) CopyExecutable

func (b AppBundle) CopyExecutable(src string) Step

CopyExecutable returns the step required to copy the executable referenced in the Info.plist into the app bundle.

func (AppBundle) CopyIcons

func (b AppBundle) CopyIcons(icons []IconSet) []Step

CopyIcons returns steps to copy the specified icons into the app bundle's Resources directory. If multiple icons are specified and the icon's BundleIcon field is set or if there is only a single icon then it is copied to the location specified by the bundle's Info.plist CFBundleIconFile field. All other icons are copied to their own directories within the Resources directory.

func (AppBundle) Create

func (b AppBundle) Create() []Step

Create returns the steps required to create the app bundle directory structure and Info.plist.

func (AppBundle) ExecutablePath

func (b AppBundle) ExecutablePath() string

ExecutablePath returns the absolute path to the executable inside the app bundle that is referenced in the Info.plist.

func (AppBundle) InstallProvisioningProfile

func (b AppBundle) InstallProvisioningProfile(profile string) Step

InstallProvisioningProfile returns a Step that copies the provisioning profile into the app bundle. See https://developer.apple.com/documentation/technotes/tn3125-inside-code-signing-provisioning-profiles for an explanation of provisioning profiles.

func (AppBundle) Resources

func (b AppBundle) Resources(elem ...string) string

Resources returns the path to the specified element within the app bundle's Resources directory.

func (AppBundle) SPCtlAsses

func (b AppBundle) SPCtlAsses() Step

func (AppBundle) Sign

func (b AppBundle) Sign(signer Signer) Step

func (AppBundle) SignContents

func (b AppBundle) SignContents(signer Signer, dst ...string) Step

SignContents returns the step required to sign a file within the app bundle, dst is relative to the bundle Contents root.

func (AppBundle) SignExecutable

func (b AppBundle) SignExecutable(signer Signer) Step

SignExecutable returns the step required to sign the executable within the app bundle.

func (AppBundle) VerifyContents

func (b AppBundle) VerifyContents(signer Signer, dst ...string) Step

VerifyContents returns the step required to sign a file within the app bundle, dst is relative to the bundle Contents root.

func (AppBundle) VerifySignatures

func (b AppBundle) VerifySignatures(signer Signer) []Step

func (AppBundle) WriteInfoPlist

func (b AppBundle) WriteInfoPlist() Step

WriteInfoPlist returns the step required to write the Info.plist file for the app bundle.

func (AppBundle) WriteInfoPlistGitBuild

func (b AppBundle) WriteInfoPlistGitBuild(_ context.Context, git Git) []Step

type BashScript

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

BashScript helps in the construction of bash scripts for any pre and post install operations.

func NewBashScript

func NewBashScript(preamble string) *BashScript

NewBashScript creates a new BashScript instance with the specified preamble.

func (*BashScript) Append

func (b *BashScript) Append(text string)

Append appends the specified text to the script.

func (*BashScript) Bytes

func (b *BashScript) Bytes() []byte

Bytes returns the script as a byte slice.

func (*BashScript) CreateInstallManifest

func (b *BashScript) CreateInstallManifest(systemWide bool, manifest File)

CreateInstallManifest appends the commands to create the install manifest to the script. If the manifest's source path is empty /dev/null is used instead.

func (*BashScript) InstallFile

func (b *BashScript) InstallFile(systemWide bool, file File, manifest string)

InstallFile appends the commands to install the specified file to the script. If systemWide is true the file is installed to the system location otherwise it is installed to the local user location. The manifest file, if specified, is updated with the installed file's path.

type Browser

type Browser struct{}

Browser represents a web browser.

func (Browser) CreateChromeExtensionID

func (b Browser) CreateChromeExtensionID() ([]byte, string, error)

CreateChromeExtensionID generates a stable Chrome Extension ID suitable for development use. Note that this ID is derived from a newly generated RSA key pair each time the function is called, so it will be different on each invocation. For a stable ID, you would need to persist the generated key pair.

func (Browser) ReadChromeExtensionID

func (b Browser) ReadChromeExtensionID(keyFile string) ([]byte, string, error)

ReadChromeExtensionID reads the RSA private key from the specified PEM-encoded file to obtain the public key and corresponding Chrome Extension ID.

type BrowserType

type BrowserType int
const (
	Chrome BrowserType = iota
	Firefox
	Safari
	Edge
)

func (BrowserType) String

func (b BrowserType) String() string

type CommandRunner

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

CommandRunner executes system commands.

func NewCommandRunner

func NewCommandRunner(opts ...CommandRunnerOption) *CommandRunner

NewCommandRunner creates a new CommandRunner with the provided options.

func (*CommandRunner) DryRun

func (r *CommandRunner) DryRun() bool

func (*CommandRunner) Run

func (r *CommandRunner) Run(ctx context.Context, name string, args ...string) (StepResult, error)

Run executes the specified command with arguments and returns the combined output and any error encountered.

func (*CommandRunner) WriteFile

func (r *CommandRunner) WriteFile(ctx context.Context, path string, data []byte, perm uint32) (string, error)

type CommandRunnerOption

type CommandRunnerOption func(o *commandRunnerOptions)

CommandRunnerOption configures a CommandRunner.

func WithCommandTiming

func WithCommandTiming(timing bool) CommandRunnerOption

func WithDryRun

func WithDryRun(dryRun bool) CommandRunnerOption

WithDryRun configures the CommandRunner to simulate command execution without actually running commands.

func WithStderr

func WithStderr(w io.Writer) CommandRunnerOption

WithStderr configures the CommandRunner to write standard error to the provided io.Writer.

func WithStdout

func WithStdout(w io.Writer) CommandRunnerOption

WithStdout configures the CommandRunner to write standard output to the provided io.Writer.

type CommonFlags

type CommonFlags struct {
	DryRun     bool   `subcmd:"dry-run,false,'if set, execute the commands in dry-run mode'"`
	Timing     bool   `subcmd:"timing,false,'if set, print timing information for each step'"`
	Release    bool   `subcmd:"swift-release,false,'if set, use swift release build, otherwise debug'"`
	BundlePath string `subcmd:"bundle-path,'','path for the output bundle, overrides any specified in a config file'"`
	Signer     string `subcmd:"signer,'','signing identity to use, overrides any specified in a config file'"`
	ConfigFile string `subcmd:"config,'spec.yaml','path to the build specification yaml file'"`
	Verbose    bool   `subcmd:"verbose,false,'if set, print verbose output'"`
}

CommonFlags represents flags commonly used by buildtools command line tools.

func (CommonFlags) CommandRunnerOptions

func (f CommonFlags) CommandRunnerOptions() []CommandRunnerOption

CommandRunnerOptions returns options for the CommandRunner based on the flags.

func (CommonFlags) ParseFile

func (f CommonFlags) ParseFile(cfg any) error

ParseFile parses the specified config file into cfg.

func (CommonFlags) PrintResult

func (f CommonFlags) PrintResult(spec any, result RunResult) error

func (CommonFlags) PrintResultAndExitOnErrorf

func (f CommonFlags) PrintResultAndExitOnErrorf(spec any, result RunResult)

PrintResultAndExitOnErrorf prints the results of running steps and exits with a non-zero status if any of the steps failed.

func (CommonFlags) StepRunnerOptions

func (f CommonFlags) StepRunnerOptions() []StepRunnerOption

StepRunnerOptions returns options for the StepRunner based on the flags.

type Config

type Config struct {
	AppBundle string        `yaml:"bundle"`
	Signing   SigningConfig `yaml:"signing"`
}

Config represents common configuration options that can be read from a yaml config file.

type Entitlements

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

Entitlements represents a set of macOS app entitlements that are specified as YAML.

func (Entitlements) MarshalIndent

func (e Entitlements) MarshalIndent(indent string) ([]byte, error)

MarshalIndent returns the XML plist representation of the entitlements with the specified indent.

func (Entitlements) MarshalPlist

func (e Entitlements) MarshalPlist() (any, error)

func (Entitlements) MarshalYAML

func (e Entitlements) MarshalYAML() (any, error)

func (*Entitlements) UnmarshalYAML

func (e *Entitlements) UnmarshalYAML(node *yaml.Node) error

type File

type File struct {
	Src       string `yaml:"src"`
	DstLocal  string `yaml:"local"`
	DstSystem string `yaml:"system"`
}

func (File) OneOf

func (f File) OneOf() string

OneOf returns the destination path to use for the file. If both DstLocal and DstSystem are set an empty string is returned, if neither is set the source path is returned, otherwise one of the system or local destination paths is returned.

func (File) RewriteHOME

func (f File) RewriteHOME() File

RewriteHOME rewrites any occurrences of $HOME in the source and destination paths to ${TARGET_HOME} which is set in the bash script preamble. Use this with the BashInstallPreamble to access the current logged in user's home directory since $HOME does not refer to the user's home directory from within the installer environment.

type Git

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

func NewGit

func NewGit(dir string) Git

NewGit creates a new Git instance rooted at the specified directory which must be within a git repository.

func (Git) GetBranch

func (g Git) GetBranch(version string) string

func (Git) Hash

func (g Git) Hash(ctx context.Context, cmdRunner *CommandRunner, branch string, n int) (StepResult, error)

func (Git) ReplaceBranch

func (g Git) ReplaceBranch(version, buildID string) string

type IconSet

type IconSet struct {
	Icon     string           `yaml:"icon"`
	Dir      string           `yaml:"dir"`
	Name     string           `yaml:"name"`       // defaults to AppIcon.icns
	Sizes    []int            `yaml:"sizes,flow"` // optional - defaults to standard sizes if not provided
	Multiple IconSizeMultiple `yaml:"multiple"`   // optional - defaults to 3 (1x, 2x and 3x) if not provided
	Format   string           `yaml:"format"`     // optional - defaults to png if not provided
	// if true, the icon is copied to the bundle Resources directory
	// as the file specified by CFBundleIconFile in the Info.plist
	BundleIcon bool `yaml:"bundle_icon"`
}

IconSet represents a directory that contains the variously sized icons needed to create an .icns file from a single source icon.

func (IconSet) CreateIcns

func (i IconSet) CreateIcns() Step

func (IconSet) CreateIconVariants

func (i IconSet) CreateIconVariants(src, dir string) []Step

CreateIconVariants creates the variously sized icons needed for the icon set. If no sizes are provided, a default set is used. The highest_multiple parameter indicates the highest scale factor to use, e.g., 2 for 1x and 2x, 3 for 1x, 2x and 3x.

func (IconSet) IconFormat

func (i IconSet) IconFormat() string

func (IconSet) IconSetDir

func (i IconSet) IconSetDir() string

func (IconSet) IconSetFile

func (i IconSet) IconSetFile() string

func (IconSet) IconSetName

func (i IconSet) IconSetName() string

type IconSetDir

type IconSetDir string

IconSetDir represents a directory for an icon set.

type IconSizeMultiple

type IconSizeMultiple int

IconSizeMultiple represents the scale factor for icon sizes, e.g., 1x, 2x, 3x.

const (
	IconSize1x IconSizeMultiple = 1
	IconSize2x IconSizeMultiple = 2
	IconSize3x IconSizeMultiple = 3
)

func (IconSizeMultiple) Suffix

func (m IconSizeMultiple) Suffix() string

Suffix returns the filename suffix appropriate for the icon size multiple.

type InfoPlist

type InfoPlist struct {
	CFBundleIdentifier     string
	CFBundleName           string
	CFBundleExecutable     string
	CFBundleIconFile       string
	CFBundlePackageType    string
	LSMinimumSystemVersion string
	CFBundleDisplayName    string
	CFBundleVersion        string
	XPCService             *XPCServicePlist
	Raw                    map[string]any
}

InfoPlist represents the contents of a macOS Info.plist file. The struct fields represent common keys found in such files and are extracted from the Raw map for convenience and use within this package.

func (InfoPlist) MarshalPlist

func (ipl InfoPlist) MarshalPlist() (any, error)

func (InfoPlist) MarshalYAML

func (ipl InfoPlist) MarshalYAML() (any, error)

func (*InfoPlist) UnmarshalYAML

func (ipl *InfoPlist) UnmarshalYAML(node *yaml.Node) error

type NativeMessagingConfig

type NativeMessagingConfig struct {
	Name              string   `json:"name"`
	Description       string   `json:"description"`
	Path              string   `json:"path"`
	Type              string   `json:"type"`                         // "stdio" or one of the other allowed communication types
	AllowedOrigins    []string `json:"allowed_origins,omitempty"`    // chrome-extension://<extension-id>/
	AllowedExtensions []string `json:"allowed_extensions,omitempty"` // firefox extension ids
}

NativeMessagingConfig represents the configuration for a native messaging host.

func (*NativeMessagingConfig) AppendChromeOrigin

func (nm *NativeMessagingConfig) AppendChromeOrigin(extensionID string)

AppendChromeOrigin appends the specified Chrome extension ID to the list of allowed origins.

func (*NativeMessagingConfig) Validate

func (nm *NativeMessagingConfig) Validate(browser BrowserType) Step

Validate validates the native messaging configuration for the specified browser.

func (*NativeMessagingConfig) ValidateChrome

func (nm *NativeMessagingConfig) ValidateChrome() error

ValidateChrome validates the native messaging configuration for Chrome.

type PerFileEntitlements

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

PerFileEntitlements represents a set of macOS app entitlements that are specific to individual files within an app bundle. These are specified as YAML. The key should be the file within the bundle and the value is the entitlements dictionary for that file. The file name can be either the base name (eg. "executable") or the full path within the bundle (e.g. "Contents/MacOS/executable").

func (PerFileEntitlements) For

For returns the entitlements for the specified path or nil if none exist. It will first look for the base name of the path and then the full path.

func (PerFileEntitlements) MarshalPlist

func (e PerFileEntitlements) MarshalPlist() (any, error)

func (PerFileEntitlements) MarshalYAML

func (e PerFileEntitlements) MarshalYAML() (any, error)

func (*PerFileEntitlements) UnmarshalYAML

func (e *PerFileEntitlements) UnmarshalYAML(node *yaml.Node) error

type PkgBuild

type PkgBuild struct {
	BuildDir        string `yaml:"build_dir"`        // Directory to use for building the package
	Identifier      string `yaml:"identifier"`       // Package identifier, e.g. com.cloudeng.myapp
	Version         string `yaml:"version"`          // Package version, e.g. 1.0.0
	InstallLocation string `yaml:"install_location"` // Installation location, e.g. /Applications/MyApp.app

}

PkgBuild represents the pkgbuild tool and its configuration.

func (PkgBuild) Build

func (p PkgBuild) Build(outputPath string) Step

Build returns a Step that builds the package using pkgbuild.

func (PkgBuild) Clean

func (p PkgBuild) Clean() Step

Clean returns a Step that removes the BuildDir directory.

func (PkgBuild) CopyApplication

func (p PkgBuild) CopyApplication(src string) Step

CopyApplication returns a Step that copies the specified application bundle to the Applications directory within the package build root.

func (PkgBuild) CopyLibrary

func (p PkgBuild) CopyLibrary(src, library string) Step

CopyLibrary returns a Step that copies the specified library directory to the Library directory within the package build root. Note that this is one way of installing files for use by the Installer.

func (PkgBuild) CopyScripts

func (p PkgBuild) CopyScripts(src string) Step

CopyScripts returns a Step that copies the specified scripts directory to the scripts directory within the package build root.

func (PkgBuild) Create

func (p PkgBuild) Create() []Step

Create returns the steps required to create the pkgbuild directory structure.

func (PkgBuild) CreateLibrary

func (p PkgBuild) CreateLibrary(library string) Step

CreateLibrary returns a Step that creates the specified library directory

func (PkgBuild) Install

func (p PkgBuild) Install(outputPath string) Step

Install returns a Step that installs the package using the system installer command using sudo.

func (PkgBuild) LibraryPath

func (p PkgBuild) LibraryPath(library string) string

LibraryPath returns the path to the specified library directory within the package build root.

func (PkgBuild) OutputsPath

func (p PkgBuild) OutputsPath() string

OutputsPath returns the path to the outputs directory within the package build root.

func (PkgBuild) ScriptsPath

func (p PkgBuild) ScriptsPath() string

ScriptsPath returns the path to the scripts directory within the package build root.

func (PkgBuild) WritePlist

func (p PkgBuild) WritePlist(cfg []PkgComponentPlist) Step

WritePlist returns a Step that writes the specified component plist configuration to the component.plist file within the package build root.

func (PkgBuild) WriteScript

func (p PkgBuild) WriteScript(data []byte, name string) Step

WriteScript returns a Step that writes the specified script data to a file with the given name in the scripts directory within the package build root.

type PkgComponentPlist

type PkgComponentPlist struct {
	RootRelativeBundlePath      string `yaml:"RootRelativeBundlePath" plist:"RootRelativeBundlePath"`
	BundleIsRelocatable         bool   `yaml:"BundleIsRelocatable" plist:"BundleIsRelocatable,omitempty"`
	BundleIsVersionChecked      bool   `yaml:"BundleIsVersionChecked" plist:"BundleIsVersionChecked,omitempty"`
	BundleHasStrictIdentifier   bool   `yaml:"BundleHasStrictIdentifier" plist:"BundleHasStrictIdentifier,omitempty"`
	BundleOverwriteAction       string `yaml:"BundleOverwriteAction" plist:"BundleOverwriteAction,omitempty"`
	BundlePreInstallScriptPath  string `yaml:"BundlePreInstallScriptPath" plist:"BundlePreInstallScriptPath,omitempty"`
	BundlePostInstallScriptPath string `yaml:"BundlePostInstallScriptPath" plist:"BundlePostInstallScriptPath,omitempty"`
	BundleInstallScriptTimeout  int    `yaml:"BundleInstallScriptTimeout" plist:"BundleInstallScriptTimeout,omitempty"`
}

PkgConfPkgComponentPlist represents the pkgbuild component plist structure.

type ProductBuild

type ProductBuild struct {
	PkgBuild
	InstallLocation string // target location for the install, e.g. /
	GUIXML          string // path to the distribution XML file relative to the resources directory
}

ProductBuild represents the productbuild tool.

func (ProductBuild) BuildDistribution

func (p ProductBuild) BuildDistribution(outputPkgPath, signingIdentity string) Step

BuildDistribution returns a Step that creates a product archive using productbuild with the specified distribution XML at outputPkgPath.

func (ProductBuild) CopyResources

func (p ProductBuild) CopyResources(src ...string) []Step

CopyResources returns a Step that copies the specified resource to the resources directory within the product build root.

func (ProductBuild) Create

func (p ProductBuild) Create() []Step

Create returns steps that create the product build directory structure in addition to those created by the embedded PkgBuild.

func (ProductBuild) Install

func (p ProductBuild) Install(outputPath string) Step

Install returns a Step that installs the package using the system installer command.

func (ProductBuild) ResourcesPath

func (p ProductBuild) ResourcesPath() string

ResourcesPath returns the path to the resources directory.

type ProductBuildResources

type ProductBuildResources struct {
	GUIXML          string   `yaml:"gui_xml"`          // The distribution XML file.
	SigningIdentity string   `yaml:"signing_identity"` // The signing identity to use for signing the product.
	Resources       []string `yaml:"resources"`        // paths to additional resources to include in the product build.
	Packages        []string `yaml:"packages"`         // paths to the component packages to include in the product build.
}

ProductBuildResources represents the resources needed to create a productbuild distribution.

type ProductPreInstallRequirements

type ProductPreInstallRequirements struct {
	Raw map[string]any
}

ProductPreInstallRequirements represents the productbuild pre-install requirements for synthesized packages.

func (ProductPreInstallRequirements) MarshalPlist

func (p ProductPreInstallRequirements) MarshalPlist() (any, error)

func (ProductPreInstallRequirements) MarshalYAML

func (p ProductPreInstallRequirements) MarshalYAML() (any, error)

func (*ProductPreInstallRequirements) UnmarshalYAML

func (p *ProductPreInstallRequirements) UnmarshalYAML(node *yaml.Node) error

type ReformatIcon

type ReformatIcon struct {
	InputPath  string
	OutputPath string
}

ReformatIcon represents a step that reformats an icon to the specified format.

func (ReformatIcon) Convert

func (j ReformatIcon) Convert(format string) Step

Convert converts the input image/icon to the specified format.

type Resources

type Resources struct {
	Executable string    `yaml:"executable"`
	Icons      []IconSet `yaml:"icons"` // multiple icon sets can be specified
}

Resources represents the resources needed to build an app bundle.

func (Resources) IconSetSteps

func (r Resources) IconSetSteps() []Step

IconSetSteps returns the steps needed to create the icon sets specified in the Resources.

type RunResult

type RunResult []StepResult

RunResult captures the outcome of running the steps.

func (RunResult) Error

func (r RunResult) Error() error

Error returns the last error encountered, if any.

type Signer

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

func NewSigner

func NewSigner(identity string, entitlements *Entitlements, perFileEntitlements *PerFileEntitlements, arguments []string) Signer

NewSigner creates a new signer. The most specific entitlements for a given path will be used. If no file specific entitlement exists, the global one (if any) is used.

func (Signer) SignPath

func (s Signer) SignPath(bundle, path string) Step

SignPath returns a Step that signs the specified path within the specified bundle. If path is empty, the bundle itself is signed.

func (Signer) VerifyPath

func (s Signer) VerifyPath(bundle, path string) Step

VerifyPath returns a Step that verifies the signature of the specified path within the specified bundle. If path is empty, the bundle itself is verified.

type SigningConfig

type SigningConfig struct {
	Identity            string               `yaml:"identity"`
	CodesignArguments   []string             `yaml:"codesign-args"`
	Entitlements        *Entitlements        `yaml:"entitlements"`
	PerFileEntitlements *PerFileEntitlements `yaml:"perfile_entitlements"`
}

SigningConfig represents signing related configuration that can be read from a yaml config file.

func (SigningConfig) Signer

func (s SigningConfig) Signer() Signer

Signer returns a Signer based on the configuration.

type Step

type Step interface {
	// Run executes the step.
	Run(context.Context, *CommandRunner) (StepResult, error)
}

Step represents a single operation that can be executed by the StepRunner.

func Copy

func Copy(oldname, newname string) Step

Copy returns a Step that copies a file using cp.

func CopyDir

func CopyDir(srcDir, dstDir string) Step

CopyDir returns a Step that copies a directory recursively using cp -r.

func DirExists

func DirExists(d string) Step

DirExists returns a Step that checks for the existence of the directory.

func ErrorStep

func ErrorStep(err error, cmd string, args ...string) Step

func FileExists

func FileExists(f string) Step

FileExists returns a Step that checks for the existence of the file.

func IsValidIconSetDir

func IsValidIconSetDir(id IconSetDir) Step

IsValidIsValidIconSetDir returns a Step that checks if the directory has a .iconset extension.

func MkdirAll

func MkdirAll(d string) Step

MkdirAll returns a Step that creates a directory and all necessary parents using mkdir -p.

func NoopStep

func NoopStep(detail string) Step

func RSync

func RSync(src, dst string, args ...string) Step

RSync returns a Step that synchronizes files and directories using rsync.

func Rename

func Rename(oldname, newname string) Step

Rename returns a Step that renames a file using mv.

func RmdirAll

func RmdirAll(d string) Step

RmdirAll returns a Step that removes an app bundle and all its contents using rm -rf.

func StepFunc

func StepFunc(f func(context.Context, *CommandRunner) (StepResult, error)) Step

StepFunc is a helper to create Steps from functions.

func WriteFile

func WriteFile(data []byte, perm os.FileMode, elems ...string) Step

WriteFile returns a Step that writes data to the specified path with the specified permissions.

func WriteJSONFile

func WriteJSONFile(v any, elems ...string) Step

WriteJSONFile returns a Step that marshals v to JSON and writes it to the specified path with the specified permissions.

func WritePlistFile

func WritePlistFile(v any, elems ...string) Step

WritePlistFile returns a Step that marshals v to a plist and writes it to the specified path with the specified permissions.

type StepResult

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

func NewStepResult

func NewStepResult(executable string, args []string, output []byte, err error) StepResult

func (*StepResult) Args

func (le *StepResult) Args() []string

func (*StepResult) CommandLine

func (le *StepResult) CommandLine() string

func (*StepResult) Duration

func (le *StepResult) Duration() time.Duration

func (*StepResult) Error

func (le *StepResult) Error() error

func (*StepResult) Executable

func (le *StepResult) Executable() string

func (*StepResult) Output

func (le *StepResult) Output() string

func (*StepResult) String

func (le *StepResult) String() string

type StepRunner

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

StepRunner manages and executes a series of Steps.

func NewRunner

func NewRunner(opts ...StepRunnerOption) *StepRunner

NewRunner creates a new StepRunner with the provided options.

func (*StepRunner) AddSteps

func (r *StepRunner) AddSteps(steps ...Step) *StepRunner

AddSteps adds one or more steps to the StepRunner.

func (*StepRunner) Run

func (r *StepRunner) Run(ctx context.Context, cmdRunner *CommandRunner) RunResult

Run executes all added steps in sequence and returns a RunResult.

type StepRunnerOption

type StepRunnerOption func(o *stepRunnerOptions)

StepRunnerOption configures a StepRunner.

func WithStepTiming

func WithStepTiming(timing bool) StepRunnerOption

type Suffix

type Suffix string

func (Suffix) Assert

func (s Suffix) Assert(path string) Step

Assert returns a Step that checks if the provided path has the specified suffix.

type SwiftApp

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

SwiftApp represents the swift build tool.

func NewSwiftApp

func NewSwiftApp(ctx context.Context, root string, release bool) SwiftApp

NewSwiftApp creates a new SwiftApp instance rooted at the specified directory.

func (SwiftApp) BinDir

func (s SwiftApp) BinDir() string

BinDir returns the directory containing the swift build products.

func (SwiftApp) Build

func (s SwiftApp) Build() Step

Build returns a Step that builds the swift project.

func (SwiftApp) CopyIcons

func (s SwiftApp) CopyIcons(icons []IconSet) []Step

CopyIcons returns steps to copy the specified icons into the swift build tree's Resources directory.

func (SwiftApp) ExecutablePath

func (s SwiftApp) ExecutablePath(name string) string

ExecutablePath returns the path to the specified executable within the swift build tree.

type XPCServicePlist

type XPCServicePlist struct {
	ServiceName string
}

XPCServicePlist represents the contents of an XPCService dictionary within an Info.plist file. The Raw field contains the full dictionary contents while the ServiceName field is extracted for convenience.

Jump to

Keyboard shortcuts

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