~whereswaldon/arbor-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v2] Start the transition to Mage.

Details
Message ID
<20201222011819.19456-1-jwhett@protonmail.com>
DKIM signature
missing
Download raw message
Patch: +159 -37
From: Josh Whetton <whetton.josh@gmail.com>

Translate some Makefile targets to use Mage: magefile.org
Targets now implemented in mage will be called by make
for backwards compatability.
---
 Makefile                    |  44 +++--------
 chat.arbor.Client.Sprig.yml |   1 +
 go.mod                      |   2 +-
 go.sum                      |   4 +-
 magefile.go                 | 145 ++++++++++++++++++++++++++++++++++++
 5 files changed, 159 insertions(+), 37 deletions(-)
 create mode 100644 magefile.go

diff --git a/Makefile b/Makefile
index 8bf352e..247e6a5 100644
--- a/Makefile
+++ b/Makefile
@@ -12,18 +12,6 @@ GOFLAGS := -ldflags=-X=main.Version="$(EMBEDDED_VERSION)"
ANDROID_APK = sprig.apk
ANDROID_SDK_ROOT := $(ANDROID_HOME)

WINDOWS_BIN = sprig.exe
WINDOWS_ARCHIVE = sprig-windows.zip

LINUX_BIN = sprig
LINUX_ARCHIVE = sprig-linux.tar.xz
LINUX_FILES = $(LINUX_BIN) ./desktop-assets ./install-linux.sh ./appicon.png ./LICENSE.txt

FPNAME = chat.arbor.Client.Sprig
FPCONFIG = $(FPNAME).yml
FPBUILD = pakbuild
FPREPO := /data/fp-repo

MACOS_BIN = sprig-mac
MACOS_APP = sprig.app
MACOS_ARCHIVE = sprig-macos.tar.gz
@@ -43,21 +31,11 @@ $(KEYSTORE):
	mkdir -p $(ANDROID_CONFIG)
	keytool -genkey -v -keystore $(ANDROID_CONFIG)/debug.keystore -alias androiddebugkey -storepass android -keypass android -keyalg RSA -validity 14000

windows: $(WINDOWS_ARCHIVE)

$(WINDOWS_ARCHIVE): $(WINDOWS_BIN)
	zip $(WINDOWS_ARCHIVE) $(WINDOWS_BIN)

$(WINDOWS_BIN): $(SOURCE)
	env GOOS=windows GOFLAGS=$(GOFLAGS) go build -o $(WINDOWS_BIN) .

linux: $(LINUX_ARCHIVE)

$(LINUX_ARCHIVE): $(LINUX_BIN)
	tar -cJf $(LINUX_ARCHIVE) $(LINUX_FILES)
windows:
	mage windows

$(LINUX_BIN): $(SOURCE)
	env GOOS=linux GOFLAGS=$(GOFLAGS) go build -o $(LINUX_BIN) .
linux:
	mage linux

macos: $(MACOS_ARCHIVE)

@@ -91,21 +69,19 @@ logs:
	adb logcat -s -T1 $(APPID):\*

fp:
	flatpak-builder --force-clean $(FPBUILD) $(FPCONFIG)
	mage flatpak

fp-shell:
	flatpak-builder --run $(FPBUILD) $(FPCONFIG) sh
	mage flatpakShell

fp-install:
	flatpak-builder --user --install --force-clean $(FPBUILD) $(FPCONFIG)
	mage flatpakInstall

fp-run:
	flatpak run $(FPCONFIG)
	mage flatpakRun

fp-repo:
	flatpak-builder --force-clean --repo=$(FPREPO) $(FPBUILD) $(FPCONFIG)
	mage flatpakRepo

clean:
	rm -rf $(ANDROID_APK) $(WINDOWS_ARCHIVE) \
	    $(WINDOWS_BIN) $(LINUX_ARCHIVE) $(LINUX_BIN) \
	    $(MACOS_ARCHIVE) $(MACOS_BIN) $(FPBUILD)
	mage clean
diff --git a/chat.arbor.Client.Sprig.yml b/chat.arbor.Client.Sprig.yml
index 3759deb..1b0f215 100644
--- a/chat.arbor.Client.Sprig.yml
+++ b/chat.arbor.Client.Sprig.yml
@@ -40,4 +40,5 @@ modules:
    sources:
      - type: git
        url: https://git.sr.ht/~whereswaldon/sprig
        branch: main

diff --git a/go.mod b/go.mod
index 3b32190..595b415 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
	git.sr.ht/~whereswaldon/niotify v0.0.4-0.20200831115722-2354c7f8372f
	git.sr.ht/~whereswaldon/scroll v0.0.0-20201124194830-0742e8213a01
	git.sr.ht/~whereswaldon/sprout-go v0.0.0-20201031213922-5dae1cbb80f6
	github.com/pkg/profile v1.5.0
	github.com/magefile/mage v1.10.0
	golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
	golang.org/x/exp v0.0.0-20201008143054-e3b2a7f2fdc7
	golang.org/x/sys v0.0.0-20201126233918-771906719818 // indirect
