This repository has been archived by the owner on Aug 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.go
127 lines (102 loc) · 3.1 KB
/
go.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
package ver
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"time"
log "github.com/sirupsen/logrus"
"github.com/josephspurrier/goversioninfo"
)
const (
goSysoFilename = "version_info.syso"
)
func WriteGoSysoFile(vi *VersionInformation) error {
// this feature works on windows, only
if runtime.GOOS != "windows" {
log.Warnf("Creating Go executable version information is supported on Windows, only")
return nil
}
// create the manifest file
manifestFile := filepath.Join(os.TempDir(), fmt.Sprintf("ktn-build-info-%v.manifest", time.Now().UnixNano()))
manifest, err := getGoManifestXml(vi)
if err != nil {
return fmt.Errorf("Failed to generate manifest file: %v", err)
}
err = ioutil.WriteFile(manifestFile, []byte(manifest), 0644)
if err != nil {
return fmt.Errorf("Failed to write manifest file: %v", err)
}
defer os.Remove(manifestFile)
// copy values
gvi := goversioninfo.VersionInfo{
FixedFileInfo: goversioninfo.FixedFileInfo{
FileVersion: goversioninfo.FileVersion{
Major: vi.Major,
Minor: vi.Minor,
Patch: vi.Hotfix,
Build: vi.Build,
},
FileFlagsMask: "3f",
FileFlags: "00",
FileOS: "040004",
FileType: "01",
FileSubType: "00",
},
StringFileInfo: goversioninfo.StringFileInfo{
CompanyName: vi.Author,
ProductName: vi.Name,
ProductVersion: vi.VersionTitle(),
FileDescription: vi.Description,
LegalCopyright: fmt.Sprintf("Copyright %v %v. License: %v", time.Now().Year(), vi.Author, vi.License),
},
VarFileInfo: goversioninfo.VarFileInfo{
Translation: goversioninfo.Translation{
LangID: goversioninfo.LngUSEnglish,
CharsetID: goversioninfo.CsUnicode,
},
},
ManifestPath: manifestFile,
}
// prepare
gvi.Build()
gvi.Walk()
// write the syso file
err = gvi.WriteSyso(goSysoFilename, runtime.GOARCH)
if err != nil {
return fmt.Errorf("Failed to generate Go syso file: %v", err)
}
return nil
}
func getGoManifestXml(vi *VersionInformation) (string, error) {
manifest :=
`<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>
</compatibility>
</assembly>`
return manifest, nil
}