Browse files

build: burn in git revision and timestamp

Burn the git revision into ./mypaint if building from a git repository. Add
a build timestamp too, for good measure.

Move the base MYPAINT_VERSION to main.py, and update release.sh

Show any git revision in the about box (if the base revision is a "+git").
  • Loading branch information...
1 parent 58ec474 commit 76bbb77e6f46cf542c48b1238e5003a62f245267 @achadwick achadwick committed Apr 10, 2013
Showing with 45 additions and 12 deletions.
  1. +22 −4 SConscript
  2. +4 −1 gui/application.py
  3. +1 −3 gui/drawwindow.py
  4. +10 −2 gui/main.py
  5. +7 −1 mypaint.py
  6. +1 −1 release.sh
View
26 SConscript
@@ -1,4 +1,5 @@
import os, sys
+import time
from os.path import join, basename
Import('env', 'install_perms', 'install_tree')
@@ -17,12 +18,29 @@ except OSError:
# Systems like Win32...
pass
-def burn_python_version(target, source, env):
- # make sure we run the python version that we built the extension modules for
+def burn_versions(target, source, env):
+ # Burn versions into the generated Python target.
+ # Make sure we run the python version that we built the extension
+ # modules for:
s = '#!/usr/bin/env ' + env['python_binary'] + '\n'
s += 5*'#\n'
s += '# DO NOT EDIT - edit %s instead\n' % source[0]
s += 5*'#\n'
+ # Also burn in the last git revision number
+ if os.path.isdir(".git"):
+ git_in, git_out = os.popen2("git rev-parse --short HEAD")
+ git_in.close()
+ git_rev = str(git_out.read()).strip()
+ git_out.close()
+ s += "_MYPAINT_BUILD_GIT_REVISION = %r\n" % (git_rev,)
+ else:
+ s += "_MYPAINT_BUILD_GIT_REVISION = ''\n"
+ # And a timestamp.
+ now_utc = time.gmtime()
+ timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", now_utc)
+ s += "_MYPAINT_BUILD_TIME_ISO = %r\n" % (timestamp,)
+ s += "_MYPAINT_BUILD_GMTIME_TUPLE = %r\n" % (tuple(now_utc),)
+ s += "\n\n"
s += open(str(source[0])).read()
f = open(str(target[0]), 'w')
f.write(s)
@@ -33,11 +51,11 @@ def burn_python_version(target, source, env):
# User-facing executable Python code
# MyPaint app
-env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
+env.Command('mypaint', 'mypaint.py', [burn_versions, Chmod('$TARGET', 0755)])
AlwaysBuild('mypaint') # especially if the "python_binary" option was changed
# Thumbnailer script
-env.Command('desktop/mypaint-ora-thumbnailer', 'desktop/mypaint-ora-thumbnailer.py', [burn_python_version, Chmod('$TARGET', 0755)])
+env.Command('desktop/mypaint-ora-thumbnailer', 'desktop/mypaint-ora-thumbnailer.py', [burn_versions, Chmod('$TARGET', 0755)])
AlwaysBuild('desktop/mypaint-ora-thumbnailer')
View
5 gui/application.py
@@ -61,7 +61,7 @@ class Application (object):
def __init__(self, filenames, app_datapath, app_extradatapath,
- user_datapath, user_confpath, fullscreen=False):
+ user_datapath, user_confpath, version, fullscreen=False):
"""Construct, but do not run.
:params filenames: The list of files to load.
@@ -82,6 +82,7 @@ def __init__(self, filenames, app_datapath, app_extradatapath,
This is where MyPaint will save user preferences data and the
keyboard accelerator map. Commonly $XDG_CONFIG_HOME/mypaint, i.e.
~/.config/mypaint
+ :param version: Version string for the about dialog.
:param fullscreen: Go fullscreen after starting.
"""
@@ -94,6 +95,8 @@ def __init__(self, filenames, app_datapath, app_extradatapath,
self.datapath = app_datapath
+ self.version = version #: version string for the app.
+
# create config directory, and subdirs where the user might drop files
for basedir in [self.user_confpath, self.user_datapath]:
if not os.path.isdir(basedir):
View
4 gui/drawwindow.py
@@ -13,8 +13,6 @@
Painting is done in tileddrawwidget.py.
"""
-MYPAINT_VERSION="1.1.0+git"
-
import os
import time
import webbrowser
@@ -793,7 +791,7 @@ def about_cb(self, action):
d = gtk.AboutDialog()
d.set_transient_for(self)
d.set_program_name("MyPaint")
- d.set_version(MYPAINT_VERSION)
+ d.set_version(self.app.version)
d.set_copyright(_("Copyright (C) 2005-2012\nMartin Renold and the MyPaint Development Team"))
d.set_website("http://mypaint.info/")
d.set_logo(self.app.pixmaps.mypaint_logo)
View
12 gui/main.py
@@ -28,7 +28,14 @@
import sys, time
-def main(datapath, extradata, oldstyle_confpath=None):
+#: Base version.
+#: If this string ends with +git, it will be expanded by the wrapper script to
+#: e.g. '1.1.0+gitSHORTCOMMITID' when built from inside a git repository.
+MYPAINT_VERSION='1.1.0+git'
+# ^ This is used by release.sh, so it must be a valid POSIX shell line too.
+
+
+def main(datapath, extradata, oldstyle_confpath=None, version=MYPAINT_VERSION):
"""Run MyPaint with `sys.argv`, called from the "mypaint" script.
:param datapath: The app's read-only data location.
@@ -46,6 +53,7 @@ def main(datapath, extradata, oldstyle_confpath=None):
for brushes and backgrounds. On Windows, these will be the same location.
On POSIX systems, $HOME/.config/mypaint and $HOME/.local/share/mypaint
are a typical division.
+ :param version: full version string for display in the about box.
The oldstyle_confpath parameter can also be overridden by command-line
parameters. To support legacy MyPaint configuration dirs, call with
@@ -103,7 +111,7 @@ def run():
app = application.Application(args,
app_datapath=datapath, app_extradatapath=extradata,
user_datapath=userdatapath, user_confpath=userconfpath,
- fullscreen=options.fullscreen)
+ version=version, fullscreen=options.fullscreen)
# Recent gtk versions don't allow changing those menu shortcuts by
# default. <rant>Sigh. This very useful feature used to be the
View
8 mypaint.py
@@ -195,4 +195,10 @@ def psyco_opt():
gettext.textdomain("mypaint")
from gui import main
- main.main(datapath, extradata, old_confpath)
+ version = main.MYPAINT_VERSION
+ if version.endswith("+git"):
+ try:
+ version += _MYPAINT_BUILD_GIT_REVISION
+ except NameError:
+ pass
+ main.main(datapath, extradata, old_confpath, version)
View
2 release.sh
@@ -7,7 +7,7 @@ if ! git diff --quiet; then
exit 1
fi
-eval $(grep MYPAINT_VERSION= gui/drawwindow.py)
+eval $(grep '^MYPAINT_VERSION=' gui/main.py)
version=$MYPAINT_VERSION
echo "Version $version"

0 comments on commit 76bbb77

Please sign in to comment.