summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-20 13:59:07 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-20 13:59:07 +0100
commit7aaf59faf8bb0ff85a2f76f6569076790a124813 (patch)
treef35c23fe5cbe709ffeea4584c9420795ef89ca5b
parentd92919284b25526581f5a3f461f1e06106b91a09 (diff)
Give access to git revision, and make test mode accessible.
-rw-r--r--.gitignore1
-rw-r--r--src/git_commit.h6
-rw-r--r--src/test_mode.cc40
-rw-r--r--src/test_mode.h29
-rw-r--r--src/wscript2
-rw-r--r--wscript21
6 files changed, 99 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index dcffabcc..f9e62ff5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ build
.lock*
doc/html
doc/latex
+src/git_commit.cc
diff --git a/src/git_commit.h b/src/git_commit.h
new file mode 100644
index 00000000..377fefbb
--- /dev/null
+++ b/src/git_commit.h
@@ -0,0 +1,6 @@
+
+namespace libdcp {
+
+extern char const * git_commit;
+
+}
diff --git a/src/test_mode.cc b/src/test_mode.cc
new file mode 100644
index 00000000..2ff806fa
--- /dev/null
+++ b/src/test_mode.cc
@@ -0,0 +1,40 @@
+/*
+ Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file src/test_mode.cc
+ * @brief A method to enable test mode for libdcp.
+ */
+
+#include "KM_prng.h"
+#include "test_mode.h"
+#include "metadata.h"
+
+/** Calling this will seed the random number generator used to
+ * generate UUIDs with a known value, and set the DCP issue
+ * date to 1st January 2012 at midnight. This means that
+ * two runs of libdcp with the same inputs will produce
+ * the same output.
+ */
+
+void
+libdcp::enable_test_mode ()
+{
+ Kumu::libdcp_test = true;
+ Metadata::instance()->issue_date = "2012-01-01T00:00:00+00:00";
+}
diff --git a/src/test_mode.h b/src/test_mode.h
new file mode 100644
index 00000000..b2e671d5
--- /dev/null
+++ b/src/test_mode.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file src/test_mode.h
+ * @brief A method to enable test mode for libdcp.
+ */
+
+namespace libdcp
+{
+
+extern void enable_test_mode ();
+
+}
diff --git a/src/wscript b/src/wscript
index a57bb75b..b0e7f8be 100644
--- a/src/wscript
+++ b/src/wscript
@@ -12,6 +12,8 @@ def build(bld):
picture_asset.cc
util.cc
metadata.cc
+ git_commit.cc
+ test_mode.cc
"""
headers = """
diff --git a/wscript b/wscript
index c1538ceb..b70a8e2d 100644
--- a/wscript
+++ b/wscript
@@ -1,3 +1,5 @@
+import subprocess
+
APPNAME = 'libdcp'
VERSION = '0.03pre'
@@ -25,6 +27,8 @@ def configure(conf):
conf.recurse('asdcplib')
def build(bld):
+ create_stored_commit()
+
bld(source = 'libdcp.pc.in',
version = VERSION,
includedir = '%s/include' % bld.env.PREFIX,
@@ -37,3 +41,20 @@ def build(bld):
def dist(ctx):
ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~'
+
+def create_stored_commit():
+ cmd = "LANG= git log --abbrev HEAD^..HEAD ."
+ output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
+ o = output[0].decode('utf-8')
+ commit = o.replace ("commit ", "")[0:10]
+
+ try:
+ text = '#include "git_commit.h"\n'
+ text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
+ print('Writing git commit info to src/git_commit.cc')
+ o = open('src/git_commit.cc', 'w')
+ o.write(text)
+ o.close()
+ except IOError:
+ print('Could not open src/git_commit.cc for writing\n')
+ sys.exit(-1)