Navigation Menu

Skip to content

Commit

Permalink
Bug 912293 - Add a generic header and footer to generated Makefiles. …
Browse files Browse the repository at this point in the history
…r=gps
  • Loading branch information
glandium committed Sep 5, 2013
1 parent b411362 commit 81fd05a
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 50 deletions.
3 changes: 3 additions & 0 deletions config/autoconf.mk.in
@@ -1,3 +1,6 @@
ifndef INCLUDED_AUTOCONF_MK
INCLUDED_AUTOCONF_MK = 1
include $(DEPTH)/config/emptyvars.mk
@ALLSUBSTS@
include $(topsrcdir)/config/baseconfig.mk
endif
2 changes: 0 additions & 2 deletions config/baseconfig.mk
@@ -1,5 +1,3 @@
INCLUDED_AUTOCONF_MK = 1

includedir := $(includedir)/$(MOZ_APP_NAME)-$(MOZ_APP_VERSION)
idldir = $(datadir)/idl/$(MOZ_APP_NAME)-$(MOZ_APP_VERSION)
installdir = $(libdir)/$(MOZ_APP_NAME)-$(MOZ_APP_VERSION)
Expand Down
6 changes: 6 additions & 0 deletions config/rules.mk
Expand Up @@ -10,6 +10,12 @@ ifndef topsrcdir
$(error topsrcdir was not set))
endif

# Define an include-at-most-once flag
ifdef INCLUDED_RULES_MK
$(error Do not include rules.mk twice!)
endif
INCLUDED_RULES_MK = 1

# Integrate with mozbuild-generated make files. We first verify that no
# variables provided by the automatically generated .mk files are
# present. If they are, this is a violation of the separation of
Expand Down
3 changes: 3 additions & 0 deletions js/src/config/autoconf.mk.in
@@ -1,3 +1,6 @@
ifndef INCLUDED_AUTOCONF_MK
INCLUDED_AUTOCONF_MK = 1
include $(DEPTH)/config/emptyvars.mk
@ALLSUBSTS@
include $(topsrcdir)/config/baseconfig.mk
endif
2 changes: 0 additions & 2 deletions js/src/config/baseconfig.mk
@@ -1,5 +1,3 @@
INCLUDED_AUTOCONF_MK = 1

installdir = $(libdir)/$(MOZ_APP_NAME)-$(MOZ_APP_VERSION)
sdkdir = $(libdir)/$(MOZ_APP_NAME)-devel-$(MOZ_APP_VERSION)

Expand Down
6 changes: 6 additions & 0 deletions js/src/config/rules.mk
Expand Up @@ -10,6 +10,12 @@ ifndef topsrcdir
$(error topsrcdir was not set))
endif

# Define an include-at-most-once flag
ifdef INCLUDED_RULES_MK
$(error Do not include rules.mk twice!)
endif
INCLUDED_RULES_MK = 1

# Integrate with mozbuild-generated make files. We first verify that no
# variables provided by the automatically generated .mk files are
# present. If they are, this is a violation of the separation of
Expand Down
2 changes: 1 addition & 1 deletion js/src/configure.in
Expand Up @@ -4341,7 +4341,7 @@ AC_SUBST(ac_configure_args)
dnl Spit out some output
dnl ========================================================

AC_OUTPUT([js-confdefs.h Makefile config/autoconf.mk config/emptyvars.mk])
AC_OUTPUT([js-confdefs.h config/autoconf.mk config/emptyvars.mk])

# Produce the js-config script at configure time; see the comments for
# 'js*-config' in Makefile.in.
Expand Down
40 changes: 37 additions & 3 deletions python/mozbuild/mozbuild/backend/configenvironment.py
Expand Up @@ -205,7 +205,42 @@ def create_config_file(self, path, extra=None):
"relativesrcdir" for its source directory relative to the top
"DEPTH" for the path to the top object directory
'''
input = self.get_input(path)
if os.path.basename(path) == 'Makefile':
return self.create_makefile(path, extra=extra)
pp = self._get_preprocessor(path, extra)
pp.do_include(self.get_input(path))
return pp.out.close()

def create_makefile(self, path, stub=False, extra=None):
'''Creates the given makefile. Makefiles are treated the same as
config files, but some additional header and footer is added to the
output.
When the stub argument is True, no source file is used, and a stub
makefile with the default header and footer only is created.
'''
pp = self._get_preprocessor(path, extra)
pp.handleLine('# THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT MODIFY BY HAND.\n');
pp.handleLine('DEPTH := @DEPTH@\n')
pp.handleLine('topsrcdir := @top_srcdir@\n')
pp.handleLine('srcdir := @srcdir@\n')
pp.handleLine('VPATH := @srcdir@\n')
pp.handleLine('relativesrcdir := @relativesrcdir@\n')
pp.handleLine('include $(DEPTH)/config/autoconf.mk\n')
if not stub:
pp.do_include(self.get_input(path))
# Empty line to avoid failures when last line in Makefile.in ends
# with a backslash.
pp.handleLine('\n')
pp.handleLine('ifndef INCLUDED_RULES_MK\n')
pp.handleLine('include $(topsrcdir)/config/rules.mk\n')
pp.handleLine('endif\n')
return pp.out.close()

def _get_preprocessor(self, path, extra):
'''Returns a preprocessor for use by create_config_file and
create_makefile.
'''
pp = Preprocessor()
pp.context.update(self.substs)
pp.context.update(top_srcdir = self.get_top_srcdir(path))
Expand All @@ -218,8 +253,7 @@ def create_config_file(self, path, extra=None):
pp.setMarker(None)

pp.out = FileAvoidWrite(path)
pp.do_include(input)
return pp.out.close()
return pp

def create_config_header(self, path):
'''Creates the given config header. A config header is generated by
Expand Down
34 changes: 5 additions & 29 deletions python/mozbuild/mozbuild/backend/recursivemake.py
Expand Up @@ -31,19 +31,6 @@
from ..util import FileAvoidWrite


