Bug 1416052 - Generate a make file to include in client.mk; r=nalexander

Currently, client.mk calls `mach environment` to obtain a make file
to be evaluated in the context of client.mk. The reason it is
implemented this way is because client.mk could be an entrypoint to
the build system.

With recent changes that require the use of mach to use client.mk,
we are now guaranteed to have Python code running before client.mk
is invoked. This means we don't need to invoke `mach` from client.mk.

This commit ports the code for generating a client.mk suitable make
file from `mach environment` to the build dispatcher. We now write out
a new .mozconfig-client-mk file in the objdir. client.mk is changed
to cat this file and to include it as a native make file.

The OBJDIR environment variable is also set so client.mk knows where
to read the auto-generated file from.

This commit should be backwards compatible.

Hopefully it is obvious, but this new make file is only temporary.
As soon as the remaining mozconfig logic is moved out of client.mk,
we should be able to simplify down to a single "include" in client.mk.

MozReview-Commit-ID: BEfWo76Z1qA

--HG--
extra : rebase_source : 752df93f816b95bda108a3c787d7f4941b136bbb
This commit is contained in:
Gregory Szorc 2017-11-09 22:27:16 -08:00
parent 550570a148
commit 5da7c49fc4
3 changed files with 23 additions and 18 deletions

View File

@ -49,8 +49,8 @@ endef
# before evaluation. $(shell) replacing newlines with spaces, || is always
# followed by a space (since sed doesn't remove newlines), except on the
# last line, so replace both '|| ' and '||'.
MOZCONFIG_CONTENT := $(subst ||,$(CR),$(subst || ,$(CR),$(shell $(TOPSRCDIR)/mach environment --format=client.mk | sed 's/$$/||/')))
$(eval $(MOZCONFIG_CONTENT))
MOZCONFIG_CONTENT := $(subst ||,$(CR),$(subst || ,$(CR),$(shell cat $(OBJDIR)/.mozconfig-client-mk | sed 's/$$/||/')))
include $(OBJDIR)/.mozconfig-client-mk
export FOUND_MOZCONFIG
@ -108,8 +108,7 @@ endif
include $(TOPSRCDIR)/config/makefiles/makeutils.mk
include $(TOPSRCDIR)/config/makefiles/autotargets.mk
# For now, only output "export" lines and lines containing UPLOAD_EXTRA_FILES
# from mach environment --format=client.mk output.
# For now, only output "export" lines and lines containing UPLOAD_EXTRA_FILES.
MOZCONFIG_MK_LINES := $(filter export||% UPLOAD_EXTRA_FILES% %UPLOAD_EXTRA_FILES%,$(MOZCONFIG_OUT_LINES))
$(OBJDIR)/.mozconfig.mk: $(TOPSRCDIR)/client.mk $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER
$(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@

View File

@ -50,6 +50,7 @@ from ..shellutil import (
quote as shell_quote,
)
from ..util import (
FileAvoidWrite,
mkdir,
resolve_target_to_make,
)
@ -1323,6 +1324,24 @@ class BuildDriver(MozbuildObject):
append_env['CONFIG_GUESS'] = self.resolve_config_guess()
mozconfig = self.mozconfig
mozconfig_client_mk = os.path.join(self.topobjdir,
'.mozconfig-client-mk')
with FileAvoidWrite(mozconfig_client_mk) as fh:
for arg in mozconfig['make_extra'] or []:
fh.write(arg)
fh.write(b'\n')
if mozconfig['make_flags']:
fh.write(b'MOZ_MAKE_FLAGS=%s\n' % b' '.join(mozconfig['make_flags']))
objdir = mozpath.normsep(self.topobjdir)
fh.write(b'MOZ_OBJDIR=%s\n' % objdir)
fh.write(b'OBJDIR=%s\n' % objdir)
if mozconfig['path']:
fh.write(b'FOUND_MOZCONFIG=%s\n' %
mozpath.normsep(mozconfig['path']))
append_env['OBJDIR'] = mozpath.normsep(self.topobjdir)
return self._run_make(srcdir=True,
filename='client.mk',
allow_parallel=False,

View File

@ -1021,7 +1021,7 @@ class MachDebug(MachCommandBase):
@Command('environment', category='build-dev',
description='Show info about the mach and build environment.')
@CommandArgument('--format', default='pretty',
choices=['pretty', 'client.mk', 'configure', 'json'],
choices=['pretty', 'configure', 'json'],
help='Print data in the given format.')
@CommandArgument('--output', '-o', type=str,
help='Output to the given file.')
@ -1089,19 +1089,6 @@ class MachDebug(MachCommandBase):
for k in sorted(config.defines):
print('\t%s' % k, file=out)
def _environment_client_mk(self, out, verbose):
if self.mozconfig['make_extra']:
for arg in self.mozconfig['make_extra']:
print(arg, file=out)
if self.mozconfig['make_flags']:
print('MOZ_MAKE_FLAGS=%s' % ' '.join(self.mozconfig['make_flags']))
objdir = mozpath.normsep(self.topobjdir)
print('MOZ_OBJDIR=%s' % objdir, file=out)
print('OBJDIR=%s' % objdir, file=out)
if self.mozconfig['path']:
print('FOUND_MOZCONFIG=%s' % mozpath.normsep(self.mozconfig['path']),
file=out)
def _environment_json(self, out, verbose):
import json
class EnvironmentEncoder(json.JSONEncoder):