Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

uname-it: add uname-format output format variables #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions go.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
)

type OutputTemplateData struct {
Dir string
OS string
Arch string
Dir string
OS string
OSUname string
Arch string
ArchUname string
}

type CompileOpts struct {
Expand Down Expand Up @@ -59,9 +61,11 @@ func GoCrossCompile(opts *CompileOpts) error {
return err
}
tplData := OutputTemplateData{
Dir: filepath.Base(opts.PackagePath),
OS: opts.Platform.OS,
Arch: opts.Platform.Arch,
Dir: filepath.Base(opts.PackagePath),
OS: opts.Platform.OS,
OSUname: opts.Platform.OSUname(),
Arch: opts.Platform.Arch,
ArchUname: opts.Platform.ArchUname(),
}
if err := tpl.Execute(&outputPath, &tplData); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ Output path template:

The output path for the compiled binaries is specified with the
"-output" flag. The value is a string that is a Go text template.
The default value is "{{.Dir}}_{{.OS}}_{{.Arch}}". The variables and
their values should be self-explanatory.
The default value is "{{.Dir}}_{{.OS}}_{{.Arch}}". Other available
variables are OSUname and ArchUname which should correspond to uname -s
and uname -m respectively.

Platforms (OS/Arch):

Expand Down
45 changes: 45 additions & 0 deletions platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,51 @@ func (p *Platform) String() string {
return fmt.Sprintf("%s/%s", p.OS, p.Arch)
}

/// Like `uname -s`
// Matches https://github.com/golang/go/blob/master/src/go/build/syslist.go
func (p *Platform) OSUname() string {
return map[string]string{
//"android":
"darwin": "Darwin",
"dragonfly": "DragonFly",
"freebsd": "FreeBSD",
"linux": "Linux",
//"nacl":
"netbsd": "NetBSD",
"openbsd": "OpenBSD",
"plan9": "Plan9",
"solaris": "SunOS",
"windows": "Windows",
//"zos":
}[p.OS]
}

/// Like `uname -m`
// Matches https://github.com/golang/go/blob/master/src/go/build/syslist.go
func (p *Platform) ArchUname() string {
return map[string]string{
"386": "i386",
"amd64": "x86_64",
//"amd64p32":
"arm": "arm",
//"armbe":
"arm64": "aarch64",
//"arm64be":
"ppc64": "ppc64",
"ppc64le": "ppc64le",
//"mips":
//"mipsle":
//"mips64":
//"mips64p32":
//"mips64p32le":
//"ppc":
//"s390":
//"s390x":
//"sparc":
//"sparc64":
}[p.Arch]
}

var (
Platforms_1_0 = []Platform{
{"darwin", "386", true},
Expand Down