Port Bug 911634 - Create a .mozconfig.mk in the objdir when starting a build, and include it from config.mk. rs=build system peer port of m-c patch,a=bustage-fix
authorMark Banner <bugzilla@standard8.plus.com>
Fri, 06 Sep 2013 10:00:06 +0100
changeset 12809 518f766beceb1a1ba0104d843e916ab8b6990d99
parent 12808 8958f7bad543101e5413557b2eafd59fd445608c
child 12810 dd53119788d828291985f9be14fff04842524d3a
push id1019
push userbugzilla@standard8.plus.com
push dateMon, 28 Oct 2013 22:08:40 +0000
treeherdercomm-esr52@742166161062 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbuild, bustage-fix
bugs911634
Port Bug 911634 - Create a .mozconfig.mk in the objdir when starting a build, and include it from config.mk. rs=build system peer port of m-c patch,a=bustage-fix
Makefile.in
build/autoconf/mozconfig2client-mk
client.mk
config/config.mk
--- a/Makefile.in
+++ b/Makefile.in
@@ -90,13 +90,13 @@ SUPPRESS_DEFAULT_RULES := 1
 include $(topsrcdir)/config/rules.mk
 
 # defined in (mozilla/.../)package-name.mk
 export MOZ_SOURCE_STAMP
 
 DIST_GARBAGE = config.cache config.log config.status* config-defs.h \
    config/autoconf.mk \
    unallmakefiles \
-   $(topsrcdir)/.mozconfig.mk $(topsrcdir)/.mozconfig.out
+   .mozconfig.mk
 
 distclean::
 	cat unallmakefiles | $(XARGS) rm -f
 	rm -f $(DIST_GARBAGE)
--- a/build/autoconf/mozconfig2client-mk
+++ b/build/autoconf/mozconfig2client-mk
@@ -38,34 +38,24 @@ ac_add_app_options() {
 
 mk_add_options() {
   for _opt
   do
     # Escape shell characters, space, tab, dollar, quote, backslash,
     # and substitute '@<word>@' with '$(<word>)'.
     _opt=`echo "$_opt" | sed -e 's/\([\"\\]\)/\\\\\1/g; s/@\([^@]*\)@/\$(\1)/g;'`
     echo $_opt;
-    opts="${opts:+$opts^}$_opt";
-  done
-}
-
-mk_echo_options() {
-  echo "Adding client.mk options from $FOUND_MOZCONFIG:" >&2
-  IFS=^
-  for _opt in $opts; do
-    echo "    $_opt" >&2
   done
 }
 
 # Main
 #--------------------------------------------------
 
 scriptdir=`dirname $0`
 topsrcdir=$1
-opts=""
 
 # If the path changes, configure should be rerun
 echo "# PATH=$PATH"
 
 # If FOUND_MOZCONFIG isn't set, look for it and make sure the script doesn't error out
 isfoundset=${FOUND_MOZCONFIG+yes}
 if [ -z $isfoundset ]; then
   FOUND_MOZCONFIG=`$scriptdir/mozconfig-find $topsrcdir`
@@ -76,15 +66,11 @@ if [ -z $isfoundset ]; then
   fi
 fi
 
 if [ -n $isfoundset ]; then
   if [ "$FOUND_MOZCONFIG" ]
   then
     print_header
     . "$FOUND_MOZCONFIG"
-  fi
-  echo "export FOUND_MOZCONFIG := $FOUND_MOZCONFIG"
-
-  if [ "$opts" ]; then
-    mk_echo_options
+    echo "FOUND_MOZCONFIG := $FOUND_MOZCONFIG"
   fi
 fi
--- a/client.mk
+++ b/client.mk
@@ -101,17 +101,32 @@ endif
 
 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
 
 define CR
 
 
 endef
 
-$(eval $(subst ||,$(CR),$(shell _PYMAKE=$(.PYMAKE) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) 2> $(TOPSRCDIR)/.mozconfig.out | sed 's/$$/||/')))
+# As $(shell) doesn't preserve newlines, use sed to replace them with an
+# unlikely sequence (||), which is then replaced back to newlines by make
+# 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 _PYMAKE=$(.PYMAKE) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) | sed 's/$$/||/')))
+$(eval $(MOZCONFIG_CONTENT))
+
+# As '||' was used as a newline separator, it means it's not occurring in
+# lines themselves. It can thus safely be used to replaces normal spaces,
+# to then replace newlines with normal spaces. This allows to get a list
+# of mozconfig output lines.
+MOZCONFIG_OUT_LINES := $(subst $(CR), ,$(subst $(NULL) $(NULL),||,$(MOZCONFIG_CONTENT)))
+# Filter-out comments from those lines.
+START_COMMENT = \#
+MOZCONFIG_OUT_FILTERED := $(filter-out $(START_COMMENT)%,$(MOZCONFIG_OUT_LINES))
 
 ifndef MOZ_OBJDIR
   MOZ_OBJDIR = obj-$(CONFIG_GUESS)
 else
 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
   ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
   ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(MOZ_OBJDIR))))
   $(error For Windows Pymake builds, MOZ_OBJDIR must be a Windows [and not MSYS] style path.)
@@ -147,32 +162,55 @@ CONFIGURES += $(TOPSRCDIR)/mozilla/js/sr
 
 # The default rule is build
 build::
 
 # Define mkdir
 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
 
+# Create a makefile containing the mk_add_options values from mozconfig,
+# but only do so when OBJDIR is defined (see further above).
+ifdef MOZ_BUILD_PROJECTS
+ifdef MOZ_CURRENT_PROJECT
+WANT_MOZCONFIG_MK = 1
+else
+WANT_MOZCONFIG_MK =
+endif
+else
+WANT_MOZCONFIG_MK = 1
+endif
+
+ifdef WANT_MOZCONFIG_MK
+# For now, only output "export" lines from mozconfig2client-mk output.
+MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES))
+$(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR))
+	$(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo "$(subst ||, ,$(line))";) )) > $@
+
+# Include that makefile so that it is created. This should not actually change
+# the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
+# from, has already been eval'ed.
+-include $(OBJDIR)/.mozconfig.mk
+endif
+
 # These targets are candidates for auto-running client.py
 
 ifeq (01,$(MAKELEVEL)$(if $(ALWAYS_RUN_CLIENT_PY),1,))
 
 build profiledbuild configure:: run_client_py
 	$(MAKE) -f $(TOPSRCDIR)/client.mk $@
 else
 
 
 # Print out any options loaded from mozconfig.
 all build clean depend distclean export libs install realclean::
-	@if test -f .mozconfig.out; then \
-	  cat .mozconfig.out; \
-	  rm -f .mozconfig.out; \
-	else true; \
-	fi
+ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
+	$(info Adding client.mk options from $(FOUND_MOZCONFIG):)
+	$(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
+endif
 
 # Windows equivalents
 build_all: build
 build_all_dep: alldep
 build_all_depend: alldep
 clobber clobber_all: clean
 
 # Do everything from scratch
--- a/config/config.mk
+++ b/config/config.mk
@@ -22,16 +22,18 @@ EXIT_ON_ERROR = set -e; # Shell loops co
 ifndef topsrcdir
 topsrcdir	= $(DEPTH)
 endif
 
 ifndef INCLUDED_AUTOCONF_MK
 include $(DEPTH)/config/autoconf.mk
 endif
 
+-include $(DEPTH)/.mozconfig.mk
+
 space = $(NULL) $(NULL)
 
 # Include defs.mk files that can be found in $(srcdir)/$(DEPTH),
 # $(srcdir)/$(DEPTH-1), $(srcdir)/$(DEPTH-2), etc., and $(srcdir)
 # where $(DEPTH-1) is one level less of depth, $(DEPTH-2), two, etc.
 # i.e. for DEPTH=../../.., DEPTH-1 is ../.. and DEPTH-2 is ..
 # These defs.mk files are used to define variables in a directory
 # and all its subdirectories, recursively.