Skip to content

Commit

Permalink
Use arduino101load/version package to automatically change build version
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Feb 7, 2023
1 parent 2ccbd62 commit fa827ec
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
13 changes: 13 additions & 0 deletions globals/globals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package globals

import (
"os"
"path/filepath"

"github.com/arduino/arduino101load/version"
)

var (
// VersionInfo contains all info injected during build
VersionInfo = version.NewInfo(filepath.Base(os.Args[0]))
)
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/arduino/arduino101load

go 1.19

require github.com/mattn/go-shellwords v1.0.12
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

"github.com/arduino/arduino101load/globals"
shellwords "github.com/mattn/go-shellwords"
)

Expand All @@ -34,8 +35,6 @@ var (
rtos_compliance_offset = flag.Int("rtos_fw_pos", 0, "RTOS FW ID offset")
)

const Version = "2.2.2"

const dfu_flags = "-d,8087:0ABA"
const rtos_firmware = "quark.bin"
const ble_firmware = "ble_core.bin"
Expand Down Expand Up @@ -205,7 +204,7 @@ func main_load() {
firmwarePath = filepath.Join(filepath.Dir(firmwarePath), "firmwares")

if stat, err := os.Stat(*core); err == nil && stat.IsDir() {
firmwarePath = *core
firmwarePath = *core
} else {
firmwarePath = filepath.Join(firmwarePath, *core)
}
Expand Down Expand Up @@ -311,7 +310,7 @@ func main() {

flag.Parse()

PrintlnVerbose(name + " " + Version + " - compiled with " + runtime.Version())
PrintlnVerbose(globals.VersionInfo)

if *copier {
if *from == "" || *to == "" {
Expand Down
39 changes: 39 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package version

import "fmt"

var (
defaultVersionString = "0.0.0-git"
versionString = ""
commit = ""
date = ""
)

// Info is a struct that contains information about the application
type Info struct {
Application string `json:"Application"`
VersionString string `json:"VersionString"`
Commit string `json:"Commit"`
Date string `json:"Date"`
}

// NewInfo returns a pointer to an updated Info struct
func NewInfo(application string) *Info {
return &Info{
Application: application,
VersionString: versionString,
Commit: commit,
Date: date,
}
}

func (i *Info) String() string {
return fmt.Sprintf("%[1]s Version: %[2]s Commit: %[3]s Date: %[4]s", i.Application, i.VersionString, i.Commit, i.Date)
}

//nolint:gochecknoinits
func init() {
if versionString == "" {
versionString = defaultVersionString
}
}

0 comments on commit fa827ec

Please sign in to comment.