# 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 os import os.path import sys import unittest from filecmp import dircmp from shutil import copy2, rmtree from tempfile import mkdtemp from zipfile import ZipFile
import mozunit import six from six import StringIO
from mozbuild.jar import JarMaker
if sys.platform == "win32": import ctypes from ctypes import POINTER, WinError
def symlinks_supported(path): if sys.platform == "win32": # Add 1 for a trailing backslash if necessary, and 1 for the terminating # null character.
volpath = ctypes.create_string_buffer(len(path) + 2)
rv = GetVolumePathName(six.ensure_binary(path), volpath, len(volpath)) if rv == 0: raise WinError()
# Return true only if the fsname is NTFS return fsname.value == "NTFS" else: returnTrue
def _getfileinfo(path): """Return information for the given file. This only works on Windows."""
fh = CreateFile(
six.ensure_binary(path),
GENERIC_READ,
FILE_SHARE_READ, None,
OPEN_EXISTING,
0, None,
) if fh isNone: raise WinError()
info = BY_HANDLE_FILE_INFORMATION()
rv = GetFileInformationByHandle(fh, info) if rv == 0: raise WinError() return info
def is_symlink_to(dest, src): if sys.platform == "win32": # Check if both are on the same volume and have the same file ID
destinfo = _getfileinfo(dest)
srcinfo = _getfileinfo(src) return (
destinfo.dwVolumeSerialNumber == srcinfo.dwVolumeSerialNumber and destinfo.nFileIndexHigh == srcinfo.nFileIndexHigh and destinfo.nFileIndexLow == srcinfo.nFileIndexLow
) else: # Read the link and check if it is correct ifnot os.path.islink(dest): returnFalse
target = os.path.abspath(os.readlink(dest))
abssrc = os.path.abspath(src) return target == abssrc
class _TreeDiff(dircmp): """Helper to report rich results on difference between two directories."""
def test_a_simple_symlink(self): """Test a simple jar.mn with a symlink""" ifnot symlinks_supported(self.srcdir): raise unittest.SkipTest("symlinks not supported")
self._create_simple_setup()
jm = JarMaker(outputFormat="symlink")
jm.sourcedirs = [self.srcdir]
jm.topsourcedir = self.srcdir
jm.makeJar(os.path.join(self.srcdir, "jar.mn"), self.builddir) # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
srcbar = os.path.join(self.srcdir, "bar")
destfoo = os.path.join(self.builddir, "chrome", "test", "dir", "foo")
self.assertTrue(
is_symlink_to(destfoo, srcbar), "{0} is not a symlink to {1}".format(destfoo, srcbar),
)
def test_a_wildcard_symlink(self): """Test a wildcard in jar.mn with symlinks""" ifnot symlinks_supported(self.srcdir): raise unittest.SkipTest("symlinks not supported")
# test.ftl should be taken from the l10ndir, since it is present there
destpath = os.path.join(
self.builddir, "localization", "test", "app", "test.ftl"
)
srcpath = os.path.join(self.l10nbase, "app", "app", "test.ftl")
self.assertTrue(
is_symlink_to(destpath, srcpath), "{0} should be a symlink to {1}".format(destpath, srcpath),
)
# test2.ftl on the other hand, is only present in en-US dir, and should # not be linked from the build dir
destpath = os.path.join(
self.builddir, "localization", "test", "app", "test2.ftl"
)
self.assertFalse(
os.path.isfile(destpath), "test2.ftl should not be taken from en-US"
)
if __name__ == "__main__":
mozunit.main()
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
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.