gecko/mach
Gregory Szorc b07ce75bc5 Bug 957721 - Switch mach's shebang to look for python2.7; r=glandium
OpenBSD doesn't have "python" on $PATH by default. "python" may also
come from a non-2.7 Python. Switching the shebang will help ensure the
user invokes mach with Python 2.7.

There is a risk this may break mach for some people. If the masses
complain, we may roll back.

--HG--
extra : rebase_source : e05b707779bc80e9f9c9f30ba8cd70aa6aa9847f
extra : amend_source : 418ecc9e4c289e7dd8c4423e701ebc9574ecae45
2014-01-08 11:19:21 -08:00

56 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python2.7
# 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/.
from __future__ import print_function, unicode_literals
import os
import sys
def ancestors(path):
while path:
yield path
(path, child) = os.path.split(path)
if child == "":
break
def load_mach(topsrcdir):
sys.path[0:0] = [os.path.join(topsrcdir, "build")]
import mach_bootstrap
return mach_bootstrap.bootstrap(topsrcdir)
def main(args):
# Check whether the current directory is within a mach src or obj dir.
for dir_path in ancestors(os.getcwd()):
# If we find a "mozinfo.json" file, we are in the objdir.
mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
if os.path.isfile(mozinfo_path):
import json
info = json.load(open(mozinfo_path))
if 'mozconfig' in info and 'MOZCONFIG' not in os.environ:
# If the MOZCONFIG environment variable is not already set, set it
# to the value from mozinfo.json. This will tell the build system
# to look for a config file at the path in $MOZCONFIG rather than
# its default locations.
#
# Note: subprocess requires native strings in os.environ on Windows
os.environ[b'MOZCONFIG'] = str(info['mozconfig'])
if 'topsrcdir' in info:
# Continue searching for mach_bootstrap in the source directory.
dir_path = info['topsrcdir']
# If we find the mach bootstrap module, we are in the srcdir.
mach_path = os.path.join(dir_path, 'build/mach_bootstrap.py')
if os.path.isfile(mach_path):
mach = load_mach(dir_path)
sys.exit(mach.run(args[1:]))
print('Could not run mach: No mach source directory found.')
sys.exit(1)
if __name__ == '__main__':
main(sys.argv)