summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-09-25 23:39:37 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-09-25 23:39:37 -0700
commit20f0c059b4ceef520a0bd8580960a9d2f4fceb88 (patch)
tree08ff98ffa47201ae520ac14ee86b2e7515dd7c9b
parent4d202efe504c98fa8eab8d122f40214270f63ad2 (diff)
downloadattobuild-20f0c059b4ceef520a0bd8580960a9d2f4fceb88.tar.gz
attobuild-20f0c059b4ceef520a0bd8580960a9d2f4fceb88.tar.bz2
attobuild-20f0c059b4ceef520a0bd8580960a9d2f4fceb88.tar.xz
attobuild-20f0c059b4ceef520a0bd8580960a9d2f4fceb88.zip
Add a more flexible converter from Makefile.in to Makefile
-rw-r--r--attoconf/_version.py2
-rw-r--r--attoconf/lib/make.py3
-rw-r--r--attoconf/lib/templates.py80
3 files changed, 84 insertions, 1 deletions
diff --git a/attoconf/_version.py b/attoconf/_version.py
index 6aaa0c1..943af03 100644
--- a/attoconf/_version.py
+++ b/attoconf/_version.py
@@ -7,7 +7,7 @@ major = 0
# Incremented for releases with compatible API additions.
# This is the number that is usually incremented.
-minor = 7
+minor = 8
# Incremented if there is a bugfix release.
# Might not be contiguous.
diff --git a/attoconf/lib/make.py b/attoconf/lib/make.py
index c63cb61..ee58619 100644
--- a/attoconf/lib/make.py
+++ b/attoconf/lib/make.py
@@ -18,6 +18,7 @@
from __future__ import print_function, division, absolute_import
import os
+import sys
from ..classy import ClassyProject
from ..version import full_version
@@ -82,5 +83,7 @@ class Make(ClassyProject):
def post(self):
super(Make, self).post()
+ if 'SRC_DIR' in self.order:
+ sys.exit('ERROR: Incompatible generator hooks!')
self.order.insert(0, 'SRC_DIR')
self.checks.append(MakeHook(self.make_in, self.make_out))
diff --git a/attoconf/lib/templates.py b/attoconf/lib/templates.py
new file mode 100644
index 0000000..791dd62
--- /dev/null
+++ b/attoconf/lib/templates.py
@@ -0,0 +1,80 @@
+# 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
+
+import os
+import sys
+
+from ..classy import ClassyProject
+
+
+class TemplateHook(object):
+ __slots__ = ('outfiles')
+ def __init__(self, outfiles):
+ self.outfiles = outfiles
+
+ def __call__(self, build):
+ build.vars['SRC_DIR'] = (build.relative_source(), 'special')
+ unseen = set(build.project.order)
+ if None in unseen:
+ unseen.remove(None)
+ for outfile in self.outfiles:
+ infile = outfile + '.in'
+ print('Generating %s from %s' % (outfile, infile))
+ # by replacing all instances of @VARIABLE@ with the value
+
+ slurpee = open(os.path.join(build.project.srcdir, infile)).read()
+ for var in build.project.order:
+ if var is None:
+ continue
+ val, origin = build.vars[var]
+ key = '@' + var + '@'
+ if key not in slurpee:
+ continue
+ if var in unseen:
+ unseen.remove(var)
+ slurpee = slurpee.replace(key, str(val))
+ # origin is not so useful, given config.status
+ with open(os.path.join(build.builddir, outfile), 'w') as out:
+ out.write(slurpee)
+ if unseen:
+ print('WARNING: variables not used:')
+ print(' ' + '\n '.join(unseen))
+ # lone @s may legitimately appear in the makefile.
+ # paired @s, which would be a forgotten subst, will be obvious.
+
+
+class Templates(ClassyProject):
+ ''' Post hook to generate output files from *.in templates
+ '''
+ __slots__ = ()
+ @classmethod
+ def slots(cls):
+ return super(Templates, cls).slots() + ('template_files',)
+
+ # this class didn't exist in attoconf < 0.7, no need for compatibility
+ def __init__(self, template_files, **kwargs):
+ super(Templates, self).__init__(**kwargs)
+ self.template_files = template_files
+
+ def post(self):
+ super(Templates, self).post()
+ if 'SRC_DIR' in self.order:
+ sys.exit('ERROR: Incompatible generator hooks!')
+ self.order.insert(0, 'SRC_DIR')
+ self.checks.append(TemplateHook(self.template_files))