Creating a PR with patch to update a FreeBSD port

From TykWiki
Jump to navigationJump to search

This article is about submitting an updated port to the FreeBSD project. It is not about updating an installed port on a system to a newer version. It is about getting an updated version of something into the FreeBSD ports tree.

Background

The FreeBSD ports tree is huge, and as such, there is a lot of updating to do to keep everything fresh. What I used to do when I found something that was outdated was:

  • Wait for someone else to update the port
  • Send an email to ports@ or the maintainer and ask if someone can update the port

Turns out both of the above options are pretty silly when it is as simple as it is to update many ports. Why waste someone elses time when it takes me just as long to submit a PR with a patch to update the port ?

Preparation

To ease the process of creating a PR to update a port, there is a port called ports-mgmt/porttools which I install:

portmaster /usr/ports/ports-mgmt/porttools/

I then edit /home/tykling/.porttools and set name and email in that file:

[tykling@tyklappy ~]$ egrep "(EMAIL|FULLNAME)" .porttools 
EMAIL="thomas@gibfest.dk"
FULLNAME="Thomas Steen Rasmussen"

This will make sure the values are pre-filled in the PR submit screen.

Updating a port

This example is for updating /usr/ports/games/openttd from 1.0.3 to 1.0.4.

First thing I do is to make a backup copy of the port dir before making any changes, so I have something to compare with when I am done making changes.

[tykling@tyklappy /usr/ports/games]$ sudo cp -rv openttd/ openttd.orig
openttd/ -> openttd.orig
openttd/files -> openttd.orig/files
openttd/files/pkg-message.in -> openttd.orig/files/pkg-message.in
openttd/Makefile -> openttd.orig/Makefile
openttd/pkg-plist -> openttd.orig/pkg-plist
openttd/distinfo -> openttd.orig/distinfo
openttd/pkg-descr -> openttd.orig/pkg-descr

I make all changes in /usr/ports/games/openttd and keep /usr/ports/games/openttd.orig for later comparison.

Then I go to work on /usr/ports/games/openttd. First thing to do is to change the version number in /usr/ports/games/openttd/Makefile:

[tykling@tyklappy /usr/ports/games/openttd]$ sudo sed -i "" "s/1.0.3/1.0.4/" Makefile

Then I run port fetch which downloads the distfile and updates /usr/ports/games/openttd/distinfo with the new filesize and checksums:

[tykling@tyklappy /usr/ports/games/openttd]$ sudo port fetch
Define WITH_MIDI_PLAYER=/path/to/player to build with external MIDI player
Define WITH_MIDI_PLAYER_ARGS=arguments for external MIDI player
Define WITH_DEDICATED_SERVER_ONLY to build CLI-based dedicated server
===>  License check disabled, port has not defined LICENSE
=> openttd-1.0.4-source.tar.bz2 doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from http://gb.binaries.openttd.org/binaries/releases/1.0.4/.
openttd-1.0.4-source.tar.bz2                  100% of 5551 kB  848 kBps
Define WITH_MIDI_PLAYER=/path/to/player to build with external MIDI player
Define WITH_MIDI_PLAYER_ARGS=arguments for external MIDI player
Define WITH_DEDICATED_SERVER_ONLY to build CLI-based dedicated server
===>  License check disabled, port has not defined LICENSE
[tykling@tyklappy /usr/ports/games/openttd]$ 

The Makefile and distfile are now both updated to reflect the new version. For simple upgrades, the work is done. This is the difference between the old port and the new port:

[tykling@tyklappy ~]$ diff -u /usr/ports/games/openttd.orig/ /usr/ports/games/openttd/
diff -u /usr/ports/games/openttd.orig/Makefile /usr/ports/games/openttd/Makefile
--- /usr/ports/games/openttd.orig/Makefile      2010-09-30 00:50:23.536888236 +0200
+++ /usr/ports/games/openttd/Makefile   2010-09-30 00:52:06.553391172 +0200
@@ -6,7 +6,7 @@
 #
 
 PORTNAME=      openttd
-PORTVERSION=   1.0.3
+PORTVERSION=   1.0.4
 CATEGORIES=    games
 MASTER_SITES=  http://gb.binaries.openttd.org/binaries/releases/${PORTVERSION}/ \
                #SF/${PORTNAME}/${PORTNAME}/${PORTNAME}-${PORTVERSION}
diff -u /usr/ports/games/openttd.orig/distinfo /usr/ports/games/openttd/distinfo
--- /usr/ports/games/openttd.orig/distinfo      2010-09-30 00:50:23.537887246 +0200
+++ /usr/ports/games/openttd/distinfo   2010-09-30 00:55:43.648371399 +0200
@@ -1,3 +1,3 @@
-MD5 (openttd-1.0.3-source.tar.bz2) = cff60c624913a491ed3c91474e845722
-SHA256 (openttd-1.0.3-source.tar.bz2) = f52f2381c678de024d26ee465c8203323eb3484300c4dc182c0d68c439ee8c57
-SIZE (openttd-1.0.3-source.tar.bz2) = 5395672
+MD5 (openttd-1.0.4-source.tar.bz2) = e11e81bee589c04abd3cc4f3fafcb2b1
+SHA256 (openttd-1.0.4-source.tar.bz2) = 2c6b1c314f6d5e2d72543cad78769d47837d59b69c98c4356d0076498db6426c
+SIZE (openttd-1.0.4-source.tar.bz2) = 5684460