summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-01-28 14:58:17 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-01-28 14:58:17 +0000
commit2024583a303ef1a79709b7ecc9fc2dce22e8ce98 (patch)
treea33b00874aaf7ccdf450b320d7fa1c51d8add1c1
parente48bbe396cccb4f4be2e7170547cab1de3d6c623 (diff)
parent132951b02d1e4e628cfbafab2d35bcda9c1fc24e (diff)
downloadmorph-2024583a303ef1a79709b7ecc9fc2dce22e8ce98.tar.gz
Merge remote-tracking branch 'origin/baserock/richardmaw/morph-version'
-rw-r--r--morphlib/__init__.py5
-rw-r--r--morphlib/builder2.py7
-rw-r--r--morphlib/gitversion.py57
-rw-r--r--setup.py53
-rwxr-xr-xtests.as-root/metadata-includes-morph-version.script52
-rwxr-xr-xtests.as-root/metadata-includes-morph-version.setup48
-rw-r--r--without-test-modules1
7 files changed, 216 insertions, 7 deletions
diff --git a/morphlib/__init__.py b/morphlib/__init__.py
index 213241d8..2d2f68a2 100644
--- a/morphlib/__init__.py
+++ b/morphlib/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2012 Codethink Limited
+# Copyright (C) 2011-2013 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,8 +19,9 @@
import cliapp
+import gitversion
-__version__ = '0.1'
+__version__ = gitversion.version
class Error(cliapp.AppException):
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index a60c4a47..ac40bf22 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -33,6 +33,7 @@ import cliapp
import morphlib
from morphlib.artifactcachereference import ArtifactCacheReference
+import morphlib.gitversion
def ldconfig(runcmd, rootdir): # pragma: no cover
@@ -204,6 +205,12 @@ class BuilderBase(object):
'morphology': self.artifact.source.filename,
'cache-key': self.artifact.cache_key,
'cache-id': self.artifact.cache_id,
+ 'morph-version': {
+ 'ref': morphlib.gitversion.ref,
+ 'tree': morphlib.gitversion.tree,
+ 'commit': morphlib.gitversion.commit,
+ 'version': morphlib.gitversion.version,
+ },
}
return meta
diff --git a/morphlib/gitversion.py b/morphlib/gitversion.py
new file mode 100644
index 00000000..b1f82da6
--- /dev/null
+++ b/morphlib/gitversion.py
@@ -0,0 +1,57 @@
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+'''Version information retrieved either from the package data, or the
+ git repository the library is being run from.
+
+ It is an error to run morph without this version information, since
+ it makes it impossible to reproduce any Systems that are built.
+'''
+
+
+import subprocess
+import os
+
+import cliapp
+
+
+try:
+ import pkgutil
+ version = pkgutil.get_data('morphlib', 'version')
+ commit = pkgutil.get_data('morphlib', 'commit')
+ tree = pkgutil.get_data('morphlib', 'tree')
+ ref = pkgutil.get_data('morphlib', 'ref')
+except IOError, e:
+ from os.path import dirname
+ def run_git(*args):
+ command = ['git'] + list(args)
+ p = subprocess.Popen(command,
+ cwd=os.path.dirname(__file__),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ o = p.communicate()
+ if p.returncode:
+ raise subprocess.CalledProcessError(p.returncode,
+ command)
+ return o[0].strip()
+
+ try:
+ version = run_git('describe', '--always', '--dirty=-unreproducible')
+ commit = run_git('rev-parse', 'HEAD^{commit}')
+ tree = run_git('rev-parse', 'HEAD^{tree}')
+ ref = run_git('rev-parse', '--symbolic-full-name', 'HEAD')
+ except cliapp.AppException:
+ raise cliapp.AppException("morphlib version could not be determined")
diff --git a/setup.py b/setup.py
index eceb705b..6e8c4c4b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011, 2012 Codethink Limited
+# Copyright (C) 2011, 2012, 2013 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,23 +23,58 @@ from distutils.command.build import build
from distutils.command.clean import clean
import glob
import os
+import os.path
import shutil
import subprocess
+import cliapp
+
import morphlib
-class GenerateManpage(build):
+class GenerateResources(build):
def run(self):
+ if not self.dry_run:
+ self.generate_manpages()
+ self.generate_version()
build.run(self)
- print 'building manpages'
+
+ def generate_manpages(self):
+ self.announce('building manpages')
for x in ['morph']:
with open('%s.1' % x, 'w') as f:
subprocess.check_call(['python', x,
'--generate-manpage=%s.1.in' % x,
'--output=%s.1' % x], stdout=f)
+ def generate_version(self):
+ target_dir = os.path.join(self.build_lib, 'morphlib')
+
+ self.mkpath(target_dir)
+
+ def save_git_info(filename, *args):
+ path = os.path.join(target_dir, filename)
+ command = ['git'] + list(args)
+
+ self.announce('generating %s with %s' %
+ (path, ' '.join(command)))
+
+ with open(os.path.join(target_dir, filename), 'w') as f:
+ p = subprocess.Popen(command,
+ cwd=os.path.dirname(__file__),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ o = p.communicate()
+ if p.returncode:
+ raise subprocess.CalledProcessError(p.returncode, command)
+ f.write(o[0].strip())
+
+ save_git_info('version', 'describe', '--always',
+ '--dirty=-unreproducible')
+ save_git_info('commit', 'rev-parse', 'HEAD^{commit}')
+ save_git_info('tree', 'rev-parse', 'HEAD^{tree}')
+ save_git_info('ref', 'rev-parse', '--symbolic-full-name', 'HEAD')
class Clean(clean):
@@ -104,10 +139,18 @@ FIXME
url='http://www.baserock.org/',
scripts=['morph'],
packages=['morphlib'],
- package_data={'morphlib': ['plugins/*_plugin.py']},
+ package_data={
+ 'morphlib': [
+ 'plugins/*_plugin.py',
+ 'version',
+ 'commit',
+ 'tree',
+ 'ref',
+ ]
+ },
data_files=[('share/man/man1', glob.glob('*.[1-8]'))],
cmdclass={
- 'build': GenerateManpage,
+ 'build': GenerateResources,
'check': Check,
'clean': Clean,
})
diff --git a/tests.as-root/metadata-includes-morph-version.script b/tests.as-root/metadata-includes-morph-version.script
new file mode 100755
index 00000000..f83712a7
--- /dev/null
+++ b/tests.as-root/metadata-includes-morph-version.script
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+# All the metadata files in /baserock of a system contain morph's version
+# information
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+. "$SRCDIR/scripts/python-check"
+
+. "$SRCDIR/scripts/fix-committer-info"
+
+# get git version info
+cd "$SRCDIR"
+description="$(git describe --always --dirty=-unreproducible)"
+commit="$(git rev-parse 'HEAD^{commit}')"
+tree="$(git rev-parse 'HEAD^{tree}')"
+ref="$(git rev-parse --symbolic-full-name 'HEAD')"
+
+tar=$("$SRCDIR/scripts/test-morph" --find-system-artifact \
+ build-morphology test:morphs tarball hello-tarball)
+
+extracted="$DATADIR/extracted"
+mkdir -p "$extracted"
+tar -xf "$tar" -C "$extracted"
+cd "$extracted/baserock"
+for f in *.meta; do
+ # Check for git describe output
+ grep -q -F -e "$description" "$f"
+ # Check the Sha-1 commit is included
+ grep -q -F -e "$commit" "$f"
+ # Check the Sha-1 of the commit's tree is included
+ grep -q -F -e "$tree" "$f"
+ # Check the ref (e.g. branch) is included
+ grep -q -F -e "$ref" "$f"
+done
diff --git a/tests.as-root/metadata-includes-morph-version.setup b/tests.as-root/metadata-includes-morph-version.setup
new file mode 100755
index 00000000..2284cfb9
--- /dev/null
+++ b/tests.as-root/metadata-includes-morph-version.setup
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+set -eu
+
+source "$SRCDIR/scripts/fix-committer-info"
+
+morphsrepo="$DATADIR/morphs"
+cd "$morphsrepo"
+git checkout -b tarball
+cat <<EOF > hello-tarball.morph
+{
+ "name": "hello-tarball",
+ "kind": "system",
+ "system-kind": "rootfs-tarball",
+ "arch": "$(uname -m)",
+ "strata": [
+ {
+ "morph": "hello-stratum",
+ "repo": "test:morphs",
+ "ref": "master"
+ },
+ {
+ "morph": "linux-stratum",
+ "repo": "test:morphs",
+ "ref": "master"
+ }
+ ]
+}
+EOF
+git add hello-tarball.morph
+
+git commit --quiet -m "add tarball system"
diff --git a/without-test-modules b/without-test-modules
index f1ea523d..cb0302c8 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -16,5 +16,6 @@ morphlib/plugins/trebuchet_plugin.py
morphlib/plugins/branch_and_merge_plugin.py
morphlib/buildcommand.py
morphlib/plugins/build_plugin.py
+morphlib/gitversion.py
morphlib/plugins/expand_repo_plugin.py