Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FyneApp.toml #87

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - Fyne.io fyne-cross

## Unreleased

### Added

- Add support for FyneApp.toml #78

## 1.1.3 - 02 Nov 2021

### Fixed
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/fyne-io/fyne-cross
go 1.13

require (
github.com/BurntSushi/toml v0.4.1
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
7 changes: 6 additions & 1 deletion internal/command/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ func (cmd *Android) Run() error {

for _, ctx := range cmd.Context {

err := bumpFyneAppBuild(ctx)
if err != nil {
log.Infof("[i] FyneApp.toml: unable to bump the build number. Error: %s", err)
}

log.Infof("[i] Target: %s/%s", ctx.OS, ctx.Architecture)
log.Debugf("%#v", ctx)

//
// pull image, if requested
//
err := pullImage(ctx)
err = pullImage(ctx)
if err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/fyne-io/fyne-cross/internal/icon"
"github.com/fyne-io/fyne-cross/internal/log"
"github.com/fyne-io/fyne-cross/internal/metadata"
"github.com/fyne-io/fyne-cross/internal/volume"
"golang.org/x/sys/execabs"
)
Expand Down Expand Up @@ -238,3 +239,14 @@ func fyneReleaseHost(ctx Context) error {
}
return nil
}

// bumpFyneAppBuild increments the BuildID into the FyneApp.toml, if any,
// to behave like the fyne CLI tool
func bumpFyneAppBuild(ctx Context) error {
data, err := metadata.LoadStandard(ctx.Volume.WorkDirHost())
if err != nil {
return nil // no metadata to update
}
data.Details.Build++
return metadata.SaveStandard(data, ctx.Volume.WorkDirHost())
}
7 changes: 6 additions & 1 deletion internal/command/darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ func (cmd *Darwin) Run() error {

for _, ctx := range cmd.Context {

err := bumpFyneAppBuild(ctx)
if err != nil {
log.Infof("[i] FyneApp.toml: unable to bump the build number. Error: %s", err)
}

log.Infof("[i] Target: %s/%s", ctx.OS, ctx.Architecture)
log.Debugf("%#v", ctx)

//
// pull image, if requested
//
err := pullImage(ctx)
err = pullImage(ctx)
if err != nil {
return err
}
Expand Down
30 changes: 27 additions & 3 deletions internal/command/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/fyne-io/fyne-cross/internal/metadata"
"github.com/fyne-io/fyne-cross/internal/volume"
)

Expand Down Expand Up @@ -73,10 +74,33 @@ func newCommonFlags() (*CommonFlags, error) {
return nil, err
}

appID := ""
appVersion := "1.0"
appBuild := 1

data, _ := metadata.LoadStandard(rootDir)
if data != nil {
if data.Details.Icon != "" {
defaultIcon = data.Details.Icon
}
if data.Details.Name != "" {
name = data.Details.Name
}
if data.Details.ID != "" {
appID = data.Details.ID
}
if data.Details.Version != "" {
appVersion = data.Details.Version
}
if data.Details.Build != 0 {
appBuild = data.Details.Build
}
}

flags := &CommonFlags{}
flagSet.IntVar(&flags.AppBuild, "app-build", 1, "Build number, should be greater than 0 and incremented for each build")
flagSet.StringVar(&flags.AppID, "app-id", "", "Application ID used for distribution")
flagSet.StringVar(&flags.AppVersion, "app-version", "1.0", "Version number in the form x, x.y or x.y.z semantic version")
flagSet.IntVar(&flags.AppBuild, "app-build", appBuild, "Build number, should be greater than 0 and incremented for each build")
flagSet.StringVar(&flags.AppID, "app-id", appID, "Application ID used for distribution")
flagSet.StringVar(&flags.AppVersion, "app-version", appVersion, "Version number in the form x, x.y or x.y.z semantic version")
flagSet.StringVar(&flags.CacheDir, "cache", cacheDir, "Directory used to share/cache sources and dependencies")
flagSet.BoolVar(&flags.NoCache, "no-cache", false, "Do not use the go build cache")
flagSet.Var(&flags.Env, "env", "List of additional env variables specified as KEY=VALUE")
Expand Down
7 changes: 6 additions & 1 deletion internal/command/freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ func (cmd *FreeBSD) Run() error {

for _, ctx := range cmd.Context {

err := bumpFyneAppBuild(ctx)
if err != nil {
log.Infof("[i] FyneApp.toml: unable to bump the build number. Error: %s", err)
}

log.Infof("[i] Target: %s/%s", ctx.OS, ctx.Architecture)
log.Debugf("%#v", ctx)

//
// pull image, if requested
//
err := pullImage(ctx)
err = pullImage(ctx)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/command/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ func (cmd *Linux) Run() error {

for _, ctx := range cmd.Context {

err := bumpFyneAppBuild(ctx)
if err != nil {
log.Infof("[i] FyneApp.toml: unable to bump the build number. Error: %s", err)
}

log.Infof("[i] Target: %s/%s", ctx.OS, ctx.Architecture)
log.Debugf("%#v", ctx)

//
// pull image, if requested
//
err := pullImage(ctx)
err = pullImage(ctx)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/command/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ func (cmd *Windows) Run() error {

for _, ctx := range cmd.CmdContext {

err := bumpFyneAppBuild(ctx)
if err != nil {
log.Infof("[i] FyneApp.toml: unable to bump the build number. Error: %s", err)
}

log.Infof("[i] Target: %s/%s", ctx.OS, ctx.Architecture)
log.Debugf("%#v", ctx)

//
// pull image, if requested
//
err := pullImage(ctx)
err = pullImage(ctx)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions internal/metadata/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package metadata

// FyneApp describes the top level metadata for building a fyne application
type FyneApp struct {
Website string `toml:",omitempty"`
Details AppDetails
}

// AppDetails describes the build information, this group may be OS or arch specific
type AppDetails struct {
Icon string `toml:",omitempty"`
Name, ID string `toml:",omitempty"`
Version string `toml:",omitempty"`
Build int `toml:",omitempty"`
}
39 changes: 39 additions & 0 deletions internal/metadata/load.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package metadata

import (
"io"
"io/ioutil"
"os"
"path/filepath"

"github.com/BurntSushi/toml"
)

// Load attempts to read a FyneApp metadata from the provided reader.
// If this cannot be done an error will be returned.
func Load(r io.Reader) (*FyneApp, error) {
str, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}

var data FyneApp
if _, err := toml.Decode(string(str), &data); err != nil {
return nil, err
}

return &data, nil
}

// LoadStandard attempts to read a FyneApp metadata from the `FyneApp.toml` file in the specified dir.
// If the file cannot be found or parsed an error will be returned.
func LoadStandard(dir string) (*FyneApp, error) {
path := filepath.Join(dir, "FyneApp.toml")
r, err := os.Open(path)
if err != nil {
return nil, err
}

defer r.Close()
return Load(r)
}
21 changes: 21 additions & 0 deletions internal/metadata/load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package metadata

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadAppMetadata(t *testing.T) {
r, err := os.Open("./testdata/FyneApp.toml")
assert.Nil(t, err)
defer r.Close()

data, err := Load(r)
assert.Nil(t, err)
assert.Equal(t, "https://apps.fyne.io", data.Website)
assert.Equal(t, "io.fyne.fyne", data.Details.ID)
assert.Equal(t, "v1.0", data.Details.Version)
assert.Equal(t, 1, data.Details.Build)
}
37 changes: 37 additions & 0 deletions internal/metadata/save.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package metadata

import (
"bytes"
"io"
"os"
"path/filepath"

"github.com/BurntSushi/toml"
)

// Save attempts to write a FyneApp metadata to the provided writer.
// If the encoding fails an error will be returned.
func Save(f *FyneApp, w io.Writer) error {
var buf bytes.Buffer
e := toml.NewEncoder(&buf)
err := e.Encode(f)
if err != nil {
return err
}

_, err = w.Write(buf.Bytes())
return err
}

// SaveStandard attempts to save a FyneApp metadata to the `FyneApp.toml` file in the specified dir.
// If the file cannot be written or encoding fails an error will be returned.
func SaveStandard(f *FyneApp, dir string) error {
path := filepath.Join(dir, "FyneApp.toml")
w, err := os.Create(path)
if err != nil {
return err
}

defer w.Close()
return Save(f, w)
}
37 changes: 37 additions & 0 deletions internal/metadata/save_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package metadata

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSaveAppMetadata(t *testing.T) {
r, err := os.Open("./testdata/FyneApp.toml")
assert.Nil(t, err)
data, err := Load(r)
_ = r.Close()
assert.Nil(t, err)
assert.Equal(t, 1, data.Details.Build)

data.Details.Build++

versionPath := "./testdata/Version.toml"
w, err := os.Create(versionPath)
assert.Nil(t, err)
err = Save(data, w)
assert.Nil(t, err)
defer func() {
os.Remove(versionPath)
}()
_ = w.Close()

r, err = os.Open(versionPath)
assert.Nil(t, err)
defer r.Close()

data2, err := Load(r)
assert.Nil(t, err)
assert.Equal(t, 2, data2.Details.Build)
}
9 changes: 9 additions & 0 deletions internal/metadata/testdata/FyneApp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Website = "https://apps.fyne.io"

[Details]
Name = "Fyne App"
ID = "io.fyne.fyne"
Icon = "https://conf.fyne.io/assets/img/fyne.png"
Version = "v1.0"
Build = 1