github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/scripts/windows/generate-windows-version-info/main.go (about) 1 package main 2 3 import ( 4 "errors" 5 "flag" 6 "fmt" 7 "os" 8 "strings" 9 10 "github.com/blang/semver" 11 "github.com/josephspurrier/goversioninfo" 12 ) 13 14 func main() { 15 var version string 16 flag.StringVar(&version, "version", "", "Version in semver format.") 17 18 var outputPath string 19 flag.StringVar(&outputPath, "out", "", "Output file path.") 20 21 var iconPath string 22 flag.StringVar(&iconPath, "icon", "", "Icon file path.") 23 flag.Parse() 24 25 if err := generateVersionInfo(version, outputPath, iconPath); err != nil { 26 _, _ = fmt.Fprintln(os.Stderr, err) 27 os.Exit(1) 28 } 29 } 30 31 func generateVersionInfo(version, outputPath, iconPath string) error { 32 version = strings.Trim(version, `"`) 33 v, err := semver.Parse(strings.TrimPrefix(version, "v")) 34 35 if version == "" { 36 return errors.New("version is required") 37 } 38 39 if err != nil { 40 return fmt.Errorf("invalid version %q: %w", version, err) 41 } 42 43 if outputPath == "" { 44 return errors.New("output path is required") 45 } 46 47 versionInfo := goversioninfo.VersionInfo{ 48 FixedFileInfo: goversioninfo.FixedFileInfo{ 49 FileVersion: goversioninfo.FileVersion{ 50 Major: int(v.Major), 51 Minor: int(v.Minor), 52 Patch: int(v.Patch), 53 Build: 0, 54 }, 55 ProductVersion: goversioninfo.FileVersion{ 56 Major: int(v.Major), 57 Minor: int(v.Minor), 58 Patch: int(v.Patch), 59 Build: 0, 60 }, 61 FileFlagsMask: "3f", 62 FileFlags: "00", 63 FileOS: "040004", 64 FileType: "01", 65 FileSubType: "00", 66 }, 67 StringFileInfo: goversioninfo.StringFileInfo{ 68 Comments: "", 69 CompanyName: "Pyroscope, Inc", 70 FileDescription: "Pyroscope continuous profiling platform agent", 71 FileVersion: version, 72 InternalName: "pyroscope.exe", 73 LegalCopyright: "Copyright (c) 2021 Pyroscope, Inc", 74 LegalTrademarks: "", 75 OriginalFilename: "", 76 PrivateBuild: "", 77 ProductName: "Pyroscope Agent", 78 ProductVersion: version, 79 SpecialBuild: "", 80 }, 81 VarFileInfo: goversioninfo.VarFileInfo{ 82 Translation: goversioninfo.Translation{ 83 LangID: goversioninfo.LngUSEnglish, 84 CharsetID: goversioninfo.CsUnicode, 85 }, 86 }, 87 IconPath: iconPath, 88 ManifestPath: "", 89 } 90 91 versionInfo.Build() 92 versionInfo.Walk() 93 94 if err = versionInfo.WriteSyso(outputPath, "amd64"); err != nil { 95 return fmt.Errorf("failed to write output file %s: %w", outputPath, err) 96 } 97 98 return nil 99 }