STUB_MAKEFILE = '''
# THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT MODIFY BY HAND.
DEPTH := {depth}
topsrcdir := {topsrc}
srcdir := {src}
VPATH := {src}
relativesrcdir := {relsrc}
include {topsrc}/config/rules.mk
'''.lstrip()


class BackendMakeFile(object):
"""Represents a generated backend.mk file.
Expand Down Expand Up @@ -237,14 +224,11 @@ def consume_finished(self):

# If Makefile.in exists, use it as a template. Otherwise, create a
# stub.
if os.path.exists(makefile_in):
stub = not os.path.exists(makefile_in)
if not stub:
self.log(logging.DEBUG, 'substitute_makefile',
{'path': makefile}, 'Substituting makefile: {path}')

self._update_from_avoid_write(
bf.environment.create_config_file(makefile))
self.summary.managed_count += 1

# Adding the Makefile.in here has the desired side-effect that
# if the Makefile.in disappears, this will force moz.build
# traversal. This means that when we remove empty Makefile.in
Expand All @@ -255,17 +239,9 @@ def consume_finished(self):
self.log(logging.DEBUG, 'stub_makefile',
{'path': makefile}, 'Creating stub Makefile: {path}')

params = {
'topsrc': bf.environment.get_top_srcdir(makefile),
'src': bf.environment.get_file_srcdir(makefile),
'depth': bf.environment.get_depth(makefile),
'relsrc': bf.environment.get_relative_srcdir(makefile),
}

aw = FileAvoidWrite(makefile)
aw.write(STUB_MAKEFILE.format(**params))
self._update_from_avoid_write(aw.close())
self.summary.managed_count += 1
self._update_from_avoid_write(
bf.environment.create_makefile(makefile, stub=stub))
self.summary.managed_count += 1

self._update_from_avoid_write(bf.close())
self.summary.managed_count += 1
Expand Down
9 changes: 1 addition & 8 deletions python/mozbuild/mozbuild/test/backend/data/stub0/Makefile.in
@@ -1,11 +1,4 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

DEPTH := @DEPTH@
topsrcdir := @top_srcdir@
srcdir := @srcdir@
VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

include $(topsrcdir)/config/rules.mk
FOO := foo
14 changes: 9 additions & 5 deletions python/mozbuild/mozbuild/test/backend/test_recursivemake.py
Expand Up @@ -47,16 +47,20 @@ def test_makefile_conversion(self):

p = os.path.join(env.topobjdir, 'Makefile')

lines = [l.strip() for l in open(p, 'rt').readlines()[3:]]
lines = [l.strip() for l in open(p, 'rt').readlines()[1:] if not l.startswith('#')]
self.assertEqual(lines, [
'DEPTH := .',
'topsrcdir := %s' % env.topsrcdir,
'srcdir := %s' % env.topsrcdir,
'VPATH = %s' % env.topsrcdir,
'',
'VPATH := %s' % env.topsrcdir,
'relativesrcdir := .',
'include $(DEPTH)/config/autoconf.mk',
'',
'include $(topsrcdir)/config/rules.mk'
'FOO := foo',
'',
'ifndef INCLUDED_RULES_MK',
'include $(topsrcdir)/config/rules.mk',
'endif',
])

def test_missing_makefile_in(self):
Expand All @@ -67,7 +71,7 @@ def test_missing_makefile_in(self):
self.assertTrue(os.path.exists(p))

lines = [l.strip() for l in open(p, 'rt').readlines()]
self.assertEqual(len(lines), 9)
self.assertEqual(len(lines), 11)

self.assertTrue(lines[0].startswith('# THIS FILE WAS AUTOMATICALLY'))

Expand Down

0 comments on commit 81fd05a

Please sign in to comment.