Bug 1411081 - Move --enable-optimize/MOZ_OPTIMIZE to moz.configure; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Tue, 24 Oct 2017 12:47:37 -0700
changeset 685628 5711b5c7abdb48bb14f03fc46fe52d8825ff63be
parent 685627 e31ae80a01b120c7106bd3e2dc517010cb553bca
child 685629 88a3dee5f1792dd4aa020c39970ae7ca26609031
push id86007
push usergszorc@mozilla.com
push dateTue, 24 Oct 2017 23:50:58 +0000
reviewersglandium
bugs1411081
milestone58.0a1
Bug 1411081 - Move --enable-optimize/MOZ_OPTIMIZE to moz.configure; r?glandium The Rust optimization logic is tied to --enable-optimize/MOZ_OPTIMIZE and --enable-debug/MOZ_DEBUG. In order to more easily implement more customization, let's move --enable-optimize/MOZ_OPTIMIZE to moz.configure so its value can be consulted there. The logic here is a bit wonky. The option behaves like a boolean flag with an optional value. We convert this option to a namespace with a numeric level and string of compiler flags. The compiler flags string is passed to old-configure where it is used to populate MOZ_OPTIMIZE_FLAGS. We stop short of moving all references to MOZ_OPTIMIZE_FLAGS to moz.configure because there are random references throughout old-configure and I don't want to scope bloat. I verified that we don't use MOZ_OPTIMIZE_FLAGS for anything meaningful before we replace its old-configure derived value with the value from moz.configure. There is obviously a bunch of improvement that remains. Again, my immediate goal is unblocking some Rust optimization work, which doesn't require the scope bloat. MozReview-Commit-ID: 6iNDu2HwLGr
build/moz.configure/old.configure
js/src/old-configure.in
moz.configure
old-configure.in
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -196,17 +196,16 @@ def old_configure_options(*options):
     '--enable-memory-sanitizer',
     '--enable-mobile-optimize',
     '--enable-necko-wifi',
     '--enable-negotiateauth',
     '--enable-nfc',
     '--enable-nspr-build',
     '--enable-official-branding',
     '--enable-oom-breakpoint',
-    '--enable-optimize',
     '--enable-parental-controls',
     '--enable-pie',
     '--enable-posix-nspr-emulation',
     '--enable-pref-extensions',
     '--enable-pulseaudio',
     '--enable-raw',
     '--enable-readline',
     '--enable-reflow-perf',
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -1432,28 +1432,21 @@ MOZ_ARG_HEADER(Debugging and Optimizatio
 
 dnl ========================================================
 dnl = Enable code optimization. ON by default.
 dnl ========================================================
 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
 	MOZ_OPTIMIZE_FLAGS="-O"
 fi
 
-MOZ_ARG_ENABLE_STRING(optimize,
-[  --disable-optimize      Disable compiler optimization
-  --enable-optimize=[OPT] Specify compiler optimization flags [OPT=-O]],
-[ if test "$enableval" != "no"; then
-    MOZ_OPTIMIZE=1
-    if test -n "$enableval" -a "$enableval" != "yes"; then
-        MOZ_OPTIMIZE_FLAGS=`echo "$enableval" | sed -e 's|\\\ | |g'`
-        MOZ_OPTIMIZE=2
-    fi
-else
-    MOZ_OPTIMIZE=
-fi ], MOZ_OPTIMIZE=1)
+# Use value from moz.configure if one is defined. Else use our computed
+# value.
+if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
+    MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
+fi
 
 MOZ_SET_FRAMEPTR_FLAGS
 
 if test "$COMPILE_ENVIRONMENT"; then
 if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_CHECKING([for valid optimization flags])
     _SAVE_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
@@ -1464,17 +1457,16 @@ if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_RESULT([$_results])
     if test "$_results" = "no"; then
         AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS])
     fi
     CFLAGS=$_SAVE_CFLAGS
 fi
 fi # COMPILE_ENVIRONMENT
 
