MCPcopy
hub / github.com/syncthing/syncthing / shouldBuildSyso

Function shouldBuildSyso

build.go:686–742  ·  view source on GitHub ↗
(dir string)

Source from the content-addressed store, hash-verified

684}
685
686func shouldBuildSyso(dir string) (string, error) {
687 type M map[string]interface{}
688 version := getVersion()
689 version = strings.TrimPrefix(version, "v")
690 major, minor, patch := semanticVersion()
691 bs, err := json.Marshal(M{
692 "FixedFileInfo": M{
693 "FileVersion": M{
694 "Major": major,
695 "Minor": minor,
696 "Patch": patch,
697 },
698 "ProductVersion": M{
699 "Major": major,
700 "Minor": minor,
701 "Patch": patch,
702 },
703 },
704 "StringFileInfo": M{
705 "CompanyName": "The Syncthing Authors",
706 "FileDescription": "Syncthing - Open Source Continuous File Synchronization",
707 "FileVersion": version,
708 "InternalName": "syncthing",
709 "LegalCopyright": "The Syncthing Authors",
710 "OriginalFilename": "syncthing",
711 "ProductName": "Syncthing",
712 "ProductVersion": version,
713 },
714 "IconPath": "assets/logo.ico",
715 })
716 if err != nil {
717 return "", err
718 }
719
720 jsonPath := filepath.Join(dir, "versioninfo.json")
721 err = os.WriteFile(jsonPath, bs, 0o644)
722 if err != nil {
723 return "", errors.New("failed to create " + jsonPath + ": " + err.Error())
724 }
725
726 defer func() {
727 if err := os.Remove(jsonPath); err != nil {
728 log.Printf("Warning: unable to remove generated %s: %v. Please remove it manually.", jsonPath, err)
729 }
730 }()
731
732 sysoPath := filepath.Join(dir, "cmd", "syncthing", "resource.syso")
733
734 // See https://github.com/josephspurrier/goversioninfo#command-line-flags
735 arm := strings.HasPrefix(goarch, "arm")
736 a64 := strings.Contains(goarch, "64")
737 if _, err := runError("goversioninfo", "-o", sysoPath, fmt.Sprintf("-arm=%v", arm), fmt.Sprintf("-64=%v", a64)); err != nil {
738 return "", errors.New("failed to create " + sysoPath + ": " + err.Error())
739 }
740
741 return sysoPath, nil
742}
743

Callers 2

installFunction · 0.85
buildFunction · 0.85

Calls 8

getVersionFunction · 0.85
semanticVersionFunction · 0.85
runErrorFunction · 0.85
MarshalMethod · 0.80
ContainsMethod · 0.80
NewMethod · 0.65
ErrorMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected