Bug 1417264 - Write objdir .mozconfig from Python; r?build draft
authorGregory Szorc <gps@mozilla.com>
Mon, 13 Nov 2017 17:31:14 -0800
changeset 698520 b38078581bddf454c3901ed22620bff4ed6c32f6
parent 698519 231027c4743947f057de4839df6c460fc6b397d0
child 698521 de60f8f52ab392eafe3cb11260bf0d089f4efa08
push id89320
push userbmo:gps@mozilla.com
push dateWed, 15 Nov 2017 22:21:16 +0000
reviewersbuild
bugs1417264
milestone59.0a1
Bug 1417264 - Write objdir .mozconfig from Python; r?build This is a pretty straightforward port of the logic. But we even go a step further: we delete the file in the objdir if there is no source mozconfig! MozReview-Commit-ID: AHFFzy6mXRY
client.mk
python/mozbuild/mozbuild/controller/building.py
--- a/client.mk
+++ b/client.mk
@@ -133,34 +133,28 @@ ifeq ($(TOPSRCDIR),$(OBJDIR))
 else
   CONFIGURE = $(TOPSRCDIR)/configure
 endif
 
 configure-files: $(CONFIGURES)
 
 configure-preqs = \
   configure-files \
-  save-mozconfig \
   $(OBJDIR)/.mozconfig.json \
   $(NULL)
 
 CREATE_MOZCONFIG_JSON = $(shell $(TOPSRCDIR)/mach environment --format=json -o $(OBJDIR)/.mozconfig.json)
 # Force CREATE_MOZCONFIG_JSON above to be resolved, without side effects in
 # case the result is non empty, and allowing an override on the make command
 # line not running the command (using := $(shell) still runs the shell command).
 ifneq (,$(CREATE_MOZCONFIG_JSON))
 endif
 
 $(OBJDIR)/.mozconfig.json: ;
 
-save-mozconfig: $(FOUND_MOZCONFIG)
-ifdef FOUND_MOZCONFIG
-	-cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
-endif
-
 configure:: $(configure-preqs)
 	$(call BUILDSTATUS,TIERS configure)
 	$(call BUILDSTATUS,TIER_START configure)
 	@echo cd $(OBJDIR);
 	@echo $(CONFIGURE) $(CONFIGURE_ARGS)
 	@cd $(OBJDIR) && $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
 	  || ( echo '*** Fix above errors and then restart with\
                "$(MAKE) -f client.mk build"' && exit 1 )
--- a/python/mozbuild/mozbuild/controller/building.py
+++ b/python/mozbuild/mozbuild/controller/building.py
@@ -1,14 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, unicode_literals
 
+import errno
 import getpass
 import io
 import json
 import logging
 import os
 import subprocess
 import sys
 import time
@@ -1365,16 +1366,29 @@ class BuildDriver(MozbuildObject):
                                            '.mozconfig-client-mk')
         with FileAvoidWrite(mozconfig_client_mk) as fh:
             fh.write(b'\n'.join(mozconfig_make_lines))
 
         mozconfig_mk = os.path.join(self.topobjdir, '.mozconfig.mk')
         with FileAvoidWrite(mozconfig_mk) as fh:
             fh.write(b'\n'.join(mozconfig_filtered_lines))
 
+        # Copy the original mozconfig to the objdir.
+        mozconfig_objdir = os.path.join(self.topobjdir, '.mozconfig')
+        if mozconfig['path']:
+            with open(mozconfig['path'], 'rb') as ifh:
+                with FileAvoidWrite(mozconfig_objdir) as ofh:
+                    ofh.write(ifh.read())
+        else:
+            try:
+                os.unlink(mozconfig_objdir)
+            except OSError as e:
+                if e.errno != errno.ENOENT:
+                    raise
+
         if mozconfig_make_lines:
             self.log(logging.WARNING, 'mozconfig_content', {
                 'path': mozconfig['path'],
                 'content': '\n    '.join(mozconfig_make_lines),
             }, 'Adding make options from {path}\n    {content}')
 
         append_env['OBJDIR'] = mozpath.normsep(self.topobjdir)