Documentation
¶
Overview ¶
Package mactool builds Glutter apps for macOS, for glutter-macos (SPEC §29.1): it writes the Info.plist of an app bundle, the .icns icon from a PNG, one Mach-O file with an arm64 and an amd64 slice (what `lipo` makes), the bundle's directories, and signs the bundle ad hoc with /usr/bin/codesign. All of it but the signing is plain Go with no OS tag, so it is tested on any host; it runs on the developer's Mac, never inside an app, and needs no Xcode, no C compiler and no lipo.
Flutter: no counterpart (flutter build macos)
Index ¶
- Constants
- func DefaultID(name string) string
- func DefaultIcon() ([]byte, error)
- func DefaultName(pkg, dir string) string
- func DefaultUsage(name string) map[string]string
- func Entitlements() []byte
- func Fat(slices []FatSlice) ([]byte, error)
- func ICNS(pngData []byte) ([]byte, error)
- func InfoPlist(i Info) ([]byte, error)
- func Sign(ctx context.Context, app string, o SignOptions) error
- func Verify(ctx context.Context, app string, o SignOptions) error
- type BuildOptions
- type BuildResult
- type Bundle
- type FatSlice
- type Info
- type Layout
- type SignOptions
Constants ¶
const ( // DefaultVersion is the version of an app that does not say. // // Flutter: no counterpart DefaultVersion = "1.0.0" // MinSystemVersion is the LSMinimumSystemVersion of every bundle. // // Flutter: no counterpart MinSystemVersion = "12.0" )
The defaults of an app's identity and the lowest macOS that runs it (D34: macOS 12 is the minimum).
const ( // TagMacOSBuildFailed is the tag of the error for a package that does not build for macOS, or a build that cannot start. // // Flutter: no counterpart TagMacOSBuildFailed = "MacOSBuildFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const TagMacOSBundleInvalid = "MacOSBundleInvalid"
TagMacOSBundleInvalid is the tag of the error for a name, identifier or version that a bundle cannot have, a layout that cannot be written, or a bundle with a problem.
Flutter: no counterpart
const ( // TagMacOSIconInvalid is the tag of the error for an icon that is not a square PNG of at least 16 pixels, or that cannot be // encoded. // // Flutter: no counterpart TagMacOSIconInvalid = "MacOSIconInvalid" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // TagMacOSMachOInvalid is the tag of the error for a file that is not a thin Mach-O, or slices that cannot make a universal // file. // // Flutter: no counterpart TagMacOSMachOInvalid = "MacOSMachOInvalid" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // TagMacOSSignFailed is the tag of the error for a bundle that codesign cannot sign or verify. // // Flutter: no counterpart TagMacOSSignFailed = "MacOSSignFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
Variables ¶
This section is empty.
Functions ¶
func DefaultID ¶
DefaultID is the identifier of an app that has none: "dev.glutter." and the name in letters, digits and hyphens.
Flutter: no counterpart
func DefaultIcon ¶
DefaultIcon returns Glutter's icon as a PNG of 1024 pixels: a white ring with a gap and a bar, the shape of a "G", on the blue of the Material seed color, in a rounded square with the margin that macOS app icons have.
Flutter: no counterpart
func DefaultName ¶
DefaultName is the name of an app that has none: the last element of its package path, or of the directory for ".".
Flutter: no counterpart
func DefaultUsage ¶
DefaultUsage are the usage strings that every bundle has: the system asks for the microphone only when an app records, and shows the string then.
Flutter: no counterpart
func Entitlements ¶
func Entitlements() []byte
Entitlements writes the entitlements file that the hardened runtime needs for what the app does: the microphone.
Flutter: no counterpart
func Fat ¶
Fat writes a universal Mach-O file with the thin files as its slices, as `lipo -create` does: the header of big-endian numbers (the magic, the number of slices, and for each slice its CPU type and subtype, offset, size and alignment), then the slices at the offsets that their alignment gives (2^14 for arm64 and 2^12 for the rest, which are what lipo uses). The CPU type of a slice is read from its own header, so a file that is not a thin Mach-O, or two slices of one architecture, is MacOSMachOInvalid.
Flutter: no counterpart
func ICNS ¶
ICNS makes the .icns file of an icon from a PNG that is square and at least 16 pixels wide: each size of the file is the picture scaled (Catmull-Rom) and stored as a PNG, which every macOS that Glutter runs on reads. It fails with MacOSIconInvalid for a picture that is not that.
Flutter: no counterpart
func InfoPlist ¶
InfoPlist writes the Info.plist of the bundle as XML, with the keys in a fixed order (so a build is the same file every time) and the usage strings sorted by key. It fails with MacOSBundleInvalid for an identity that a bundle cannot have.
Flutter: no counterpart
func Sign ¶
func Sign(ctx context.Context, app string, o SignOptions) error
Sign signs the bundle with codesign: a signature on the bundle binds its Info.plist and resources to the executable, which Gatekeeper and the system's permission prompts read (an ad-hoc signature has no identity, so Gatekeeper still warns about an app that was downloaded). It fails with MacOSSignFailed, with codesign's output, when codesign cannot be run or says no.
Flutter: no counterpart
Types ¶
type BuildOptions ¶
type BuildOptions struct {
// Package is the main package to build, as `go build` takes it: "./examples/counter".
Package string
// Dir is the directory to run the go command in, which Package is relative to. The default is the current directory.
Dir string
// Out is the bundle to write, which ends in ".app"; "<Name>.app" in the current directory when empty.
Out string
// Archs are the architectures to build, "arm64" and "amd64"; with both the executable is one universal Mach-O. The default is
// the architecture of this machine (arm64 on a host that is not a Mac).
Archs []string
// Release builds with -tags glutter_release and -ldflags=-s -w.
Release bool
// Hardened signs with the hardened runtime and the entitlements of Entitlements().
Hardened bool
// ID, Name and Version go into the Info.plist; the defaults are DefaultID, the name of the package, and DefaultVersion.
ID, Name, Version string
// Icon is a PNG for the icon; Glutter's icon when empty.
Icon string
// Usage are usage strings added to those of DefaultUsage (a key of the plist and its text).
Usage map[string]string
// Env is added to the environment of the go command.
Env []string
// Sign says how to sign the bundle; the zero value signs it ad hoc.
Sign SignOptions
}
BuildOptions are the parameters of Build (the flags of `glutter-macos build`, SPEC §29.1).
Flutter: no counterpart
type BuildResult ¶
type BuildResult struct {
// Layout has the paths of the bundle.
Layout Layout
// Archs are the architectures of the executable, in the order asked for.
Archs []string
// Info is what went into the plist, with the defaults filled in.
Info Info
// Size is the size of the executable in bytes.
Size int64
// Thin are the sizes of the thin files, by architecture.
Thin map[string]int64
}
BuildResult says what Build wrote.
Flutter: no counterpart
func Build ¶
func Build(ctx context.Context, o BuildOptions) (BuildResult, error)
Build compiles the package for each architecture without cgo, makes the executable (universal when there are two), the icon and the bundle, and signs it. It fails with MacOSBuildFailed, with the output of the go command, when the package does not build, and with the tags of the pieces (MacOSIconInvalid, MacOSMachOInvalid, MacOSBundleInvalid, MacOSSignFailed) otherwise.
Flutter: no counterpart
type Bundle ¶
type Bundle struct {
Info Info
// Executable is the Mach-O file, which is written with mode 0755 as Contents/MacOS/<Info.Executable>.
Executable []byte
// Icon is the .icns file; nil leaves the bundle without one.
Icon []byte
}
Bundle is what goes into an app bundle.
Flutter: no counterpart
type FatSlice ¶
type FatSlice struct {
// Name says which file it is, for the errors ("arm64").
Name string
// Data is the thin Mach-O file.
Data []byte
}
FatSlice is a thin Mach-O file that goes into a universal one.
Flutter: no counterpart
type Info ¶
type Info struct {
// Executable is the name of the file in Contents/MacOS (CFBundleExecutable).
Executable string
// ID is the bundle identifier (CFBundleIdentifier), in reverse DNS form.
ID string
// Name is what the Dock and the menu bar call the app (CFBundleName and CFBundleDisplayName).
Name string
// Version is CFBundleShortVersionString and CFBundleVersion.
Version string
// IconFile is the name of the icon file in Contents/Resources (CFBundleIconFile); empty for none.
IconFile string
// Usage are the usage strings that the system shows when the app first asks for something: the keys are those of the plist
// ("NSMicrophoneUsageDescription"), the values the text.
Usage map[string]string
}
Info is what goes into the Info.plist of an app bundle.
Flutter: no counterpart
type Layout ¶
type Layout struct {
App, Contents, MacOS, Resources, Plist, Executable, Icon string
}
Layout names the paths of a bundle that is at app (a directory ending in ".app").
Flutter: no counterpart
func Write ¶
Write makes the bundle at app, replacing a bundle that is there. It writes Contents/MacOS/<executable>, Contents/Info.plist, Contents/PkgInfo and, with an icon, Contents/Resources/<IconFile>.icns. A file at app that is not a bundle is not removed: it is MacOSBundleInvalid. It fails with MacOSBundleInvalid for an identity that a bundle cannot have and for a path that cannot be written.
Flutter: no counterpart
type SignOptions ¶
type SignOptions struct {
// Hardened turns the hardened runtime on (`--options runtime`) with the entitlements of Entitlements(), which a bundle needs to be
// notarized; the owner does the notarization (docs/GUIDE.md), the tool only prepares for it.
Hardened bool
// Identity is the signing identity; "-" (ad hoc) when empty. A Developer ID is the owner's.
Identity string
// Tool is the codesign program; /usr/bin/codesign when empty.
Tool string
}
SignOptions are what Sign is asked for.
Flutter: no counterpart