Bug 656049 - teach comm-central client.mk to invoke client.py r=Standard8,Callek
authorPhilippe M. Chiasson <gozer@mozilla.com>
Thu, 07 Jul 2011 13:04:40 -0400
changeset 7890 1fe64d255b2b0c733ad9610ba43b4ed1b1d20585
parent 7889 31cb62010d42c2338eebe3d894382d122333853f
child 7891 9b9d32bb5fd2b497cc3351a3cf6ef0f849b2cec9
push id158
push userbugzilla@standard8.plus.com
push dateTue, 27 Sep 2011 19:18:14 +0000
treeherdercomm-esr52@bafeec1cd4a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, Callek
bugs656049
Bug 656049 - teach comm-central client.mk to invoke client.py r=Standard8,Callek
build/print_mk_add_options.sh
build/run_client.py
client.mk
--- a/build/print_mk_add_options.sh
+++ b/build/print_mk_add_options.sh
@@ -1,14 +1,18 @@
 #!/bin/sh
 
 ac_add_options() {
   return
 }
 
+ac_add_app_options() {
+  return
+}
+
 mk_add_options() {
   echo "mk_add_options:" "$@"
 }
 
 MOZCONFIG=${MOZCONFIG:-./.mozconfig}
 topsrcdir=${topsrcdir:-$PWD}
 
 source $MOZCONFIG
--- a/build/run_client.py
+++ b/build/run_client.py
@@ -1,47 +1,71 @@
 #!/usr/bin/env python
 
 import sys
 import os.path
 import re
 from subprocess import Popen, PIPE
+from optparse import OptionParser, OptionValueError
 import shlex
 
-topsrcdir = sys.argv[1]
+o = OptionParser(usage="%prog [options] topsrcdir")
+
+o.add_option("--make", "-m", dest="make",
+              action="store", default="make",
+              help="Command to invoke make")
+
+o.add_option("--force", "-f", dest="run",
+             action="store_true", default=False,
+             help="Run client.py no matter what .mozconfig says")
 
-run = False
+try:
+    (options, args) = o.parse_args()
+except ValueError:
+    o.print_help()
+    sys.exit(2)
 
-if len(sys.argv) >= 3:
-    run = True
+if len(args) != 1:
+    o.print_help()
+    sys.exit(2)
+
+topsrcdir = args[0]
 
 client_py_args = []
 
 options_re = re.compile('^mk_add_options:\s+CLIENT_PY_ARGS\s*=\s*(.*)$')
 always_run_re = re.compile('^mk_add_options:\s+ALWAYS_RUN_CLIENT_PY\s*=\s*(.*)$')
 
-process = Popen(['build/print_mk_add_options.sh'], stdout=PIPE, stderr=sys.stderr)
+process = Popen([options.make,'-f', 'client.mk', 'print_mk_add_options', 'NO_CLIENT_PY=1'], stdout=PIPE, stderr=sys.stderr)
 output, unused_err = process.communicate()
 
 for line in output.splitlines():
     found_opt = options_re.match(line)
     if found_opt:
         client_py_args = found_opt.group(1)
 
     found_always = always_run_re.match(line)
     if found_always:
         val = found_always.group(1)
         if val != "0":
-            run = True
+            options.run = True
 
-if run:
+if options.run:
     if not client_py_args:
         print >> sys.stderr, "Can't run client.py without some CLIENT_PY_ARGS in mozconfig"
         sys.exit(1)
-    cmd = [sys.executable, 'client.py' ] + shlex.split(client_py_args)
+
+    client_py_args = shlex.split(client_py_args)
+
+    #Turn off tinderboxprint when we clone from scratch, we'll shortly afterwards update
+    mozilla_dir = os.path.join(topsrcdir, 'mozilla')
+    if not os.path.exists(mozilla_dir):
+        client_py_args = [arg for arg in client_py_args if arg != '--tinderbox-print']
+
+    cmd = [sys.executable, 'client.py' ] +  client_py_args
     print >> sys.stderr, "Running: %s" % cmd
     # Run the command and redirect output to stderr so make will display it
     p = Popen(cmd,
         stdout=sys.stderr,
         stderr=sys.stderr,
     )
     p.wait()
     print >> sys.stderr, "%s returned %s" % (cmd, p.returncode)
