Bug 1417264 - Write .mozconfig.json from Python; r=nalexander draft
authorGregory Szorc <gps@mozilla.com>
Mon, 13 Nov 2017 17:45:03 -0800
changeset 699269 ee1defd74decfd64ffb66a45b053dada58de04fb
parent 699268 1b9387bd72f5a8e9bf8274f5764b0db0176fdba2
child 699371 13377948d6eb4862fab79c792a13981fa5b43bb8
push id89518
push userbmo:gps@mozilla.com
push dateThu, 16 Nov 2017 23:00:58 +0000
reviewersnalexander
bugs1417264
milestone59.0a1
Bug 1417264 - Write .mozconfig.json from Python; r=nalexander In order to determine if we need to re-run configure, we write a JSON file representing the evaluated mozconfig. If this JSON file changes, configure (and config.status for that matter) is out of data and it is re-executed. This commit moves the generation of that JSON file to Python. MozReview-Commit-ID: 636rpSY7gOm
client.mk
python/mozbuild/mozbuild/controller/building.py
--- a/client.mk
+++ b/client.mk
@@ -136,25 +136,16 @@ endif
 
 configure-files: $(CONFIGURES)
 
 configure-preqs = \
   configure-files \
   $(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: ;
-
 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 )
@@ -163,17 +154,17 @@ configure:: $(configure-preqs)
 
 ifneq (,$(MAKEFILE))
 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
 
 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
 else
 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
 endif
-	@$(MAKE) -f $(TOPSRCDIR)/client.mk configure CREATE_MOZCONFIG_JSON=
+	@$(MAKE) -f $(TOPSRCDIR)/client.mk configure
 
 ####################################
 # Build it
 
 build::  $(OBJDIR)/Makefile $(OBJDIR)/config.status
 	+$(MOZ_MAKE)
 
 ifdef MOZ_AUTOMATION
--- a/python/mozbuild/mozbuild/controller/building.py
+++ b/python/mozbuild/mozbuild/controller/building.py
@@ -1367,16 +1367,24 @@ 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))
 
+        mozconfig_json = os.path.join(self.topobjdir, '.mozconfig.json')
+        with FileAvoidWrite(mozconfig_json) as fh:
+            json.dump({
+                'topsrcdir': self.topsrcdir,
+                'topobjdir': self.topobjdir,
+                'mozconfig': mozconfig,
+            }, fh, sort_keys=True, indent=2)
+
         # 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: