Bug 911634 - Create a .mozconfig.mk in the objdir when starting a build, and include it from config.mk. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 05 Sep 2013 09:01:44 +0900
changeset 145637 34ca46861c2839621576b4f24231458504303c77
parent 145636 88f62538d582fd57e6e478b0575c96389d5de7f6
child 145638 c2ef6df8c8d69398d99fafa85d88e6a354fb3ea0
push id744
push useremorley@mozilla.com
push dateThu, 05 Sep 2013 13:54:13 +0000
treeherderb2g-inbound@10d28291bf82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs911634
milestone26.0a1
Bug 911634 - Create a .mozconfig.mk in the objdir when starting a build, and include it from config.mk. r=gps
Makefile.in
build/autoconf/mozconfig2client-mk
client.mk
config/config.mk
js/src/config/config.mk
--- a/Makefile.in
+++ b/Makefile.in
@@ -30,17 +30,17 @@ endif
 
 include $(topsrcdir)/config/config.mk
 
 GARBAGE_DIRS += dist _javagen _profile _tests staticlib
 DIST_GARBAGE = config.cache config.log config.status* config-defs.h \
    config/autoconf.mk \
    mozilla-config.h \
    netwerk/necko-config.h xpcom/xpcom-config.h xpcom/xpcom-private.h \
-   $(topsrcdir)/.mozconfig.mk $(topsrcdir)/.mozconfig.out
+   .mozconfig.mk
 
 ifndef MOZ_PROFILE_USE
 # One of the first things we do in the build is purge "unknown" files
 # from the object directory. This serves two purposes:
 #
 #   1) Remove files from a previous build no longer accounted for in
 #      this build configuration.
 #
--- 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
@@ -109,18 +109,30 @@ MOZCONFIG_LOADER := build/autoconf/mozco
 
 define CR
 
 
 endef
 
 # 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.
-$(eval $(subst ||,$(CR),$(shell _PYMAKE=$(.PYMAKE) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) 2> $(TOPSRCDIR)/.mozconfig.out | sed 's/$$/||/')))
+# 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))
 
 ifdef AUTOCLOBBER
 export AUTOCLOBBER=1
 endif
 
 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
 ifeq (,$(findstring -j,$(MOZ_MAKE_FLAGS)))
   cores=$(shell $(PYTHON) -c 'import multiprocessing; print(multiprocessing.cpu_count())')
@@ -170,23 +182,45 @@ OBJDIR_TARGETS = install export libs cle
 # The default rule is build
 build::
 	$(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild)
 
 # 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.
+$(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR))
+	( $(foreach line,$(filter export||%,$(MOZCONFIG_OUT_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
+
 # Print out any options loaded from mozconfig.
 all realbuild 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
 
 # helper target for mobile
--- 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.
--- a/js/src/config/config.mk
+++ b/js/src/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.