# 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/.
import mozpack.path as mozpath from buildconfig import topobjdir, topsrcdir from mach.logging import LoggingManager from mozfile.mozfile import NamedTemporaryFile from mozunit import main from six import StringIO
from mozbuild.backend.configenvironment import ConfigEnvironment from mozbuild.base import (
BadEnvironmentException,
MachCommandBase,
MozbuildObject,
PathArgument,
) from mozbuild.test.common import prepare_tmp_topsrcdir
def test_objdir_trailing_slash(self): """Trailing slashes in topobjdir should be removed."""
base = self.get_base()
with NamedTemporaryFile(mode="wt") as mozconfig:
mozconfig.write("mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/foo/")
mozconfig.flush()
os.environ["MOZCONFIG"] = mozconfig.name
def test_objdir_config_status(self): """Ensure @CONFIG_GUESS@ is handled when loading mozconfig."""
base = self.get_base()
guess = base.resolve_config_guess()
# There may be symlinks involved, so we use real paths to ensure # path consistency.
d = os.path.realpath(tempfile.mkdtemp()) try:
mozconfig = os.path.join(d, "mozconfig") with open(mozconfig, "wt") as fh:
fh.write("mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/foo/@CONFIG_GUESS@")
print("Wrote mozconfig %s" % mozconfig)
def test_relative_objdir(self): """Relative defined objdirs are loaded properly."""
d = os.path.realpath(tempfile.mkdtemp()) try:
mozconfig = os.path.join(d, "mozconfig") with open(mozconfig, "wt") as fh:
fh.write("mk_add_options MOZ_OBJDIR=./objdir")
@unittest.skipIf( not hasattr(os, "symlink") or os.name == "nt", "symlinks not available."
) def test_symlink_objdir(self): """Objdir that is a symlink is loaded properly."""
d = os.path.realpath(tempfile.mkdtemp()) try:
topobjdir_real = os.path.join(d, "objdir")
topobjdir_link = os.path.join(d, "objlink")
def test_objdir_is_srcdir_rejected(self): """Ensure the srcdir configurations are rejected."""
d = os.path.realpath(tempfile.mkdtemp())
try: # The easiest way to do this is to create a mozinfo.json with data # that will never happen.
mozinfo = os.path.join(d, "mozinfo.json") with open(mozinfo, "wt") as fh:
json.dump({"topsrcdir": d}, fh)
os.chdir(d)
with self.assertRaises(BadEnvironmentException):
MozbuildObject.from_environment(detect_virtualenv_mozinfo=False)
finally:
os.chdir(self._old_cwd)
shutil.rmtree(d)
def test_objdir_mismatch(self): """Ensure MachCommandBase throwing on objdir mismatch."""
d = os.path.realpath(tempfile.mkdtemp())
p = base.get_binary_path("foobar", validate_exists=False) if platform.startswith("win32"):
self.assertTrue(p.endswith("foobar.exe")) else:
self.assertTrue(p.endswith("foobar"))
class TestPathArgument(unittest.TestCase): def test_path_argument(self): # Absolute path
p = PathArgument("/obj/foo", "/src", "/obj", "/src")
self.assertEqual(p.relpath(), "foo")
self.assertEqual(p.srcdir_path(), "/src/foo")
self.assertEqual(p.objdir_path(), "/obj/foo")
# Relative path within srcdir
p = PathArgument("foo", "/src", "/obj", "/src")
self.assertEqual(p.relpath(), "foo")
self.assertEqual(p.srcdir_path(), "/src/foo")
self.assertEqual(p.objdir_path(), "/obj/foo")
# Relative path within subdirectory
p = PathArgument("bar", "/src", "/obj", "/src/foo")
self.assertEqual(p.relpath(), "foo/bar")
self.assertEqual(p.srcdir_path(), "/src/foo/bar")
self.assertEqual(p.objdir_path(), "/obj/foo/bar")
# Relative path within objdir
p = PathArgument("foo", "/src", "/obj", "/obj")
self.assertEqual(p.relpath(), "foo")
self.assertEqual(p.srcdir_path(), "/src/foo")
self.assertEqual(p.objdir_path(), "/obj/foo")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.