summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-08-06 15:13:03 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-08-06 15:13:03 -0700
commit9532822afccc8db328e07992313d458192f2a367 (patch)
tree8aa5907282100e65648020b130c3e845b8a1da8b
parentb26aadbf16f4873411f77f08ebdd228528c5723b (diff)
downloadattobuild-9532822afccc8db328e07992313d458192f2a367.tar.gz
attobuild-9532822afccc8db328e07992313d458192f2a367.tar.bz2
attobuild-9532822afccc8db328e07992313d458192f2a367.tar.xz
attobuild-9532822afccc8db328e07992313d458192f2a367.zip
All specifying varname, and fix bugs
-rw-r--r--attoconf/_version.py2
-rw-r--r--attoconf/core.py26
-rw-r--r--attoconf/lib/c.py10
-rw-r--r--attoconf/lib/install.py13
-rw-r--r--attoconf/lib/make.py8
-rw-r--r--attoconf/types.py6
6 files changed, 29 insertions, 36 deletions
diff --git a/attoconf/_version.py b/attoconf/_version.py
index cf56cb9..d7460a2 100644
--- a/attoconf/_version.py
+++ b/attoconf/_version.py
@@ -11,7 +11,7 @@ minor = 3
# Incremented if there is a bugfix release.
# Might not be contiguous.
-patch = 1
+patch = 2
# Reserved for distributors and forks.
# Contains arbitrary text, but no parentheses or newlines.
diff --git a/attoconf/core.py b/attoconf/core.py
index 39a3298..b200cc1 100644
--- a/attoconf/core.py
+++ b/attoconf/core.py
@@ -19,13 +19,12 @@ from __future__ import print_function, division, absolute_import
from collections import namedtuple
import os
-import pipes
import sys
from .help import Help
# Nothing to see here. Move along.
-Option = namedtuple('Option', ['type', 'init'])
+Option = namedtuple('Option', ['type', 'init', 'var'])
class ArgumentError(Exception): pass
def as_var(name):
@@ -77,7 +76,7 @@ class Project(object):
self.help.add_option(key, help, hidden)
def add_option(self, name, init, type, check,
- help, hidden,
+ help, hidden, var=None,
help_var=None, help_def=None):
''' Add an actual option.
@@ -96,16 +95,18 @@ class Project(object):
if name in self.options:
raise KeyError(name)
assert type.__module__ == 'attoconf.types', '%s.%s' % (type.__module__, type.__name__)
- self.options[name] = Option(init=init, type=type)
+ if var is None:
+ var = as_var(name)
+ if init is not None:
+ init = type(init)
+ self.options[name] = Option(init=init, type=type, var=var)
if check is not None:
self.checks.append(
- lambda bld: check(bld, bld.vars[as_var(name)][0]) )
+ lambda bld: check(bld, bld.vars[var][0]) )
if help_var is None:
- help_var = as_var(name)
+ help_var = var
if help_def is None:
help_def = init
- if isinstance(help_def, list):
- help_def = ' '.join(pipes.quote(a) for a in help_def)
if help_def is not None:
help = '%s [%s]' % (help, help_def)
@@ -142,8 +143,8 @@ class Build(object):
'''
self.project = project
self.builddir = trim_trailing_slashes(builddir)
- self.vars = {as_var(k): (o.init, 'default')
- for k, o in project.options.iteritems()}
+ self.vars = {o.var: (o.init, 'default')
+ for o in project.options.itervalues()}
def apply_arg(self, arg):
''' Parse a single argument, expanding aliases.
@@ -168,7 +169,7 @@ class Build(object):
opt = self.project.options.get(k)
if opt is None:
raise sys.exit('Unknown option %s' % k)
- self.vars[as_var(k)] = (opt.type(a), 'command-line')
+ self.vars[opt.var] = (opt.type(a), 'command-line')
def finish(self):
''' With the current set of variables, run all the checks
@@ -186,7 +187,8 @@ class Build(object):
continue
val = env.get(k)
if val is not None:
- self.vars[k] = (self.project.options[k].type(val), 'environment')
+ opt = self.project.options[k]
+ self.vars[opt.var] = (opt.type(val), 'environment')
for arg in args:
self.apply_arg(arg)
diff --git a/attoconf/lib/c.py b/attoconf/lib/c.py
index c4eefdb..13dd3c1 100644
--- a/attoconf/lib/c.py
+++ b/attoconf/lib/c.py
@@ -28,7 +28,7 @@ class TestError(Exception):
pass
def do_exec(build, args):
- p = subprocess.Popen(args, cwd=build.builddir,
+ p = subprocess.Popen(args.list, cwd=build.builddir,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, _ = p.communicate()
@@ -200,10 +200,8 @@ def try_compile_link2_cxx(build, body, CXXFLAGS=[], CPPFLAGS=[], LDFLAGS=[], LDL
def ldflags(build, LDFLAGS):
pass
-def libs(build, LIBS):
- # Make expects something different
- build.vars['LDLIBS'] = build.vars['LIBS']
- del build.vars['LIBS']
+def libs(build, LDLIBS):
+ pass
def cppflags(build, CPPFLAGS):
pass
@@ -235,7 +233,7 @@ class Link(Arches2):
self.add_option('LIBS', init=[],
type=ShellList, check=libs,
help='libraries to pass to the linker, e.g. -l<library>',
- hidden=False)
+ hidden=False, var='LDLIBS')
class Preprocess(Arches2):
__slots__ = ()
diff --git a/attoconf/lib/install.py b/attoconf/lib/install.py
index d8d6cf5..444c167 100644
--- a/attoconf/lib/install.py
+++ b/attoconf/lib/install.py
@@ -20,7 +20,7 @@ from __future__ import print_function, division, absolute_import
import os
from ..classy import ClassyProject
-from ..types import shell_word, version, filepath
+from ..types import shell_word, version, filepath, quoted_string
def exec_prefix(build, EPREFIX):
@@ -28,12 +28,7 @@ def exec_prefix(build, EPREFIX):
PREFIX, origin = build.vars['PREFIX']
if origin != 'default':
origin = 'derived from PREFIX'
- build.vars['EXEC_PREFIX'] = (PREFIX, origin)
- # is this a good idea? is there a better way?
- # how will this interfere with hashing?
- # at least we don't have to worry about the environment ...
- build.vars['EPREFIX'] = build.vars['EXEC_PREFIX']
- del build.vars['EXEC_PREFIX']
+ build.vars['EPREFIX'] = (PREFIX, origin)
def bindir(build, DIR):
if DIR is None:
@@ -196,7 +191,7 @@ class Install(ClassyProject):
hidden=True,
help_var='VERSION')
self.add_option('--package-name', init=self.package_name,
- type=version, check=None,
+ type=quoted_string, check=None,
help='Long name of this package (don\'t change)',
hidden=True,
help_var='NAME')
@@ -213,7 +208,7 @@ class Install(ClassyProject):
type=filepath, check=exec_prefix,
help='install architecture-dependent files in EPREFIX',
hidden=False,
- help_var='EPREFIX', help_def='PREFIX')
+ var='EPREFIX', help_def='PREFIX')
self.add_help('Fine tuning of the installation directories:',
hidden=False)
diff --git a/attoconf/lib/make.py b/attoconf/lib/make.py
index e54224d..890361a 100644
--- a/attoconf/lib/make.py
+++ b/attoconf/lib/make.py
@@ -18,7 +18,6 @@
from __future__ import print_function, division, absolute_import
import os
-from pipes import quote
from ..classy import ClassyProject
from ..version import string as version_string
@@ -53,13 +52,6 @@ class MakeHook(object):
# especially conditional ones ...
var = '# ' + var
val = 'not defined'
- elif isinstance(val, list):
- val = ' '.join(quote(a) for a in val)
- elif isinstance(val, str):
- val = quote(val)
- else:
- print('Assuming it\'s safe to print an instance of',
- type(val).__name__, '...')
out.write('%s = %s # %s\n' % (var, val, origin))
if self.infile is not None:
out.write('\n# The rest was copied from %s\n' % self.infile)
diff --git a/attoconf/types.py b/attoconf/types.py
index f4cd178..ae0ca44 100644
--- a/attoconf/types.py
+++ b/attoconf/types.py
@@ -80,10 +80,16 @@ class ShellList(object):
def shell_word(s):
if s != shell_quote(s):
+ if s == '':
+ return "''"
raise ValueError('not a word: %r' % s)
return s
+def quoted_string(s):
+ return shell_quote(s)
+
+
def version(s):
if s.startswith('v'):
s = s[1:]