Skip to content

Commit

Permalink
Merge pull request #6 from alficles/master
Browse files Browse the repository at this point in the history
Added architecture support via command line argument.
  • Loading branch information
josephspurrier committed Jun 22, 2016
2 parents 096c7bd + 2545125 commit 53f6213
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
10 changes: 9 additions & 1 deletion cmd/goversioninfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func main() {
flagTranslation := flag.Int("translation", 0, "translation ID")
flagCharset := flag.Int("charset", 0, "charset ID")

flag64 := flag.Bool("64", false, "generate 64-bit binaries")

flagVerMajor := flag.Int("ver-major", -1, "FileVersion.Major")
flagVerMinor := flag.Int("ver-minor", -1, "FileVersion.Minor")
flagVerPatch := flag.Int("ver-patch", -1, "FileVersion.Patch")
Expand Down Expand Up @@ -150,8 +152,14 @@ func main() {
// Write the data to a buffer
vi.Walk()

// Set the architecture, defaulted to 32-bit.
arch := "386" // 32-bit
if flag64 != nil && *flag64 {
arch = "amd64" // 64-bit
}

// Create the file
if err := vi.WriteSyso(*flagOut); err != nil {
if err := vi.WriteSyso(*flagOut, arch); err != nil {
log.Printf("Error writing syso: %v", err)
os.Exit(3)
}
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func logic() {
vi.IconPath = "icon.ico"

// Create the file
if err := vi.WriteSyso("resource.syso"); err != nil {
if err := vi.WriteSyso("resource.syso", "386"); err != nil {
log.Printf("Error writing syso: %v", err)
os.Exit(3)
}
Expand Down
11 changes: 9 additions & 2 deletions goversioninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func (vi *VersionInfo) Walk() {
vi.Buffer = b
}

// WriteSyso creates a resource file from the version info and optionally an icon
func (vi *VersionInfo) WriteSyso(filename string) error {
// WriteSyso creates a resource file from the version info and optionally an icon.
// arch must be an architecture string accepted by coff.Arch, like "386" or "amd64"
func (vi *VersionInfo) WriteSyso(filename string, arch string) error {

// Channel for generating IDs
newID := make(chan uint16)
Expand All @@ -184,6 +185,12 @@ func (vi *VersionInfo) WriteSyso(filename string) error {
// Create a new RSRC section
coff := coff.NewRSRC()

// Set the architechture
err := coff.Arch(arch)
if err != nil {
return err
}

// ID 16 is for Version Information
coff.AddResource(16, 1, SizedReader{&vi.Buffer})

Expand Down
22 changes: 15 additions & 7 deletions goversioninfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ func testFile(t *testing.T, filename string) {
}
}

func TestWrite(t *testing.T) {
func TestWrite32(t *testing.T) {
doTestWrite(t, "386")
}

func TestWrite64(t *testing.T) {
doTestWrite(t, "amd64")
}

func doTestWrite(t *testing.T, arch string) {
filename := "cmd"

path, _ := filepath.Abs("./tests/" + filename + ".json")
Expand All @@ -86,7 +94,7 @@ func TestWrite(t *testing.T) {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, arch)

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -143,7 +151,7 @@ func TestIcon(t *testing.T) {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, "386")

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -181,7 +189,7 @@ func TestBadIcon(t *testing.T) {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, "386")

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -219,7 +227,7 @@ func TestTimestamp(t *testing.T) {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, "386")

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -318,7 +326,7 @@ func ExampleUseIcon() {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, "386")

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -355,7 +363,7 @@ func ExampleUseTimestamp() {

file := "resource.syso"

vi.WriteSyso(file)
vi.WriteSyso(file, "386")

_, err = ioutil.ReadFile(file)
if err != nil {
Expand Down

0 comments on commit 53f6213

Please sign in to comment.