Bug 1257958 - Add a template to construct an environment-set option that sets the corresponding variable. r=glandium
authorChris Manchester <cmanchester@mozilla.com>
Fri, 22 Apr 2016 13:01:21 -0700
changeset 332463 6ef6252740a31dc8ad86e79a059a13cf4e703080
parent 332462 d6ea7c8e2449d9b34882650490383ee86b8bb164
child 332464 083f95a42cc87c8da3d9ebe3090c8c90cf036406
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1257958
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257958 - Add a template to construct an environment-set option that sets the corresponding variable. r=glandium MozReview-Commit-ID: 2ufoFdwCdDk
build/moz.configure/init.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -649,19 +649,19 @@ set_define('MOZ_BUILD_APP', build_projec
 add_old_configure_assignment('MOZ_BUILD_APP', build_project)
 
 
 # set RELEASE_BUILD and NIGHTLY_BUILD variables depending on the cycle we're in
 # The logic works like this:
 # - if we have "a1" in GRE_MILESTONE, we're building Nightly (define NIGHTLY_BUILD)
 # - otherwise, if we have "a" in GRE_MILESTONE, we're building Nightly or Aurora
 # - otherwise, we're building Release/Beta (define RELEASE_BUILD)
-@depends(check_build_environment)
+@depends(check_build_environment, '--help')
 @imports(_from='__builtin__', _import='open')
-def milestone(build_env):
+def milestone(build_env, _):
     milestone_path = os.path.join(build_env.topsrcdir,
                                   'config',
                                   'milestone.txt')
     with open(milestone_path, 'r') as fh:
         milestone = fh.read().splitlines()[-1]
 
     is_nightly = is_release = None
 
@@ -679,16 +679,49 @@ set_config('NIGHTLY_BUILD', delayed_geta
 set_define('NIGHTLY_BUILD', delayed_getattr(milestone, 'is_nightly'))
 add_old_configure_assignment('NIGHTLY_BUILD',
                              delayed_getattr(milestone, 'is_nightly'))
 set_config('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
 set_define('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
 add_old_configure_assignment('RELEASE_BUILD',
                              delayed_getattr(milestone, 'is_release'))
 
+# A template providing a shorthand for tying an environment-set option to
+# the corresponding variable in set_config, where the value of that variable
+# passed to set_config only depends on the provided value and default.
+# If required, the set_as_define and set_for_old_configure arguments
+# will additionally cause the variable to be set using set_define and
+# add_old_configure_assignment. util.configure would be an appropriate place for
+# this, but it uses add_old_configure_assignment, which is defined in this file.
+@template
+def env_flag(env=None, set_for_old_configure=False, set_as_define=False,
+             **kwargs):
+
+    if not env:
+        configure_error("An env_flag must be passed a variable name to set.")
+
+    opt = option(env=env, **kwargs)
+
+    @depends(opt.option)
+    def option_implementation(value):
+        if value:
+            if len(value):
+                return value
+            return bool(value)
+
+    set_config(env, option_implementation)
+    if set_as_define:
+        set_define(env, option_implementation)
+    if set_for_old_configure:
+        add_old_configure_assignment(env, option_implementation)
+
+# milestone.is_nightly corresponds to cases NIGHTLY_BUILD is set.
+@depends(milestone, '--help')
+def enabled_in_nightly(milestone, _):
+    return milestone.is_nightly
 
 # Set the MOZ_CONFIGURE_OPTIONS variable with all the options that
 # were passed somehow (environment, command line, mozconfig)
 @depends(mozconfig_options)
 @imports(_from='mozbuild.shellutil', _import='quote')
 @imports('__sandbox__')
 def all_configure_options(_):
     result = []