Bug 1031180 - Fallback to checking whether the directory mach lives in contains mach_bootstrap.py. r=gps

This commit is contained in:
Mike Hommey 2014-07-03 07:15:31 +09:00
parent 4ba5a79732
commit 9cb7180400

21
mach
View File

@ -26,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()):
@ -47,11 +56,11 @@ 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)
@ -105,4 +114,4 @@ if __name__ == '__main__':
orig_command_line = forking.get_command_line
forking.get_command_line = my_get_command_line
main(sys.argv)
main(sys.argv[1:])