wintool

package
v1.17.11 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: BSD-3-Clause Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wintool builds, runs and takes screenshots of Glutter apps for Windows, for glutter-windows (SPEC §25.1): it generates the application manifest, writes the resources of the .exe (the manifest, the icon with its sizes, the version information) as a COFF object with a .rsrc section in pure Go, runs the Go toolchain with that object added through `go build -overlay`, and starts the .exe under Wine through internal/winetest. It runs on the developer's machine, never inside an app, and needs no rc.exe, windres, Windows SDK or C compiler.

Flutter: no counterpart (flutter build windows)

Index

Constants

View Source
const (
	// RTIcon is the type of one image of an icon.
	//
	// Flutter: no counterpart
	RTIcon = 3
	// RTGroupIcon is the type of the directory of an icon's images.
	//
	// Flutter: no counterpart
	RTGroupIcon = 14
	// RTVersion is the type of the version information.
	//
	// Flutter: no counterpart
	RTVersion = 16
	// RTManifest is the type of the application manifest.
	//
	// Flutter: no counterpart
	RTManifest = 24
	// LangEnglishUS is the language of the resources (0x0409).
	//
	// Flutter: no counterpart
	LangEnglishUS = 0x0409
)

The types of the resources of an .exe (RT_ICON and the like).

View Source
const (

	// TagWindowsRunFailed is the tag of the error for a program that cannot be started, or that
	// ends with a status other than 0.
	TagWindowsRunFailed = "WindowsRunFailed"
	// TagWindowsShotFailed is the tag of the error for a shot that failed: the app ended with a
	// failure, or it saved no frame.
	TagWindowsShotFailed = "WindowsShotFailed"
	// TagWindowsScreenUnsupported is the tag of the error for a request to capture the screen on
	// a launcher that cannot (Windows runs the program itself).
	TagWindowsScreenUnsupported = "WindowsScreenUnsupported"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const CopyPrefix = "_glutterwin-"

CopyPrefix starts the name of the temporary directory that Build makes next to the package's directory and removes at the end (SPEC §25.1). The underscore makes the go command's "./..." skip it.

Flutter: no counterpart

View Source
const ShotReadyLine = "first frame presented"

ShotReadyLine is the line of the engine's log that a capture of the screen waits for before it settles: the app has presented its first frame (scripts/wine-screenshot.sh, GLUTTER_SHOT_READY).

Flutter: no counterpart

View Source
const SupportedOSWindows10 = "{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"

SupportedOSWindows10 is the GUID of the `supportedOS` element that names Windows 10 and 11.

Flutter: no counterpart

View Source
const (

	// TagWindowsBuildInvalid is the tag of the error for a build that cannot be done: no package, an
	// architecture that is not known, a package that is not one main package or that has resources
	// of its own, or a file of the build that cannot be written.
	TagWindowsBuildInvalid = "WindowsBuildInvalid"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const TagWindowsCommandFailed = "WindowsCommandFailed"

TagWindowsCommandFailed is the tag of the error for a program of the build that cannot be started or exits with a failure; the metadata "command" and "output" say which and why.

View Source
const (

	// TagWindowsIconInvalid 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.
	TagWindowsIconInvalid = "WindowsIconInvalid"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const (

	// TagWindowsManifestInvalid is the tag of the error for a manifest that cannot be made from the
	// configuration (an application ID, a name or an architecture it cannot have).
	TagWindowsManifestInvalid = "WindowsManifestInvalid"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const (

	// TagWindowsResourceInvalid is the tag of the error for resources that cannot be written: none,
	// an empty one, a duplicate, an unknown architecture, a version that is not up to four numbers.
	TagWindowsResourceInvalid = "WindowsResourceInvalid"
)

The tags of the errors that this file and versioninfo.go make (rm4n0s/errors, R5).

Variables

View Source
var Archs = []Arch{
	{Name: "amd64", GOARCH: "amd64", Machine: 0x8664, AddrNB: 3},
	{Name: "arm64", GOARCH: "arm64", Machine: 0xAA64, AddrNB: 2},
}

Archs are the architectures of Windows that Glutter builds for (SPEC §25.1), amd64 first.

Flutter: no counterpart

View Source
var DefaultVersion = Version{1, 0, 0, 0}

DefaultVersion is the version of an app built without -version.

Flutter: no counterpart

View Source
var IconSizes = []int{16, 24, 32, 48, 64, 128, 256}

IconSizes are the sizes in pixels of the images in the icon of an .exe (SPEC §25.1): the 16 pixels of the title bar and the lists, 24 and 32 for the task bar and the desktop, 48 for the large lists, and 64, 128 and 256 for Explorer's large views. The 256 pixels one is stored as a PNG and the others as bitmaps, as Windows expects.

Flutter: no counterpart

Functions

func BuildSyso

func BuildSyso(arch string, resources []Resource) ([]byte, error)

BuildSyso writes the .syso file for the resources: a COFF object for the architecture with a .rsrc section that holds the resource directory (three levels: type, ID, language), the data entries and the data, and one relocation for each data entry, which the linker resolves to the entry's address in the image (SPEC §25.1). It fails with WindowsResourceInvalid when there are no resources, when two have the same type, ID and language, when one is empty, and for an unknown architecture.

Flutter: no counterpart

func DefaultAppID

func DefaultAppID(pkg string) string

DefaultAppID derives an application ID from a package path: "./examples/counter" is "org.glutter.counter". Characters that an ID cannot have become underscores, and a name that does not start with a letter gets a leading "a".

Flutter: no counterpart

func DefaultIcon

func DefaultIcon() ([]byte, error)

DefaultIcon returns Glutter's icon as a PNG of 256 pixels: a white ring with a gap and a bar, the shape of a "G", on the blue of the Material seed color (the shape of the launcher icon of the Android tool, drawn here at the size the largest image of an .exe icon has).

Flutter: no counterpart

func DefaultName

func DefaultName(pkg string) string

DefaultName is the base name of a package path, such as "counter"; "Glutter" for ".".

Flutter: no counterpart

func Manifest

func Manifest(c ManifestConfig) ([]byte, error)

Manifest returns the text of the application manifest (SPEC §25.1): the assembly identity, version 6 of the Common Controls, the supported operating systems (Windows 10 and 11), the execution level asInvoker, and the Windows settings: per-monitor DPI awareness version 2 (`true/pm` for older builds), the UTF-8 code page and long paths. It fails with WindowsManifestInvalid when the application ID has a character a manifest cannot have, the name is empty or the architecture is not known.

Flutter: no counterpart (windows/runner/runner.exe.manifest)

func Run

Run starts the .exe with the launcher and waits for it (`glutter-windows run`). The Result is returned also when the program fails, so that its output can be shown. It fails with WindowsRunFailed when the program cannot be started or does not end with status 0.

Flutter: no counterpart (flutter run -d windows)

func Shot

func Shot(ctx context.Context, l Launcher, exe string, o ShotOptions) (png []byte, output string, err error)

Shot is proof method F (SPEC §25.13): it runs the .exe with GLUTTER_SCREENSHOT, so that the app saves its own first frame as a PNG and ends, and returns the PNG together with the output of the app. With o.Screen it captures the root window of the X server instead. It fails with WindowsShotFailed (the app failed, or saved no frame) and WindowsScreenUnsupported (Screen with a launcher that cannot).

Flutter: no counterpart (flutter screenshot)

func SysoFile

func SysoFile(arch string) string

SysoFile is the name, in the package's directory, of the file that holds the resources of an architecture: "rsrc_windows_amd64.syso". The go command links every .syso whose name's GOOS and GOARCH match the build.

Flutter: no counterpart

Types

type Arch

type Arch struct {
	// Name is the name the command line and the manifest use: "amd64" or "arm64".
	Name string
	// GOARCH is the value of GOARCH for the go command.
	GOARCH string
	// Machine is the IMAGE_FILE_MACHINE value of the COFF object.
	Machine uint16
	// AddrNB is the type of the relocation that stores an address as an offset from the image base
	// (IMAGE_REL_AMD64_ADDR32NB, IMAGE_REL_ARM64_ADDR32NB).
	AddrNB uint16
}

Arch is a processor architecture an .exe is built for.

Flutter: no counterpart

func FindArch

func FindArch(name string) (Arch, bool)

FindArch returns the architecture with the name.

Flutter: no counterpart

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 .exe to write; "<base name of Package>.exe" when empty. With more than one
	// architecture the architecture is added before the extension: "app_amd64.exe".
	Out string
	// Archs are the architectures to build, by name ("amd64", "arm64"); amd64 when empty.
	Archs []string
	// Debug builds with -tags debug_mode (foundation.DebugMode) and does not strip the program;
	// without it the build is a release, stripped with -ldflags=-s -w.
	Debug bool
	// Console builds a console program (no -H=windowsgui): it opens a console window when started
	// from Explorer, and prints to the terminal it is started from.
	Console bool
	// AppID, Name and Version go into the manifest and the version information; they have defaults
	// (DefaultAppID, DefaultName, DefaultVersion).
	AppID, Name, Version string
	// Icon is a PNG for the icon; Glutter's icon when empty.
	Icon string
	// Env is added to the environment of the go command.
	Env []string
}

BuildOptions are the parameters of Build (the flags of `glutter-windows build`, SPEC §25.1).

Flutter: no counterpart

type BuildResult

type BuildResult struct {
	// Exes are the files written, one per architecture, in the order asked for.
	Exes []Built
	// AppID is the application ID of the manifest.
	AppID string
}

BuildResult says what Build wrote.

Flutter: no counterpart

func Build

func Build(ctx context.Context, run Runner, o BuildOptions) (*BuildResult, error)

Build makes the .exe files of a package (SPEC §25.1): for each architecture it writes the resources (the manifest, the icon, the version information) as a .syso, puts it into a temporary copy of the package's directory (next to the original, named CopyPrefix plus a number; the go command does not take a .syso from an overlay), and runs `go build` on the copy with GOOS=windows and CGO_ENABLED=0. The copy is removed afterwards. The programs run through run. It fails with WindowsBuildInvalid, WindowsManifestInvalid, WindowsResourceInvalid, WindowsIconInvalid and WindowsCommandFailed.

Flutter: no counterpart (flutter build windows)

type Built

type Built struct {
	// Arch is the architecture's name.
	Arch string
	// Path is the .exe, Size its size in bytes.
	Path string
	Size int64
}

Built is one .exe that Build wrote.

Flutter: no counterpart

type Command

type Command struct {
	// Dir is the working directory; the current one when empty.
	Dir string
	// Env is the complete environment; the current one when nil.
	Env []string
	// Name is the program, found on the PATH when it has no directory.
	Name string
	// Args are the arguments.
	Args []string
}

Command is one program the builder runs.

Flutter: no counterpart

func (Command) String

func (c Command) String() string

String is the command line, for messages.

type ExecRunner

type ExecRunner struct{}

ExecRunner is the Runner that runs the programs with os/exec.

Flutter: no counterpart

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, c Command) (string, error)

Run implements Runner.

type Icon

type Icon struct {
	// Images are the RT_ICON resources, one per size of IconSizes, in that order; image i is the
	// resource with ID i+1.
	Images []IconImage
	// Group is the data of the RT_GROUP_ICON resource (a GRPICONDIR that lists Images).
	Group []byte
}

Icon is the icon of an .exe made from a PNG.

Flutter: no counterpart

func NewIcon

func NewIcon(pngData []byte) (*Icon, error)

NewIcon makes the icon of an .exe from a PNG: the image must be square and at least 16 pixels wide. It is scaled to each of IconSizes (not scaled if it has that size already). It fails with WindowsIconInvalid.

Flutter: no counterpart (windows/runner/resources/app_icon.ico)

type IconImage

type IconImage struct {
	// Size is the width and the height in pixels.
	Size int
	// Data is the resource data: a DIB (a BITMAPINFOHEADER with a doubled height, the 32-bit pixels
	// bottom up and the AND mask) for sizes under 256, a PNG for 256.
	Data []byte
}

IconImage is one image of an icon: the data of an RT_ICON resource.

Flutter: no counterpart

type Launcher

type Launcher interface {
	// Launch runs the .exe and returns its exit code and output. A program that exits with a failure
	// is not an error: the status is in the Result.
	Launch(ctx context.Context, exe string, o winetest.RunOptions) (winetest.Result, error)
	// ProgramPath is a file of the host as the program sees it: Z:\tmp\x.png under Wine, the path
	// itself on Windows.
	ProgramPath(hostPath string) string
}

Launcher starts a Windows program and waits for it: under Wine on Linux (WineLauncher), or by itself on Windows (LocalLauncher).

Flutter: no counterpart

type LocalLauncher

type LocalLauncher struct{}

LocalLauncher runs the program itself, which is what `run` and `shot` do on Windows.

Flutter: no counterpart

func (LocalLauncher) Launch

Launch implements Launcher. The program ends with status 124 when o.Timeout (120 seconds when zero) passes, as it does under Wine.

func (LocalLauncher) ProgramPath

func (LocalLauncher) ProgramPath(hostPath string) string

ProgramPath implements Launcher.

type ManifestConfig

type ManifestConfig struct {
	// AppID is the name of the assembly identity, such as "org.glutter.counter": letters, digits,
	// dots, dashes and underscores.
	AppID string
	// Name is the description of the application.
	Name string
	// Version is the version of the assembly identity (four numbers).
	Version Version
	// Arch is the processor architecture: "amd64" or "arm64".
	Arch string
}

ManifestConfig is what the generated application manifest says (SPEC §25.1).

Flutter: no counterpart

type Resource

type Resource struct {
	Type, ID, Lang uint16
	Data           []byte
}

Resource is one resource of an .exe: a type, an ID, a language and the bytes.

Flutter: no counterpart

func Resources

func Resources(manifest []byte, icon *Icon, info VersionInfo) []Resource

Resources returns the resources of an app: the manifest (ID 1, RT_MANIFEST), the icon (RT_ICON with the IDs 1 to 7 and the group RT_GROUP_ICON with ID 1, which is the ID the platform loads for the window class) and the version information (ID 1).

Flutter: no counterpart

type Runner

type Runner interface {
	// Run runs the command and returns its combined output. A command that fails is an error tagged
	// WindowsCommandFailed, with the command line and its output in the metadata.
	Run(ctx context.Context, c Command) (string, error)
}

Runner runs the programs of a build (the go command). A test gives the builder a fake one and checks the command lines.

Flutter: no counterpart

type ScreenLauncher

type ScreenLauncher interface {
	Launcher
	// Capture runs the .exe and saves the root window of its display to the PNG out after
	// GLUTTER_SHOT_DELAY seconds (the environment of o can set it).
	Capture(ctx context.Context, exe, out string, o winetest.RunOptions) (winetest.Result, error)
}

ScreenLauncher is a Launcher that can also save the whole screen the program runs on.

Flutter: no counterpart

type ShotOptions

type ShotOptions struct {
	// Env are more environment variables for the app (KEY=value, GLUTTER_X=v).
	Env []string
	// Screen captures the whole screen of the X server (title bar, other windows, dialogs) instead of
	// the app's own frame. It needs a ScreenLauncher.
	Screen bool
	// Settle is how long to wait, after the app logged its first frame (ShotReadyLine), before the
	// capture of the screen (3 seconds when zero); it is the value of GLUTTER_SHOT_DELAY.
	Settle time.Duration
	// Timeout is how long the app may run (2 minutes when zero).
	Timeout time.Duration
}

ShotOptions are the parameters of Shot.

Flutter: no counterpart

type Version

type Version [4]uint16

Version is a file or product version of four numbers, such as 1.2.3.4.

Flutter: no counterpart

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion reads "1", "1.2", "1.2.3" or "1.2.3.4" (each number from 0 to 65535; a missing one is 0). An empty text is DefaultVersion. It fails with WindowsResourceInvalid.

Flutter: no counterpart (pubspec.yaml version)

func (Version) String

func (v Version) String() string

String is the version as "1.2.3.4".

type VersionInfo

type VersionInfo struct {
	// Version is the file and product version.
	Version Version
	// Name is the product name and the file description.
	Name string
	// AppID is the internal name.
	AppID string
	// FileName is the original file name, such as "counter.exe".
	FileName string
}

VersionInfo is what the VERSIONINFO resource says (SPEC §25.1).

Flutter: no counterpart

func (VersionInfo) Encode

func (vi VersionInfo) Encode() []byte

Encode returns the binary VS_VERSIONINFO structure, the data of the RT_VERSION resource: the fixed file information, a StringFileInfo block with the strings and a VarFileInfo block with the translation.

Flutter: no counterpart

type WineLauncher

type WineLauncher struct {
	// Harness starts Wine.
	Harness *winetest.Harness
	// Headless runs the program on Xvfb, not on the user's display.
	Headless bool
}

WineLauncher runs a program under Wine through the harness of internal/winetest: on a headless X server, or, without Headless, on the display of the environment (the window shows on the screen).

Flutter: no counterpart

func (WineLauncher) Capture

func (w WineLauncher) Capture(ctx context.Context, exe, out string, o winetest.RunOptions) (winetest.Result, error)

Capture implements ScreenLauncher: it runs the program on a headless X server whatever Headless says, because the capture takes the X server's root window.

func (WineLauncher) Launch

Launch implements Launcher.

func (WineLauncher) ProgramPath

func (WineLauncher) ProgramPath(hostPath string) string

ProgramPath implements Launcher: the host's root is the drive Z: of Wine.

Jump to

Keyboard shortcuts

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