$OpenBSD$ index 29ec13f..045a335 100755 --- mach.orig Fri Feb 20 15:40:37 2015 +++ mach Fri Feb 20 15:40:37 2015 @@ -1,8 +1,14 @@ -#!/usr/bin/env python +#!/bin/sh # 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/. +# The beginning of this script is both valid shell and valid python, +# such that the script starts with the shell and is reexecuted with +# the right python. +'''which' python2.7 > /dev/null && exec python2.7 "$0" "$@" || exec python "$0" "$@" +''' + from __future__ import print_function, unicode_literals import os @@ -20,6 +26,15 @@ def load_mach(topsrcdir): import mach_bootstrap return mach_bootstrap.bootstrap(topsrcdir) + +def check_and_run_mach(dir_path, args): + # 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)) + + def main(args): # Check whether the current directory is within a mach src or obj dir. for dir_path in ancestors(os.getcwd()): @@ -41,15 +56,15 @@ def main(args): # 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:])) + check_and_run_mach(dir_path, args) + + # If we didn't find a source path by scanning for a mozinfo.json, check + # whether the directory containing this script is a source directory. + check_and_run_mach(os.path.dirname(__file__), args) print('Could not run mach: No mach source directory found.') sys.exit(1) if __name__ == '__main__': - main(sys.argv) + main(sys.argv[1:])