Skip to content

Commit

Permalink
Bug 1231314 - Turn mozilla-config.h and js-confdefs.h into CONFIGURE_…
Browse files Browse the repository at this point in the history
…DEFINE_FILES. r=gps

Both these files, are, after all, define files, like other CONFIGURE_DEFINE_FILES.
They only happen to have a special requirement for an expansion for all defines,
which doesn't need to happen through traditional preprocessing.

This change adds consistency in how configure-related headers are being handled.
  • Loading branch information
glandium committed Dec 14, 2015
1 parent 91eb55a commit 11dac49
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
3 changes: 2 additions & 1 deletion js/src/js-confdefs.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#ifndef js_confdefs_h
#define js_confdefs_h

@ALLDEFINES@
// Expands to all the defines from configure.
#undef ALLDEFINES

#include "js/RequiredDefines.h"

Expand Down
4 changes: 3 additions & 1 deletion js/src/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ TEST_DIRS += ['jsapi-tests', 'tests', 'gdb']

CONFIGURE_SUBST_FILES += [
'devtools/rootAnalysis/Makefile',
'js-confdefs.h',
'js-config',
'js.pc',
]
CONFIGURE_DEFINE_FILES += [
'js-confdefs.h',
]

if not CONFIG['JS_STANDALONE']:
CONFIGURE_SUBST_FILES += [
Expand Down
4 changes: 3 additions & 1 deletion moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ DIRS += [

if not CONFIG['JS_STANDALONE']:
CONFIGURE_SUBST_FILES += [
'mozilla-config.h',
'tools/update-packaging/Makefile',
]
CONFIGURE_DEFINE_FILES += [
'mozilla-config.h',
]

DIRS += [
'build',
Expand Down
3 changes: 2 additions & 1 deletion mozilla-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#endif
#endif

@ALLDEFINES@
// Expands to all the defines from configure.
#undef ALLDEFINES

/*
* The c99 defining the limit macros (UINT32_MAX for example), says:
Expand Down
16 changes: 15 additions & 1 deletion python/mozbuild/mozbuild/backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def _create_config_header(self, obj):
"#define NAME ORIGINAL_VALUE" is turned into "#define NAME VALUE"
"#undef UNKNOWN_NAME" is turned into "/* #undef UNKNOWN_NAME */"
Whitespaces are preserved.
As a special rule, "#undef ALLDEFINES" is turned into "#define NAME
VALUE" for all the defined variables.
'''
with self._write_file(obj.output_path) as fh, \
open(obj.input_path, 'rU') as input:
Expand All @@ -393,7 +396,18 @@ def _create_config_header(self, obj):
name = m.group('name')
value = m.group('value')
if name:
if name in obj.config.defines:
if name == 'ALLDEFINES':
if cmd == 'define':
raise Exception(
'`#define ALLDEFINES` is not allowed in a '
'CONFIGURE_DEFINE_FILE')
defines = '\n'.join(sorted(
'#define %s %s' % (name, val)
for name, val in obj.config.defines.iteritems()
if name not in obj.config.non_global_defines))
l = l[:m.start('cmd') - 1] \
+ defines + l[m.end('name'):]
elif name in obj.config.defines:
if cmd == 'define' and value:
l = l[:m.start('value')] \
+ str(obj.config.defines[name]) \
Expand Down
17 changes: 6 additions & 11 deletions python/mozbuild/mozbuild/backend/configenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,20 @@ class ConfigEnvironment(object):
- 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)
that are not meant to be exported in ACDEFINES (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
ConfigEnvironment automatically defines one additional substs variable
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 two other additional subst variables 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. Only substs with a VALUE are included, such that
the resulting file doesn't change when new empty substs are added.
order, for use in autoconf.mk. It includes ACDEFINES
Only substs with a VALUE are included, such that the resulting file
doesn't change when new empty substs are added.
This results in less invalidation of build dependencies in the case
of autoconf.mk..
- ALLEMPTYSUBSTS contains the substs with an empty value, in the form
Expand All @@ -117,6 +113,7 @@ def __init__(self, topsrcdir, topobjdir, defines=[], non_global_defines=[],
source = mozpath.join(topobjdir, 'config.status')
self.source = source
self.defines = ReadOnlyDict(defines)
self.non_global_defines = non_global_defines
self.substs = dict(substs)
self.topsrcdir = mozpath.abspath(topsrcdir)
self.topobjdir = mozpath.abspath(topobjdir)
Expand Down Expand Up @@ -146,8 +143,6 @@ def serialize(obj):
serialize(self.substs[name])) for name in self.substs if self.substs[name]]))
self.substs['ALLEMPTYSUBSTS'] = '\n'.join(sorted(['%s =' % name
for name in self.substs if not self.substs[name]]))
self.substs['ALLDEFINES'] = '\n'.join(sorted(['#define %s %s' % (name,
self.defines[name]) for name in global_defines]))

self.substs = ReadOnlyDict(self.substs)

Expand Down
14 changes: 4 additions & 10 deletions python/mozbuild/mozbuild/test/backend/test_configenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(self, *args, **kwargs):

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

0 comments on commit 11dac49

Please sign in to comment.