summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/action/dump_env.py
blob: ec178700eb474dc449aa6aef525121d60df0e78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# We invoke a Python program to dump our environment in order to get
# native paths printed on Windows so that these paths can be incorporated
# into Python configure's environment.
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

from shellutil import quote


def environ():
    # We would use six.ensure_text but the global Python isn't guaranteed to have
    # the correct version of six installed.
    def ensure_text(s):
        if sys.version_info > (3, 0) or isinstance(s, unicode):
            # os.environ always returns string keys and values in Python 3.
            return s
        else:
            return s.decode("utf-8")

    return [(ensure_text(k), ensure_text(v)) for (k, v) in os.environ.items()]


for key, value in environ():
    print("%s=%s" % (key, quote(value)))