-AC_SUBST(MOZ_OPTIMIZE)
 AC_SUBST(MOZ_FRAMEPTR_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_LDFLAGS)
 AC_SUBST(MOZ_PGO_OPTIMIZE_FLAGS)
 
 dnl ========================================================
 dnl = Trace logging. Enabled by default in DEBUG builds.
 dnl ========================================================
--- a/moz.configure
+++ b/moz.configure
@@ -91,16 +91,57 @@ def linux_gtest_defines(target, enable_t
 
 set_define('GTEST_OS_LINUX_ANDROID',
            linux_gtest_defines.os_linux_android)
 set_define('GTEST_USE_OWN_TR1_TUPLE',
            linux_gtest_defines.use_own_tr1_tuple)
 set_define('GTEST_HAS_CLONE',
            linux_gtest_defines.has_clone)
 
+# Code optimization is enabled by default.
+# unset: no optimization
+# 1: basic optimization
+# 2: more optimization
+js_option('--enable-optimize',
+          nargs='?',
+          default='1',
+          help='Compiler optimization level (1 or 2) or flags')
+
+@depends('--enable-optimize')
+@imports('os')
+def moz_optimize(option):
+    # The option can be a PositiveOptionValue, NegativeOptionValue, or
+    # a regular Option. This makes value comparisons somewhat complicated.
+
+    flags = None
+
+    # Explicit value specified.
+    if len(option):
+        if option[0] in ('1', '2'):
+            val = option[0]
+        elif option[0] == '0':
+            val = None
+        else:
+            val = '2'
+            flags = option[0]
+    elif option:
+        val = '1'
+    else:
+        val = None
+
+    return namespace(
+        optimize=val,
+        flags=flags,
+    )
+
+set_config('MOZ_OPTIMIZE', moz_optimize.optimize)
+add_old_configure_assignment('MOZ_OPTIMIZE', moz_optimize.optimize)
+add_old_configure_assignment('MOZ_CONFIGURE_OPTIMIZE_FLAGS', moz_optimize.flags)
+
+
 js_option('--enable-debug',
           nargs='?',
           help='Enable building with developer debug info '
                '(using the given compiler flags).')
 
 add_old_configure_assignment('MOZ_DEBUG',
                              depends('--enable-debug')(lambda v: bool(v)))
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -3708,28 +3708,21 @@ fi
 
 dnl ========================================================
 dnl = Enable code optimization. ON by default.
 dnl ========================================================
 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
     MOZ_OPTIMIZE_FLAGS="-O"
 fi
 
-MOZ_ARG_ENABLE_STRING(optimize,
-[  --disable-optimize      Disable compiler optimization
-  --enable-optimize=[OPT] Specify compiler optimization flags [OPT=-O]],
-[ if test "$enableval" != "no"; then
-    MOZ_OPTIMIZE=1
-    if test -n "$enableval" -a "$enableval" != "yes"; then
-        MOZ_OPTIMIZE_FLAGS=`echo "$enableval" | sed -e 's|\\\ | |g'`
-        MOZ_OPTIMIZE=2
-    fi
-else
-    MOZ_OPTIMIZE=
-fi ], MOZ_OPTIMIZE=1)
+# Use value from moz.configure if one is defined. Else use our computed
+# value.
+if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
+    MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
+fi
 
 MOZ_SET_FRAMEPTR_FLAGS
 
 if test "$COMPILE_ENVIRONMENT"; then
 if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_CHECKING([for valid C compiler optimization flags])
     _SAVE_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
@@ -3740,17 +3733,16 @@ if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_RESULT([$_results])
     if test "$_results" = "no"; then
         AC_MSG_ERROR([These compiler flags for C are invalid: $MOZ_OPTIMIZE_FLAGS])
     fi
     CFLAGS=$_SAVE_CFLAGS
 fi
 fi # COMPILE_ENVIRONMENT
 
-AC_SUBST(MOZ_OPTIMIZE)
 AC_SUBST(MOZ_FRAMEPTR_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_LDFLAGS)
 AC_SUBST(MOZ_PGO_OPTIMIZE_FLAGS)
 
 dnl ========================================================
 dnl = Disable treating compiler warnings as errors
 dnl ========================================================