Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 742795 - Autogenerate autoconf.mk. r=ted
  • Loading branch information
glandium committed Aug 6, 2012
1 parent 60a9477 commit f719e34
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 996 deletions.
49 changes: 27 additions & 22 deletions build/ConfigStatus.py
Expand Up @@ -99,28 +99,32 @@ class ConfigEnvironment(object):
directory. It preprocesses files from the source directory and stores
the result in the object directory.
There are two types of files: config files and config headers,
each treated through a different member function.
Creating a ConfigEnvironment requires a few arguments:
- topsrcdir and topobjdir are, respectively, the top source and
the top object directory.
- defines is a list of (name, value) tuples. In autoconf, these are
set with AC_DEFINE and AC_DEFINE_UNQUOTED
- non_global_defines are a list of names appearing in defines above
that are not meant to be exported in ACDEFINES and ALLDEFINES (see
below)
- substs is a list of (name, value) tuples. In autoconf, these are
set with AC_SUBST.
ConfigEnvironment automatically defines two additional substs variables
from all the defines not appearing in non_global_defines:
- ACDEFINES contains the defines in the form -DNAME=VALUE, for use on
preprocessor command lines. The order in which defines were given
when creating the ConfigEnvironment is preserved.
- ALLDEFINES contains the defines in the form #define NAME VALUE, in
sorted order, for use in config files, for an automatic listing of
defines.
There are two types of files: config files and config headers,
each treated through a different member function.
Creating a ConfigEnvironment requires a few arguments:
- topsrcdir and topobjdir are, respectively, the top source and
the top object directory.
- defines is a list of (name, value) tuples. In autoconf, these are
set with AC_DEFINE and AC_DEFINE_UNQUOTED
- non_global_defines are a list of names appearing in defines above
that are not meant to be exported in ACDEFINES and ALLDEFINES (see
below)
- substs is a list of (name, value) tuples. In autoconf, these are
set with AC_SUBST.
ConfigEnvironment automatically defines two additional substs variables
from all the defines not appearing in non_global_defines:
- ACDEFINES contains the defines in the form -DNAME=VALUE, for use on
preprocessor command lines. The order in which defines were given
when creating the ConfigEnvironment is preserved.
- ALLDEFINES contains the defines in the form #define NAME VALUE, in
sorted order, for use in config files, for an automatic listing of
defines.
and another additional subst variable from all the other substs:
- ALLSUBSTS contains the substs in the form NAME = VALUE, in sorted
order, for use in autoconf.mk. It includes ACDEFINES, but doesn't
include ALLDEFINES.
ConfigEnvironment expects a "top_srcdir" subst to be set with the top
source directory, in msys format on windows. It is used to derive a
Expand All @@ -136,6 +140,7 @@ def __init__(self, topobjdir = '.', topsrcdir = '.',
self.topobjdir = topobjdir
global_defines = [name for name, value in defines if not name in non_global_defines]
self.substs['ACDEFINES'] = ' '.join(["-D%s=%s" % (name, shell_escape(self.defines[name])) for name in global_defines])
self.substs['ALLSUBSTS'] = '\n'.join(sorted(["%s = %s" % (name, self.substs[name]) for name in self.substs]))
self.substs['ALLDEFINES'] = '\n'.join(sorted(["#define %s %s" % (name, self.defines[name]) for name in global_defines]))

def get_relative_srcdir(self, file):
Expand Down
16 changes: 13 additions & 3 deletions build/tests/unit-ConfigStatus.py
Expand Up @@ -54,20 +54,30 @@ def __call__(self, name, mode):

class TestEnvironment(unittest.TestCase):
def test_auto_substs(self):
'''Test the automatically set values of ACDEFINES and ALLDEFINES.
'''Test the automatically set values of ACDEFINES, ALLDEFINES
and ALLSUBSTS.
'''
env = ConfigEnvironment(
defines = [ ('foo', 'bar'), ('baz', 'qux 42'),
('abc', 'def'), ('extra', 'foobar') ],
non_global_defines = ['extra', 'ignore'])
non_global_defines = ['extra', 'ignore'],
substs = [ ('FOO', 'bar'), ('ABC', 'def'),
('bar', 'baz qux'), ('zzz', '"abc def"') ])
# non_global_defines should be filtered out in ACDEFINES and
# ALLDEFINES.
# Original order of the defines need to be respected in ACDEFINES
self.assertEqual(env.substs['ACDEFINES'], '-Dfoo=bar -Dbaz=qux\\ 42 -Dabc=def')
self.assertEqual(env.substs['ACDEFINES'], '''-Dfoo=bar -Dbaz=qux\ 42 -Dabc=def''')
# ALLDEFINES, on the other hand, needs to be sorted
self.assertEqual(env.substs['ALLDEFINES'], '''#define abc def
#define baz qux 42
#define foo bar''')
# Likewise for ALLSUBSTS, which also mustn't contain ALLDEFINES
# but contain ACDEFINES
self.assertEqual(env.substs['ALLSUBSTS'], '''ABC = def
ACDEFINES = -Dfoo=bar -Dbaz=qux\ 42 -Dabc=def
FOO = bar
bar = baz qux
zzz = "abc def"''')

def test_config_file(self):
'''Test the creation of config files.
Expand Down

0 comments on commit f719e34

Please sign in to comment.