Commit 720d497c authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1575959 - Restore the mozbuild.util.encode function. a=glandium

Older config.status laying around in old trees are read by mach whenever
it runs, including when running mach clobber. Those files still try to
include mozbuild.util.encode, which is not here anymore. So we restore
the function for now to unbreak those.

Differential Revision: https://phabricator.services.mozilla.com//D43132

--HG--
extra : histedit_source : 3eb10cc8e18cc9094887061b00705afb6e705b54
parent bbbac52a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import sys
import time

from collections import (
    Iterable,
    OrderedDict,
)
from io import (
@@ -1296,6 +1297,24 @@ def indented_repr(o, indent=4):
    return ''.join(recurse_indented_repr(o, 0))


# Please do not use this function. It's only kept for backwards compatibility
# with older config.status files that may lay around before a CLOBBER.
def encode(obj, encoding='utf-8'):
    '''Recursively encode unicode strings with the given encoding.'''
    if isinstance(obj, dict):
        return {
            encode(k, encoding): encode(v, encoding)
            for k, v in six.iteritems(obj)
        }
    if isinstance(obj, bytes):
        return obj
    if isinstance(obj, six.text_type):
        return obj.encode(encoding)
    if isinstance(obj, Iterable):
        return [encode(i, encoding) for i in obj]
    return obj


def patch_main():
    '''This is a hack to work around the fact that Windows multiprocessing needs
    to import the original main module, and assumes that it corresponds to a file