Bug 750436 - Add new test to xpcshell manifest. r=WhoNeedsTryAnyway
[gecko.git] / mach
blobdbbd8fca40e228590f56ffd57bb89f3c796fe0fe
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 from __future__ import print_function, unicode_literals
8 import os
9 import sys
11 def ancestors(path):
12 while path:
13 yield path
14 (path, child) = os.path.split(path)
15 if child == "":
16 break
18 def load_mach(topsrcdir):
19 sys.path[0:0] = [os.path.join(topsrcdir, "build")]
20 import mach_bootstrap
21 return mach_bootstrap.bootstrap(topsrcdir)
23 # Check whether the current directory is within a mach src or obj dir.
24 for dir_path in ancestors(os.getcwd()):
25 # If we find a "mozinfo.json" file, we are in the objdir.
26 mozinfo_path = os.path.join(dir_path, "mozinfo.json")
27 if os.path.isfile(mozinfo_path):
28 import json
29 info = json.load(open(mozinfo_path))
30 if "mozconfig" in info and "MOZCONFIG" not in os.environ:
31 # If the MOZCONFIG environment variable is not already set, set it
32 # to the value from mozinfo.json. This will tell the build system
33 # to look for a config file at the path in $MOZCONFIG rather than
34 # its default locations.
36 # Note: subprocess requires native strings in os.environ on Windows
37 os.environ[b"MOZCONFIG"] = str(info["mozconfig"])
39 if "topsrcdir" in info:
40 # Continue searching for mach_bootstrap in the source directory.
41 dir_path = info["topsrcdir"]
43 # If we find the mach bootstrap module, we are in the srcdir.
44 mach_path = os.path.join(dir_path, "build/mach_bootstrap.py")
45 if os.path.isfile(mach_path):
46 mach = load_mach(dir_path)
47 sys.exit(mach.run(sys.argv[1:]))
49 print("Could not run mach: No mach source directory found")
50 sys.exit(1)