Bug 1257958 - Add a template to construct an environment-set option that sets the corresponding variable. r=glandium draft
authorChris Manchester <cmanchester@mozilla.com>
Fri, 22 Apr 2016 12:43:53 -0700
changeset 355509 cf162cd7e21061d66db0e5e701c700fcb0547b0c
parent 355401 fc15477ce628599519cb0055f52cc195d640dc94
child 355510 83dc8cee4b42a8488461200d05e5a5d80a9c9af1
push id16313
push usercmanchester@mozilla.com
push dateFri, 22 Apr 2016 19:48:11 +0000
reviewersglandium
bugs1257958
milestone48.0a1
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 = []