Skip to content

Commit fa827ec

Browse files
Use arduino101load/version package to automatically change build version
1 parent 2ccbd62 commit fa827ec

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

globals/globals.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package globals
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/arduino/arduino101load/version"
8+
)
9+
10+
var (
11+
// VersionInfo contains all info injected during build
12+
VersionInfo = version.NewInfo(filepath.Base(os.Args[0]))
13+
)

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/arduino/arduino101load
2+
3+
go 1.19
4+
5+
require github.com/mattn/go-shellwords v1.0.12

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
2+
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515
"time"
1616

17+
"github.com/arduino/arduino101load/globals"
1718
shellwords "github.com/mattn/go-shellwords"
1819
)
1920

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

37-
const Version = "2.2.2"
38-
3938
const dfu_flags = "-d,8087:0ABA"
4039
const rtos_firmware = "quark.bin"
4140
const ble_firmware = "ble_core.bin"
@@ -205,7 +204,7 @@ func main_load() {
205204
firmwarePath = filepath.Join(filepath.Dir(firmwarePath), "firmwares")
206205

207206
if stat, err := os.Stat(*core); err == nil && stat.IsDir() {
208-
firmwarePath = *core
207+
firmwarePath = *core
209208
} else {
210209
firmwarePath = filepath.Join(firmwarePath, *core)
211210
}
@@ -311,7 +310,7 @@ func main() {
311310

312311
flag.Parse()
313312

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

316315
if *copier {
317316
if *from == "" || *to == "" {

version/version.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package version
2+
3+
import "fmt"
4+
5+
var (
6+
defaultVersionString = "0.0.0-git"
7+
versionString = ""
8+
commit = ""
9+
date = ""
10+
)
11+
12+
// Info is a struct that contains information about the application
13+
type Info struct {
14+
Application string `json:"Application"`
15+
VersionString string `json:"VersionString"`
16+
Commit string `json:"Commit"`
17+
Date string `json:"Date"`
18+
}
19+
20+
// NewInfo returns a pointer to an updated Info struct
21+
func NewInfo(application string) *Info {
22+
return &Info{
23+
Application: application,
24+
VersionString: versionString,
25+
Commit: commit,
26+
Date: date,
27+
}
28+
}
29+
30+
func (i *Info) String() string {
31+
return fmt.Sprintf("%[1]s Version: %[2]s Commit: %[3]s Date: %[4]s", i.Application, i.VersionString, i.Commit, i.Date)
32+
}
33+
34+
//nolint:gochecknoinits
35+
func init() {
36+
if versionString == "" {
37+
versionString = defaultVersionString
38+
}
39+
}

0 commit comments

Comments
 (0)