Ticket #1424 (closed defect: fixed)

Opened 12 months ago

Last modified 4 weeks ago

[PATCH] Remove hardcoded paths for better Linux Packaging support

Reported by: vincent Owned by: leper
Priority: Nice to Have Milestone: Alpha 14
Component: Build & Packages Keywords: patch
Cc: Philip

Description

Currently, the script that calls pyrogenesis (build/resources/0ad.sh) hardcodes the path to the pyrogenesis binary (/usr/bin/pyrogenesis), which means that Linux distros which install game binaries to /usr/games (i.e. Debian & Ubuntu) end up having to patch the file. Instead of hardcoding the path, I propose the following patch, which looks for the first instance of pyrogenesis in the user's PATH and runs that. The patch below also modifies build/resources/0ad.desktop to use a relative path for the Exec= field rather than a hardcoded path.

--- a/build/resources/0ad.sh
+++ b/build/resources/0ad.sh
@@ -1,3 +1,9 @@
 #!/bin/sh
 
-/usr/bin/pyrogenesis "$@"
+path_to_pyrogenesis=$(which pyrogenesis)
+if [ -x "$path_to_pyrogenesis" ] ; then
+	"$path_to_pyrogenesis" "$@"
+else
+	echo "Error: pyrogenesis cannot be found in $PATH"
+	exit 1
+fi
--- a/build/resources/0ad.desktop
+++ b/build/resources/0ad.desktop
@@ -3,7 +3,7 @@
 Name=0 A.D.
 Comment=A real-time strategy game of ancient warfare
 Comment[it]=Videogioco strategico in tempo reale di guerre antiche
-Exec=/usr/bin/0ad
+Exec=0ad
 Icon=0ad
 Terminal=false
 Type=Application

Change History

comment:1 Changed 12 months ago by k776

  • Keywords patch review added

comment:2 Changed 12 months ago by vincent

  • Summary changed from Remove hardcoded paths for better Linux Packaging support to [PATCH] Remove hardcoded paths for better Linux Packaging support

comment:3 Changed 12 months ago by historic_bruno

  • Cc Philip added

Hmm, what if 0ad is not in the path though? I don't feel strongly one way or another, but it seems a possibility which hardcoding the path would eliminate. Also there may be confusion if multiple versions of the game are installed in different locations, then it's left to chance as to which will be found on the path.

Probably best to get opinions of those that actually work on packaging though :)

Last edited 12 months ago by historic_bruno (previous) (diff)

comment:4 Changed 12 months ago by vincent

I can't think of any distro where /usr/bin isn't in the user's path, so if 0ad isn't in $PATH, hardcoding 0ad.sh to look for "/usr/bin/pyrogenesis" would fail as well. Having multiple versions of the game installed in different locations is a valid concern, but it's not 'left to chance' which version of the game will be run; whichever path has the highest precedence on the user's system (often /usr/local/bin) will be used. IMO this is actually preferable to hardcoding the path, e.g. a user who chose to build 0ad from source for whatever reason and installed it to /usr/local probably wants to run his binary rather than the version distributed by his distro, installed into /usr/bin or /usr/games (assuming the user chooses to abide by the FHS and installs site-specific programs and data into /usr/local rather than replacing files in /usr). Incidentally, on Debian/Ubuntu? systems, /usr/games has the lowest precedence in $PATH, so users who just want to play 0ad can install it from the repositories and run it; users who prefer building from svn can stick their binary anywhere else in $PATH and run that, without having to modify 0ad.sh.

comment:5 Changed 4 weeks ago by leper

  • Owner set to leper
  • Status changed from new to closed
  • Resolution set to fixed

In 13365:

Remove hardcoding of path from desktop file and launcher script. Patch by vincent. Fixes #1424.

comment:6 Changed 4 weeks ago by leper

  • Keywords review removed
  • Component changed from Core engine to Build & Packages
  • Milestone changed from Backlog to Alpha 14

Thanks for the patch.

Applying this at least removes the need for patching this file for Debian/Ubunutu, FreeBSD, Slackware (the slackbuild one) and possibly others.

Note: See TracTickets for help on using tickets.