diff --git a/go.sum b/go.sum
index b4b7281..396c20e 100644
--- a/go.sum
+++ b/go.sum
@@ -57,10 +57,10 @@ github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08 h1:V0an7KRw92wmJysvFvtqtKMAPmvS5O0jtB0nYo6t+gs=
github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08/go.mod h1:dFWs1zEqDjFtnBXsd1vPOZaLsESovai349994nHx3e0=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM=
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/pkg/profile v1.5.0 h1:042Buzk+NhDI+DeSAA62RwJL8VAuZUMQZUjCsRz1Mug=
github.com/pkg/profile v1.5.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
diff --git a/magefile.go b/magefile.go
new file mode 100644
index 0000000..bc5f828
--- /dev/null
+++ b/magefile.go
@@ -0,0 +1,145 @@
// +build mage

package main

import (
	"archive/zip"
	"io/ioutil"
	"os"

	"github.com/magefile/mage/mg"
	"github.com/magefile/mage/sh"
)

var LINUX_BIN = "sprig"
var LINUX_ARCHIVE = "sprig-linux.tar.xz"
var WINDOWS_BIN = "sprig.exe"
var WINDOWS_ARCHIVE = "sprig-windows.zip"
var FPNAME = "chat.arbor.Client.Sprig"
var FPCONFIG = FPNAME + ".yml"
var FPBUILD = "pakbuild"
var FPREPO = "/data/fp-repo"

var Aliases = map[string]interface{}{
	"c":   Clean,
	"l":   Linux,
	"w":   Windows,
	"fp":  Flatpak,
	"run": FlatpakRun,
}

func goFlags() string {
	return "-ldflags=-X=main.Version=" + embeddedVersion()
}

func embeddedVersion() string {
	gitVersion, err := sh.Output("git", "describe", "--tags", "--dirty", "--always")
	if err != nil {
		return "git"
	}
	return gitVersion
}

// Build all binary targets
func All() {
	mg.Deps(Linux, Windows)
}

// Build for specific platforms with a given binary name.
func BuildFor(platform, binary string) error {
	_, err := sh.Exec(map[string]string{"GOOS": platform, "GOFLAGS": goFlags()},
		os.Stdout, os.Stderr, "go", "build", "-o", binary, ".")
	if err != nil {
		return err
	}
	return nil
}

// Build Linux
func LinuxBin() error {
	return BuildFor("linux", LINUX_BIN)
}

// Build Linux and archive/compress binary
func Linux() error {
	mg.Deps(LinuxBin)
	return sh.Run("tar", "-cJf", LINUX_ARCHIVE, LINUX_BIN, "desktop-assets", "install-linux.sh", "appicon.png", "LICENSE.txt")
}

// Build Windows
func WindowsBin() error {
	return BuildFor("windows", WINDOWS_BIN)
}

// Build Windows binary and zip it up
func Windows() error {
	mg.Deps(WindowsBin)
	file, err := os.Create(WINDOWS_ARCHIVE)
	if err != nil {
		return err
	}
	zipWriter := zip.NewWriter(file)
	f, err := zipWriter.Create(WINDOWS_BIN)
	if err != nil {
		return err
	}
	body, err := ioutil.ReadFile(WINDOWS_BIN)
	if err != nil {
		return err
	}
	_, err = f.Write(body)
	if err != nil {
		return err
	}
	err = zipWriter.Close()
	if err != nil {
		return err
	}
	return nil
}

// Build flatpak
func Flatpak() error {
	mg.Deps(FlatpakInit)
	return sh.Run("flatpak-builder", "--force-clean", FPBUILD, FPCONFIG)
}

// Get a shell within flatpak
func FlatpakShell() error {
	mg.Deps(FlatpakInit)
	return sh.Run("flatpak-builder", "--run", FPBUILD, FPCONFIG, "sh")
}

// Install flatpak
func FlatpakInstall() error {
	mg.Deps(FlatpakInit)
	return sh.Run("flatpak-builder", "--user", "--install", "--force-clean", FPBUILD, FPCONFIG)
}

// Run flatpak
func FlatpakRun() error {
	return sh.Run("flatpak", "run", FPNAME)
}

// Flatpak into repo
func FlatpakRepo() error {
	return sh.Run("flatpak-builder", "--force-clean", "--repo="+FPREPO, FPBUILD, FPCONFIG)
}

// Enable repos if this is your first time running flatpak
func FlatpakInit() error {
	err := sh.Run("flatpak", "remote-add", "--user", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo")
	if err != nil {
		return err
	}
	err = sh.Run("flatpak", "install", "--user", "flathub", "org.freedesktop.Sdk/x86_64/19.08")
	if err != nil {
		return err
	}
	return nil
}

// Clean up
func Clean() error {
	return sh.Run("rm", "-rf", WINDOWS_ARCHIVE, WINDOWS_BIN, LINUX_ARCHIVE, LINUX_BIN, FPBUILD)
}
-- 
2.25.1
Details
Message ID
<C7YZAPSPVQTW.2VXI3AKAI9HGV@vendetta>
In-Reply-To
<20201222011819.19456-1-jwhett@protonmail.com> (view parent)
DKIM signature
pass
Download raw message
Thanks! I applied some tweaks to the flatpak targets to make them work
for me. This is applied now.

Cheers,
Chris
Reply to thread Export thread (mbox)