--- a/client.mk
+++ b/client.mk
@@ -131,31 +131,20 @@ endif
 # Load mozconfig Options
 
 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
 
 MOZCONFIG_LOADER := mozilla/build/autoconf/mozconfig2client-mk
 MOZCONFIG_FINDER := mozilla/build/autoconf/mozconfig-find
 MOZCONFIG_MODULES := mozilla/build/unix/uniq.pl
 
-# We need to give client.py an early chance to run, since we don't necessarely
-# have a mozilla/ checkout yet
-run_for_side_effects := \
-  @if test ! -f .client.run; then \
-    $(shell $(PYTHON) $(TOPSRCDIR)/build/run_client.py $(TOPSRCDIR) > .client.out ); \
-    touch .client.run \
-  else \
-    rm -f .client.run; \
-    true; \
-  fi
-
 run_for_side_effects := \
   $(shell $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) $(TOPSRCDIR)/.mozconfig.mk > $(TOPSRCDIR)/.mozconfig.out)
 
-include $(TOPSRCDIR)/.mozconfig.mk
+sinclude $(TOPSRCDIR)/.mozconfig.mk
 
 ifndef MOZ_OBJDIR
   MOZ_OBJDIR = obj-$(CONFIG_GUESS)
 endif
 
 ifdef MOZ_BUILD_PROJECTS
 
 ifdef MOZ_CURRENT_PROJECT
@@ -180,16 +169,24 @@ CONFIGURES += $(TOPSRCDIR)/mozilla/confi
 CONFIGURES += $(TOPSRCDIR)/mozilla/js/src/configure
 
 #######################################################################
 # Rules
 
 # The default rule is build
 build::
 
+# These targets are candidates for auto-running client.py
+ifndef NO_CLIENT_PY
+$(TOPSRCDIR)/.mozconfig.mk:: run_client_py
+	$(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) $(TOPSRCDIR)/.mozconfig.mk > $(TOPSRCDIR)/.mozconfig.out
+build 	  		:: run_client_py
+configure 		:: run_client_py
+endif
+
 # 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
 
@@ -323,17 +320,17 @@ endif
 	@echo cd $(OBJDIR);
 	@echo $(CONFIGURE) $(CONFIGURE_ARGS)
 	@cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
 	  || ( echo "*** Fix above errors and then restart with\
                \"$(MAKE) -f client.mk build\"" && exit 1 )
 	@touch $(OBJDIR)/Makefile
 
 $(OBJDIR)/Makefile $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
-	@$(MAKE) -f $(TOPSRCDIR)/client.mk configure
+	@$(MAKE) -f $(TOPSRCDIR)/client.mk configure NO_CLIENT_PY=1
 
 ifneq (,$(CONFIG_STATUS))
 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
 	cd $(OBJDIR); \
 	  CONFIG_FILES=config/autoconf.mk ./config.status
 endif
 
 
@@ -411,20 +408,25 @@ cleansrcdir:
 	  echo "Removing object files from srcdir..."; \
 	  rm -fr `find . -type d \( -name .deps -print -o -name CVS \
 	          -o -exec test ! -d {}/CVS \; \) -prune \
 	          -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
 	   build/autoconf/clean-config.sh; \
 	fi;
 
 checkout co:
-	@$(PYTHON) $(TOPSRCDIR)/build/run_client.py $(TOPSRCDIR) force
+	@$(PYTHON) $(TOPSRCDIR)/build/run_client.py --force --make $(MAKE) $(TOPSRCDIR)
 
+run_client_py:
+	@$(PYTHON) $(TOPSRCDIR)/build/run_client.py --make $(MAKE) $(TOPSRCDIR)
+
+print_mk_add_options:
+	@$(TOPSRCDIR)/build/print_mk_add_options.sh
 
 echo-variable-%:
 	@echo $($*)
 
 # This makefile doesn't support parallel execution. It does pass
 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
 # in parallel.
 .NOTPARALLEL:
 
-.PHONY: checkout co real_checkout depend build profiledbuild maybe_clobber_profiledbuild export libs alldep install clean realclean distclean cleansrcdir pull_all build_all clobber clobber_all pull_and_build_all everything configure preflight_all preflight postflight postflight_all
+.PHONY: run_client_py print_mk_add_options checkout co real_checkout depend build profiledbuild maybe_clobber_profiledbuild export libs alldep install clean realclean distclean cleansrcdir pull_all build_all clobber clobber_all pull_and_build_all everything configure preflight_all preflight postflight postflight_all