mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 844635 - Part 2: Don't require Makefile.in to exist; r=glandium
This commit is contained in:
parent
75bfecd9a3
commit
e5ad4d7a1c
@ -16,6 +16,19 @@ from ..frontend.data import (
|
|||||||
from ..util import FileAvoidWrite
|
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):
|
class BackendMakeFile(object):
|
||||||
"""Represents a generated backend.mk file.
|
"""Represents a generated backend.mk file.
|
||||||
|
|
||||||
@ -73,9 +86,17 @@ class BackendMakeFile(object):
|
|||||||
self.fh.write('\n')
|
self.fh.write('\n')
|
||||||
self.fh.write('MOZBUILD_DERIVED := 1\n')
|
self.fh.write('MOZBUILD_DERIVED := 1\n')
|
||||||
|
|
||||||
# SUBSTITUTE_FILES handles Makefile.in -> Makefile conversion.
|
# SUBSTITUTE_FILES handles Makefile.in -> Makefile conversion. This
|
||||||
|
# also doubles to handle the case where there is no Makefile.in.
|
||||||
self.fh.write('NO_MAKEFILE_RULE := 1\n')
|
self.fh.write('NO_MAKEFILE_RULE := 1\n')
|
||||||
|
|
||||||
|
# We can't blindly have a SUBMAKEFILES rule because some of the
|
||||||
|
# Makefile may not have a corresponding Makefile.in. For the case
|
||||||
|
# where a new directory is added, the mozbuild file referencing that
|
||||||
|
# new directory will need updated. This will cause a full backend
|
||||||
|
# scan and build, installing the new Makefile.
|
||||||
|
self.fh.write('NO_SUBMAKEFILES_RULE := 1\n')
|
||||||
|
|
||||||
|
|
||||||
def write(self, buf):
|
def write(self, buf):
|
||||||
self.fh.write(buf)
|
self.fh.write(buf)
|
||||||
@ -157,16 +178,29 @@ class RecursiveMakeBackend(BuildBackend):
|
|||||||
os.makedirs(bf.objdir)
|
os.makedirs(bf.objdir)
|
||||||
|
|
||||||
makefile_in = os.path.join(srcdir, 'Makefile.in')
|
makefile_in = os.path.join(srcdir, 'Makefile.in')
|
||||||
|
makefile = os.path.join(bf.objdir, 'Makefile')
|
||||||
|
|
||||||
if not os.path.exists(makefile_in):
|
# If Makefile.in exists, use it as a template. Otherwise, create a
|
||||||
raise Exception('Could not find Makefile.in: %s' % makefile_in)
|
# stub.
|
||||||
|
if os.path.exists(makefile_in):
|
||||||
|
self.log(logging.DEBUG, 'substitute_makefile',
|
||||||
|
{'path': makefile}, 'Substituting makefile: {path}')
|
||||||
|
bf.environment.create_config_file(makefile)
|
||||||
|
bf.write('SUBSTITUTE_FILES += Makefile\n')
|
||||||
|
else:
|
||||||
|
self.log(logging.DEBUG, 'stub_makefile',
|
||||||
|
{'path': makefile}, 'Creating stub Makefile: {path}')
|
||||||
|
|
||||||
out_path = os.path.join(bf.objdir, 'Makefile')
|
params = {
|
||||||
self.log(logging.DEBUG, 'create_makefile', {'path': out_path},
|
'topsrc': bf.environment.get_top_srcdir(makefile),
|
||||||
'Generating makefile: {path}')
|
'src': bf.environment.get_file_srcdir(makefile),
|
||||||
bf.environment.create_config_file(out_path)
|
'depth': bf.environment.get_depth(makefile),
|
||||||
|
'relsrc': bf.environment.get_relative_srcdir(makefile),
|
||||||
|
}
|
||||||
|
|
||||||
|
with FileAvoidWrite(makefile) as fh:
|
||||||
|
fh.write(STUB_MAKEFILE.format(**params))
|
||||||
|
|
||||||
bf.write('SUBSTITUTE_FILES += Makefile\n')
|
|
||||||
bf.close()
|
bf.close()
|
||||||
|
|
||||||
def _process_directory_traversal(self, obj, backend_file):
|
def _process_directory_traversal(self, obj, backend_file):
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
# 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
|
|
||||||
|
|
@ -31,11 +31,9 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||||||
expected = ['', 'dir1', 'dir2']
|
expected = ['', 'dir1', 'dir2']
|
||||||
|
|
||||||
for d in expected:
|
for d in expected:
|
||||||
in_path = os.path.join(env.topsrcdir, d, 'Makefile.in')
|
|
||||||
out_makefile = os.path.join(env.topobjdir, d, 'Makefile')
|
out_makefile = os.path.join(env.topobjdir, d, 'Makefile')
|
||||||
out_backend = os.path.join(env.topobjdir, d, 'backend.mk')
|
out_backend = os.path.join(env.topobjdir, d, 'backend.mk')
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(in_path))
|
|
||||||
self.assertTrue(os.path.exists(out_makefile))
|
self.assertTrue(os.path.exists(out_makefile))
|
||||||
self.assertTrue(os.path.exists(out_backend))
|
self.assertTrue(os.path.exists(out_backend))
|
||||||
|
|
||||||
@ -57,6 +55,18 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||||||
'include $(topsrcdir)/config/rules.mk'
|
'include $(topsrcdir)/config/rules.mk'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_missing_makefile_in(self):
|
||||||
|
"""Ensure missing Makefile.in results in Makefile creation."""
|
||||||
|
env = self._consume('stub0', RecursiveMakeBackend)
|
||||||
|
|
||||||
|
p = os.path.join(env.topobjdir, 'dir2', 'Makefile')
|
||||||
|
self.assertTrue(os.path.exists(p))
|
||||||
|
|
||||||
|
lines = [l.strip() for l in open(p, 'rt').readlines()]
|
||||||
|
self.assertEqual(len(lines), 9)
|
||||||
|
|
||||||
|
self.assertTrue(lines[0].startswith('# THIS FILE WAS AUTOMATICALLY'))
|
||||||
|
|
||||||
def test_backend_mk(self):
|
def test_backend_mk(self):
|
||||||
"""Ensure backend.mk file is written out properly."""
|
"""Ensure backend.mk file is written out properly."""
|
||||||
env = self._consume('stub0', RecursiveMakeBackend)
|
env = self._consume('stub0', RecursiveMakeBackend)
|
||||||
@ -67,6 +77,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||||||
self.assertEqual(lines, [
|
self.assertEqual(lines, [
|
||||||
'MOZBUILD_DERIVED := 1',
|
'MOZBUILD_DERIVED := 1',
|
||||||
'NO_MAKEFILE_RULE := 1',
|
'NO_MAKEFILE_RULE := 1',
|
||||||
|
'NO_SUBMAKEFILES_RULE := 1',
|
||||||
'DIRS := dir1',
|
'DIRS := dir1',
|
||||||
'PARALLEL_DIRS := dir2',
|
'PARALLEL_DIRS := dir2',
|
||||||
'TEST_DIRS := dir3',
|
'TEST_DIRS := dir3',
|
||||||
@ -100,6 +111,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||||||
self.assertEqual(lines, [
|
self.assertEqual(lines, [
|
||||||
'MOZBUILD_DERIVED := 1',
|
'MOZBUILD_DERIVED := 1',
|
||||||
'NO_MAKEFILE_RULE := 1',
|
'NO_MAKEFILE_RULE := 1',
|
||||||
|
'NO_SUBMAKEFILES_RULE := 1',
|
||||||
'DIRS := dir',
|
'DIRS := dir',
|
||||||
'PARALLEL_DIRS := p_dir',
|
'PARALLEL_DIRS := p_dir',
|
||||||
'DIRS += external',
|
'DIRS += external',
|
||||||
|
Loading…
Reference in New Issue
Block a user