coredata: Make a deepcopy of global state before mutating

When a compiler is initialized, it adds specific options that it
supports, but taking some global UserOption objects and adding them to
itself. When it does so, it mutates then if necessary. This means that
each compiler initialized mutates global state, this is bad. This is
worse because in our test suite we do in process testing, so these
mutations are preserved *between tests*, potentially leading to
incorrect results. The simple fix is to do the right thing, and copy the
UserOption before mutating. A deepcopy is required because the option
might be an ArrayOption, and a shallow copy is not sufficient in that
case.
pull/11288/head
Dylan Baker 2 years ago committed by Eli Schwartz
parent 42bfe53446
commit e0efc7603e
  1. 4
      mesonbuild/coredata.py

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
from . import mlog, mparser
import pickle, os, uuid
import sys
@ -886,7 +888,7 @@ class CoreData:
for key in comp.base_options:
if key in self.options:
continue
oobj = compilers.base_options[key]
oobj = copy.deepcopy(compilers.base_options[key])
if key in env.options:
oobj.set_value(env.options[key])
enabled_opts.append(key)

Loading…
Cancel
Save