Skip to content

Commit

Permalink
Adhere to XDG (#458)
Browse files Browse the repository at this point in the history
* Adhere to XDG

* Make things simpler

* Simplify Makefile

* Simplify Makefile

* Better deb package

* Create /etc/ludo.toml in deb package

* Try this

* Fix bundle id

* Try this

* Move packaging files to pkg
  • Loading branch information
kivutar authored Aug 16, 2021
1 parent 89c1722 commit 9ab470f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 101 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jobs:
- run: sudo apt-get update -q
- run: sudo apt-get install libopenal-dev xorg-dev libgl1-mesa-dev -y --allow-unauthenticated
- run: OS=Linux ARCH=x86_64 VERSION=$VERSION make tar
- run: make deb_defaults
- run: go build
- run: OS=Linux ARCH=x86_64 VERSION=$VERSION make deb
- run: sha256sum Ludo-Linux-x86_64-${VERSION}.tar.gz > Ludo-Linux-x86_64-${VERSION}.tar.gz.sha256

Expand Down Expand Up @@ -55,8 +53,6 @@ jobs:
- run: export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/
- run: GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build -v
- run: OS=Linux ARCH=arm VERSION=$VERSION make tar
- run: make deb_defaults
- run: GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build -v
- run: OS=Linux ARCH=arm VERSION=$VERSION make deb
- run: sha256sum Ludo-Linux-arm-${VERSION}.tar.gz > Ludo-Linux-arm-${VERSION}.tar.gz.sha256

Expand Down Expand Up @@ -86,7 +82,7 @@ jobs:
- run: security import dev.p12 -k build.keychain -P ${{ secrets.OSXCERTPASS }} -T /usr/bin/codesign && rm dev.p12
- run: security set-key-partition-list -S "apple-tool:,apple:,codesign:" -s -k github build.keychain
- run: OS=OSX ARCH=x86_64 VERSION=$VERSION make dmg
- run: echo "REQUESTUUID=$(xcrun altool --notarize-app -t osx -f Ludo-OSX-x86_64-${VERSION}.dmg --primary-bundle-id org.libretro.ludo -u ${{ secrets.APPLEID }} -p ${{ secrets.APPLEIDPASS }} -itc_provider ZE9XE938Z2 | awk '/RequestUUID/ { print $NF; }')" >> $GITHUB_ENV
- run: echo "REQUESTUUID=$(xcrun altool --notarize-app -t osx -f Ludo-OSX-x86_64-${VERSION}.dmg --primary-bundle-id com.libretro.ludo -u ${{ secrets.APPLEID }} -p ${{ secrets.APPLEIDPASS }} -itc_provider ZE9XE938Z2 | awk '/RequestUUID/ { print $NF; }')" >> $GITHUB_ENV
- run: sleep 180
- run: xcrun altool --notarization-info $REQUESTUUID -u ${{ secrets.APPLEID }} -p ${{ secrets.APPLEIDPASS }} -ascprovider ZE9XE938Z2
- run: xcrun stapler staple Ludo-OSX-x86_64-${VERSION}.dmg
Expand Down
58 changes: 29 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ cores/%_libretro.dylib cores/%_libretro.dll cores/%_libretro.so:

$(APP).app: ludo $(DYLIBS)
mkdir -p $(APP).app/Contents/MacOS
mkdir -p $(APP).app/Contents/Frameworks
mkdir -p $(APP).app/Contents/Resources/$(APP).iconset
cp Info.plist $(APP).app/Contents/
cp pkg/Info.plist $(APP).app/Contents/
sed -i.bak 's/0.1.0/$(VERSION)/' $(APP).app/Contents/Info.plist
rm $(APP).app/Contents/Info.plist.bak
echo "APPL????" > $(APP).app/Contents/PkgInfo
cp -r database $(APP).app/Contents/Resources
cp -r assets $(APP).app/Contents/Resources
cp cores/* $(APP).app/Contents/Frameworks
cp -r cores $(APP).app/Contents/Resources
codesign --force --options runtime --verbose --timestamp --sign "7069CC8A4AE9AFF0493CC539BBA4FA345F0A668B" \
--entitlements entitlements.xml $(APP).app/Contents/Frameworks/*.dylib
--entitlements pkg/entitlements.xml $(APP).app/Contents/Resources/cores/*.dylib
rm -rf $(APP).app/Contents/Resources/database/.git
rm -rf $(APP).app/Contents/Resources/assets/.git
sips -z 16 16 assets/icon.png --out $(APP).app/Contents/Resources/$(APP).iconset/icon_16x16.png
Expand All @@ -76,11 +75,11 @@ $(APP).app: ludo $(DYLIBS)
sips -z 512 512 assets/icon.png --out $(APP).app/Contents/Resources/$(APP).iconset/icon_512x512.png
cp ludo $(APP).app/Contents/MacOS
codesign --force --options runtime --verbose --timestamp --sign "7069CC8A4AE9AFF0493CC539BBA4FA345F0A668B" \
--entitlements entitlements.xml $(APP).app/Contents/MacOS/ludo
--entitlements pkg/entitlements.xml $(APP).app/Contents/MacOS/ludo
iconutil -c icns -o $(APP).app/Contents/Resources/$(APP).icns $(APP).app/Contents/Resources/$(APP).iconset
rm -rf $(APP).app/Contents/Resources/$(APP).iconset
codesign --force --options runtime --verbose --timestamp --sign "7069CC8A4AE9AFF0493CC539BBA4FA345F0A668B" \
--entitlements entitlements.xml $(APP).app
--entitlements pkg/entitlements.xml $(APP).app

empty.dmg:
mkdir -p template
Expand All @@ -98,7 +97,7 @@ dmg: empty.dmg $(APP).app
rm -f $(BUNDLENAME)-*.dmg
hdiutil convert empty.dmg -quiet -format UDZO -imagekey zlib-level=9 -o $(BUNDLENAME).dmg
codesign --force --options runtime --verbose --timestamp --sign "7069CC8A4AE9AFF0493CC539BBA4FA345F0A668B" \
--entitlements entitlements.xml $(BUNDLENAME).dmg
--entitlements pkg/entitlements.xml $(BUNDLENAME).dmg

# For Windows
zip: ludo.exe $(DLLS)
Expand All @@ -125,30 +124,31 @@ DEB_ARCH = amd64
ifeq ($(ARCH), arm)
DEB_ARCH = armhf
endif

deb_defaults:
sed -i.bak 's/"\.\/assets"/"\/usr\/local\/share\/ludo\/assets"/' settings/defaults.go
sed -i.bak 's/"\.\/database"/"\/usr\/local\/share\/ludo\/database"/' settings/defaults.go
sed -i.bak 's/"\.\/cores"/"\/usr\/local\/lib\/ludo\/cores"/' settings/defaults.go
DEB_ROOT = ludo_$(VERSION)-1_$(DEB_ARCH)

deb: ludo $(SOBJS)
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/DEBIAN
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/bin
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/share/ludo
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/lib/ludo
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/share/applications
mkdir -p ludo_$(VERSION)-1_$(DEB_ARCH)/usr/share/icons/hicolor/1024x1024/apps/
cp ludo ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/bin
cp -r database ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/share/ludo
cp -r assets ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/share/ludo
cp -r cores ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/lib/ludo
cp assets/icon.png ludo_$(VERSION)-1_$(DEB_ARCH)/usr/share/icons/hicolor/1024x1024/apps/ludo.png
cp ludo.desktop ludo_$(VERSION)-1_$(DEB_ARCH)/usr/local/share/applications
cp control ludo_$(VERSION)-1_$(DEB_ARCH)/DEBIAN
sed -i.bak 's/VERSION/$(VERSION)/' ludo_$(VERSION)-1_$(DEB_ARCH)/DEBIAN/control
sed -i.bak 's/ARCH/$(DEB_ARCH)/' ludo_$(VERSION)-1_$(DEB_ARCH)/DEBIAN/control
rm ludo_$(VERSION)-1_$(DEB_ARCH)/DEBIAN/control.bak
dpkg-deb --build ludo_$(VERSION)-1_$(DEB_ARCH)
mkdir -p $(DEB_ROOT)/DEBIAN
mkdir -p $(DEB_ROOT)/etc
mkdir -p $(DEB_ROOT)/usr/bin
mkdir -p $(DEB_ROOT)/usr/lib/ludo
mkdir -p $(DEB_ROOT)/usr/share/ludo
mkdir -p $(DEB_ROOT)/usr/share/applications
mkdir -p $(DEB_ROOT)/usr/share/icons/hicolor/1024x1024/apps/
touch $(DEB_ROOT)/etc/ludo.toml
echo "cores_dir = \"/usr/lib/ludo\"" >> $(DEB_ROOT)/etc/ludo.toml
echo "assets_dir = \"/usr/share/ludo/assets\"" >> $(DEB_ROOT)/etc/ludo.toml
echo "database_dir = \"/usr/share/ludo/databbase\"" >> $(DEB_ROOT)/etc/ludo.toml
cp ludo $(DEB_ROOT)/usr/bin
cp cores/* $(DEB_ROOT)/usr/lib/ludo
cp -r assets $(DEB_ROOT)/usr/share/ludo
cp -r database $(DEB_ROOT)/usr/share/ludo
cp assets/icon.png $(DEB_ROOT)/usr/share/icons/hicolor/1024x1024/apps/ludo.png
cp pkg/ludo.desktop $(DEB_ROOT)/usr/share/applications
cp pkg/control $(DEB_ROOT)/DEBIAN
sed -i.bak 's/VERSION/$(VERSION)/' $(DEB_ROOT)/DEBIAN/control
sed -i.bak 's/ARCH/$(DEB_ARCH)/' $(DEB_ROOT)/DEBIAN/control
rm $(DEB_ROOT)/DEBIAN/control.bak
dpkg-deb --build $(DEB_ROOT)

clean:
rm -rf Ludo.app ludo wc *.dmg *.deb $(BUNDLENAME)-* cores/
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/libretro/ludo

require (
github.com/adrg/xdg v0.3.3 // indirect
github.com/cavaliercoder/grab v2.0.0+incompatible
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/disintegration/imaging v1.6.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/adrg/xdg v0.3.3 h1:s/tV7MdqQnzB1nKY8aqHvAMD+uCiuEDzVB5HLRY849U=
github.com/adrg/xdg v0.3.3/go.mod h1:61xAR2VZcggl2St4O9ohF5qCKe08+JDmE4VNzPFQvOQ=
github.com/cavaliercoder/grab v2.0.0+incompatible h1:wZHbBQx56+Yxjx2TCGDcenhh3cJn7cCLMfkEPmySTSE=
github.com/cavaliercoder/grab v2.0.0+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
16 changes: 4 additions & 12 deletions history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"log"
"os"
"path/filepath"

"github.com/adrg/xdg"
)

// Game represents a game in the history file
Expand Down Expand Up @@ -48,12 +50,7 @@ func Push(g Game) {

// Load loads history.csv in memory
func Load() error {
home, err := os.UserHomeDir()
if err != nil {
return err
}

file, err := os.Open(filepath.Join(home, ".ludo", "history.csv"))
file, err := os.Open(filepath.Join(xdg.DataHome, "ludo", "history.csv"))
if err != nil {
return err
}
Expand Down Expand Up @@ -83,12 +80,7 @@ func Load() error {

// Save persists the history as a csv file
func Save() error {
home, err := os.UserHomeDir()
if err != nil {
return err
}

file, err := os.Create(filepath.Join(home, ".ludo", "history.csv"))
file, err := os.Create(filepath.Join(xdg.DataHome, "ludo", "history.csv"))
if err != nil {
return err
}
Expand Down
15 changes: 3 additions & 12 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"

"github.com/adrg/xdg"
"github.com/libretro/ludo/state"
"github.com/libretro/ludo/utils"
"github.com/pelletier/go-toml"
Expand Down Expand Up @@ -69,11 +70,6 @@ func (o *Options) Save() error {
o.Lock()
defer o.Unlock()

home, err := os.UserHomeDir()
if err != nil {
return err
}

m := make(map[string]string)
for _, v := range o.Vars {
m[strings.Replace(v.Key, ".", "___", 1)] = v.Choices[v.Choice]
Expand All @@ -84,7 +80,7 @@ func (o *Options) Save() error {
}

name := utils.FileName(state.CorePath)
fd, err := os.Create(filepath.Join(home, ".ludo", name+".toml"))
fd, err := os.Create(filepath.Join(xdg.ConfigHome, "ludo", name+".toml"))
if err != nil {
return err
}
Expand All @@ -103,13 +99,8 @@ func (o *Options) load() error {
o.Lock()
defer o.Unlock()

home, err := os.UserHomeDir()
if err != nil {
return err
}

name := utils.FileName(state.CorePath)
b, err := ioutil.ReadFile(filepath.Join(home, ".ludo", name+".toml"))
b, err := ioutil.ReadFile(filepath.Join(xdg.ConfigHome, "ludo", name+".toml"))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion Info.plist → pkg/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleVersion</key>
<string>0.1.0</string>
<key>CFBundleIdentifier</key>
<string>org.libretro.ludo</string>
<string>com.libretro.ludo</string>
<key>CFBundleDisplayName</key>
<string>Ludo</string>
<key>CFBundleName</key>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 9 additions & 29 deletions settings/defaults.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
package settings

import (
"log"
"os"
"path/filepath"
"runtime"
)

func coresDir() string {
coresDir := "./cores"
// with hardened runtime enabled, dylibs can't be loaded from a relative path
if runtime.GOOS == "darwin" {
exe, err := os.Executable()
if err != nil {
log.Fatalln(err)
}
exeDir := filepath.Dir(exe)
coresDir = filepath.Join(exeDir, "..", "Frameworks")
}
return coresDir
}
"github.com/adrg/xdg"
)

func defaultSettings() Settings {
home, err := os.UserHomeDir()
if err != nil {
log.Fatalln(err)
}

return Settings{
VideoFullscreen: false,
VideoMonitorIndex: 0,
Expand Down Expand Up @@ -78,14 +58,14 @@ func defaultSettings() Settings {
"SNK - Neo Geo Pocket": "mednafen_ngp_libretro",
"Sony - PlayStation": playstationCore,
},
CoresDirectory: coresDir(),
CoresDirectory: "./cores",
AssetsDirectory: "./assets",
DatabaseDirectory: "./database",
SavestatesDirectory: filepath.Join(home, ".ludo", "savestates"),
SavefilesDirectory: filepath.Join(home, ".ludo", "savefiles"),
ScreenshotsDirectory: filepath.Join(home, ".ludo", "screenshots"),
SystemDirectory: filepath.Join(home, ".ludo", "system"),
PlaylistsDirectory: filepath.Join(home, ".ludo", "playlists"),
ThumbnailsDirectory: filepath.Join(home, ".ludo", "thumbnails"),
SavestatesDirectory: filepath.Join(xdg.DataHome, "ludo", "savestates"),
SavefilesDirectory: filepath.Join(xdg.DataHome, "ludo", "savefiles"),
ScreenshotsDirectory: filepath.Join(xdg.DataHome, "ludo", "screenshots"),
SystemDirectory: filepath.Join(xdg.DataHome, "ludo", "system"),
PlaylistsDirectory: filepath.Join(xdg.DataHome, "ludo", "playlists"),
ThumbnailsDirectory: filepath.Join(xdg.DataHome, "ludo", "thumbnails"),
}
}
17 changes: 4 additions & 13 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"

"github.com/adrg/xdg"
"github.com/fatih/structs"
"github.com/libretro/ludo/ludos"
"github.com/libretro/ludo/utils"
Expand Down Expand Up @@ -67,11 +68,6 @@ func Load() error {
}
}()

home, err := os.UserHomeDir()
if err != nil {
return err
}

// Set default values for settings
Current = Defaults

Expand All @@ -84,7 +80,7 @@ func Load() error {
}
}

b, err := ioutil.ReadFile(filepath.Join(home, ".ludo", "settings.toml"))
b, err := ioutil.ReadFile(filepath.Join(xdg.ConfigHome, "ludo", "settings.toml"))
if err != nil {
return err
}
Expand All @@ -102,12 +98,7 @@ func Load() error {

// Save saves the current configuration to the home directory
func Save() error {
home, err := os.UserHomeDir()
if err != nil {
return err
}

err = os.MkdirAll(filepath.Join(home, ".ludo"), os.ModePerm)
err := os.MkdirAll(filepath.Join(xdg.ConfigHome, "ludo"), os.ModePerm)
if err != nil {
return err
}
Expand All @@ -117,7 +108,7 @@ func Save() error {
return err
}

fd, err := os.Create(filepath.Join(home, ".ludo", "settings.toml"))
fd, err := os.Create(filepath.Join(xdg.ConfigHome, "ludo", "settings.toml"))
if err != nil {
return err
}
Expand Down

0 comments on commit 9ab470f

Please sign in to comment.