forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
133 lines (105 loc) · 3.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// This is a utility which binds to libkb to get the correct version
// for printing out or generating compiled resources for the windows
// executable.
// +build windows
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"time"
"strconv"
"github.com/josephspurrier/goversioninfo"
"github.com/keybase/client/go/libkb"
)
func getBuildName() string {
// Todo: use regular build number when not doing prerelease
gitHash, err := exec.Command("cmd", "/C", "git", "log", "-1", "--pretty=format:%h").Output()
if err != nil {
log.Print("Error generating githash", err)
os.Exit(3)
}
return fmt.Sprintf("%d%02d%02d%02d%02d%02d+%s", time.Now().Year(), time.Now().Month(), time.Now().Day(), time.Now().Hour(), time.Now().Minute(), time.Now().Second(), gitHash)
}
// Create the syso and custom build file
func main() {
outPtr := flag.String("o", "rsrc_windows.syso", "resource output pathname")
printverPtr := flag.Bool("v", false, "print version to console (no .syso output)")
printCustomVerPtr := flag.Bool("cv", false, "print custom version to console (no .syso output)")
printCustomBuildPtr := flag.Bool("cb", false, "print custom build number to console (no .syso output)")
printWinVerPtr := flag.Bool("w", false, "print windows format version to console (no .syso output)")
iconPtr := flag.String("i", "../../media/icons/Keybase.ico", "icon pathname")
fileDescriptionPtr := flag.String("d", "Keybase utility", "File Description")
originalFilenamePtr := flag.String("n", "keybase.exe", "File name")
flag.Parse()
var fv goversioninfo.FileVersion
if int, err := fmt.Sscanf(libkb.Version, "%d.%d.%d", &fv.Major, &fv.Minor, &fv.Patch); int != 3 || err != nil {
log.Printf("Error parsing version %v", err)
os.Exit(3)
}
fv.Build, _ = strconv.Atoi(os.Getenv("KEYBASE_WINBUILD"))
if fv.Build == 0 && libkb.PrereleaseBuild != "" {
fv.Build, _ = strconv.Atoi(libkb.PrereleaseBuild)
}
semVer := fmt.Sprintf("%d.%d.%d-%d", fv.Major, fv.Minor, fv.Patch, fv.Build)
if *printverPtr {
fmt.Print(semVer)
return
}
if *printWinVerPtr {
fmt.Printf("%d.%d.%d.%d", fv.Major, fv.Minor, fv.Patch, fv.Build)
return
}
if *printCustomVerPtr {
customVer := fmt.Sprintf("%d.%d.%d-%s", fv.Major, fv.Minor, fv.Patch, getBuildName())
fmt.Print(customVer)
return
}
if *printCustomBuildPtr {
fmt.Printf("%s", getBuildName())
return
}
// Create a new container
vi := &goversioninfo.VersionInfo{
FixedFileInfo: goversioninfo.FixedFileInfo{
FileVersion: fv,
ProductVersion: fv,
FileFlagsMask: "3f",
FileFlags: "00",
FileOS: "040004",
FileType: "01",
FileSubType: "00",
},
StringFileInfo: goversioninfo.StringFileInfo{
CompanyName: "Keybase, Inc.",
FileDescription: *fileDescriptionPtr,
InternalName: "Keybase",
LegalCopyright: "Copyright (c) 2015, Keybase",
OriginalFilename: *originalFilenamePtr,
ProductName: "Keybase",
ProductVersion: libkb.VersionString(),
},
VarFileInfo: goversioninfo.VarFileInfo{
Translation: goversioninfo.Translation{
LangID: 0x409, // english
CharsetID: 0x4B0, // unicode
},
},
}
// Fill the structures with config data
vi.Build()
// Write the data to a buffer
vi.Walk()
// Optionally, embed an icon by path
// If the icon has multiple sizes, all of the sizes will be embedded
vi.IconPath = *iconPtr
// Create the file
if err := vi.WriteSyso(*outPtr); err != nil {
log.Printf("Error writing %s: %v", *outPtr, err)
os.Exit(3)
}
}