Bug 1181040 - Set ${var}_IS_SET variables for mk_add_options-defined variables
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 06 Aug 2015 16:24:54 +0900
changeset 523130 ce78ec95dca66532696de5da04c8414298712e81
parent 523049 21829aaf72e1ae094c6de7a35f3dcfaeb85ce5b8
child 523131 e7617dcf3a23e7175e870ccf36c335604c21f402
push id82012
push usermh@glandium.org
push dateThu, 06 Aug 2015 07:34:33 +0000
treeherdertry@13556a279df9 [default view] [failures only]
bugs1181040
milestone42.0a1
Bug 1181040 - Set ${var}_IS_SET variables for mk_add_options-defined variables It is useful to be able, during mozconfig execution, to do tests depending on what was previously added with mk_add_options. Specifically, there is a need to do this for MOZ_PGO because developers pushing to try may add it to mozconfig.common.override. While, ideally, it would be nice if we just defined the variable itself in the mozconfig execution environment, that is a tedious task, having to jump through hoops with eval, and handle all cases of variable assigment properly. The hacky alternative is to just treat MOZ_PGO specially, but meh. So instead, we set a ${var}_IS_SET variable to 1, indicating that a mk_add_options defined ${var} to some value.
python/mozbuild/mozbuild/mozconfig_loader
python/mozbuild/mozbuild/test/test_mozconfig.py
--- a/python/mozbuild/mozbuild/mozconfig_loader
+++ b/python/mozbuild/mozbuild/mozconfig_loader
@@ -31,20 +31,33 @@ ac_add_app_options() {
   shift
   echo "------BEGIN_AC_APP_OPTION"
   echo $app
   echo "$*"
   echo "------END_AC_APP_OPTION"
 }
 
 mk_add_options() {
-  local opt
+  local opt name op value
   for opt; do
     echo "------BEGIN_MK_OPTION"
     echo $opt
+    # Remove any leading "export"
+    opt=${opt#export}
+    case "$opt" in
+    *\?=*) op="?=" ;;
+    *:=*) op=":=" ;;
+    *+=*) op="+=" ;;
+    *=*) op="=" ;;
+    esac
+    # Remove the operator and the value that follows
+    name=${opt%%${op}*}
+    # Note: $(echo ${name}) strips the variable from any leading and trailing
+    # whitespaces.
+    eval "$(echo ${name})_IS_SET=1"
     echo "------END_MK_OPTION"
   done
 }
 
 echo "------BEGIN_ENV_BEFORE_SOURCE"
 env
 echo "------END_ENV_BEFORE_SOURCE"
 
--- a/python/mozbuild/mozbuild/test/test_mozconfig.py
+++ b/python/mozbuild/mozbuild/test/test_mozconfig.py
@@ -314,16 +314,20 @@ class TestMozconfigLoader(unittest.TestC
             mozconfig.write('mk_add_options BIZ=1\n')
             mozconfig.flush()
 
             result = self.get_loader().read_mozconfig(mozconfig.name)
             self.assertEqual(result['topobjdir'], '/foo/bar')
             self.assertEqual(result['make_flags'], ['-j8', '-s'])
             self.assertEqual(result['make_extra'], ['FOO=BAR BAZ', 'BIZ=1'])
 
+            vars = result['vars']['added']
+            for var in ('MOZ_OBJDIR', 'MOZ_MAKE_FLAGS', 'FOO', 'BIZ'):
+                self.assertEqual(vars.get('%s_IS_SET' % var), '1')
+
     def test_read_empty_mozconfig_objdir_environ(self):
         os.environ[b'MOZ_OBJDIR'] = b'obj-firefox'
         with NamedTemporaryFile(mode='w') as mozconfig:
             result = self.get_loader().read_mozconfig(mozconfig.name)
             self.assertEqual(result['topobjdir'], 'obj-firefox')
 
     def test_read_capture_mk_options_objdir_environ(self):
         """Ensures mk_add_options calls are captured and override the environ."""