summaryrefslogtreecommitdiff
path: root/attoconf/lib/config_hash.py
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-08-06 16:29:24 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-08-06 16:31:11 -0700
commit93215a82b4ebda6d322f75023cfea4cc7d4904d2 (patch)
treee8157186ca7026807fb602921b96b793a16314a0 /attoconf/lib/config_hash.py
parent7b5f69de3f7b52b718507fe16c2560901e48a70c (diff)
downloadattobuild-93215a82b4ebda6d322f75023cfea4cc7d4904d2.tar.gz
attobuild-93215a82b4ebda6d322f75023cfea4cc7d4904d2.tar.bz2
attobuild-93215a82b4ebda6d322f75023cfea4cc7d4904d2.tar.xz
attobuild-93215a82b4ebda6d322f75023cfea4cc7d4904d2.zip
Add config hash
Diffstat (limited to 'attoconf/lib/config_hash.py')
-rw-r--r--attoconf/lib/config_hash.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/attoconf/lib/config_hash.py b/attoconf/lib/config_hash.py
new file mode 100644
index 0000000..5641558
--- /dev/null
+++ b/attoconf/lib/config_hash.py
@@ -0,0 +1,48 @@
+# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+#
+# This file is part of attoconf.
+#
+# attoconf 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 3 of the License, or
+# (at your option) any later version.
+#
+# attoconf 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 attoconf. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import print_function, division, absolute_import
+
+from hashlib import md5
+import os
+
+from ..classy import ClassyProject
+
+
+def calc_hash(build):
+ hash = md5()
+ for var, (val, origin), in sorted(build.vars.iteritems()):
+ # origin is not included in the hash
+ hash.update('%s = %s\n' % (var, val))
+ return hash.hexdigest()
+
+
+def add_config_hash(build):
+ print('Generating a hash of config options ...')
+ build.vars['CONFIG_HASH'] = (calc_hash(build), 'special')
+
+
+class ConfigHash(ClassyProject):
+ ''' Post hook add the build hash.
+
+ This should be run before any other post hooks.
+ '''
+ __slots__ = ()
+
+ def post(self):
+ self.checks.append(add_config_hash)
+ super(ConfigHash, self).post()