зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1712817: Add tests for mozbuild file editing r=jewilde
Depends on D120481 Differential Revision: https://phabricator.services.mozilla.com/D121379
This commit is contained in:
Родитель
e603a5f57c
Коммит
ba6db969f0
|
@ -13,7 +13,7 @@ import unittest
|
|||
from mozunit import main
|
||||
import mozbuild.vendor.rewrite_mozbuild as mu
|
||||
|
||||
SAMPLE_MOZBUILD = """
|
||||
SAMPLE_PIXMAN_MOZBUILD = """
|
||||
if CONFIG['OS_ARCH'] != 'Darwin' and CONFIG['CC_TYPE'] in ('clang', 'gcc'):
|
||||
if CONFIG['HAVE_ARM_NEON']:
|
||||
SOURCES += [
|
||||
|
@ -42,6 +42,45 @@ if use_sse2:
|
|||
SOURCES['pixman-sse2.c'].flags += ['-Winline']
|
||||
"""
|
||||
|
||||
SAMPLE_DAV1D_MOZBUILD = """
|
||||
SOURCES += [
|
||||
'../../third_party/dav1d/src/cdf.c',
|
||||
'../../third_party/dav1d/src/cpu.c',
|
||||
]
|
||||
EXPORTS = [
|
||||
'../../third_party/dav1d/src/header1.h',
|
||||
'../../third_party/dav1d/src/header2.h',
|
||||
]
|
||||
"""
|
||||
|
||||
|
||||
SAMPLE_JPEGXL_MOZBUILD = """
|
||||
SOURCES += [
|
||||
"/third_party/jpeg-xl/lib/jxl/ac_strategy.cc",
|
||||
"/third_party/jpeg-xl/lib/jxl/alpha.cc",
|
||||
"/third_party/jpeg-xl/lib/jxl/ans_common.cc",
|
||||
"/third_party/jpeg-xl/lib/jxl/aux_out.cc",
|
||||
]
|
||||
EXPORTS.bob.carol = [
|
||||
"/third_party/jpeg-xl/lib/jxl/header1.hpp",
|
||||
"/third_party/jpeg-xl/lib/jxl/header2.h",
|
||||
]
|
||||
"""
|
||||
|
||||
|
||||
def _make_mozbuild_directory_structure(mozbuild_path, contents):
|
||||
d = tempfile.TemporaryDirectory()
|
||||
os.makedirs(os.path.join(d.name, os.path.split(mozbuild_path)[0]))
|
||||
|
||||
arcconfig = open(os.path.join(d.name, ".arcconfig"), mode="w")
|
||||
arcconfig.close()
|
||||
|
||||
mozbuild = open(os.path.join(d.name, mozbuild_path), mode="w")
|
||||
mozbuild.write(contents)
|
||||
mozbuild.close()
|
||||
|
||||
return d
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
def test_normalize_filename(self):
|
||||
|
@ -56,10 +95,7 @@ class TestUtils(unittest.TestCase):
|
|||
|
||||
def test_unnormalize_filename(self):
|
||||
test_vectors = [
|
||||
(
|
||||
"foo/bar/moz.build",
|
||||
"/",
|
||||
),
|
||||
("foo/bar/moz.build", "/"),
|
||||
("foo/bar/moz.build", "a.c"),
|
||||
("foo/bar/moz.build", "baz/a.c"),
|
||||
("foo/bar/moz.build", "/a.c"),
|
||||
|
@ -95,9 +131,7 @@ class TestUtils(unittest.TestCase):
|
|||
"> SOURCES": ["root/dir/main.c"],
|
||||
"> if conditional > SOURCES": ["root/dir/asm/blah.S"],
|
||||
},
|
||||
{
|
||||
"> SOURCES": ["root/dir/main.c"],
|
||||
},
|
||||
{"> SOURCES": ["root/dir/main.c"]},
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -140,7 +174,7 @@ class TestUtils(unittest.TestCase):
|
|||
"> if ASM > SOURCES": ["foo/asm_x86.c"],
|
||||
},
|
||||
"> if ASM > SOURCES",
|
||||
),
|
||||
)
|
||||
]
|
||||
for vector in test_vectors:
|
||||
normalized_filename, source_assignments, expected = vector
|
||||
|
@ -149,24 +183,184 @@ class TestUtils(unittest.TestCase):
|
|||
)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_mozbuild_removing(self):
|
||||
test_vectors = [
|
||||
(
|
||||
"media/dav1d/moz.build",
|
||||
SAMPLE_DAV1D_MOZBUILD,
|
||||
"third_party/dav1d/src/cdf.c",
|
||||
"media/dav1d/",
|
||||
"third-party/dav1d/",
|
||||
" '../../third_party/dav1d/src/cdf.c',\n",
|
||||
),
|
||||
(
|
||||
"media/dav1d/moz.build",
|
||||
SAMPLE_DAV1D_MOZBUILD,
|
||||
"third_party/dav1d/src/header1.h",
|
||||
"media/dav1d/",
|
||||
"third-party/dav1d/",
|
||||
" '../../third_party/dav1d/src/header1.h',\n",
|
||||
),
|
||||
(
|
||||
"media/jxl/moz.build",
|
||||
SAMPLE_JPEGXL_MOZBUILD,
|
||||
"third_party/jpeg-xl/lib/jxl/alpha.cc",
|
||||
"media/jxl/",
|
||||
"third-party/jpeg-xl/",
|
||||
' "/third_party/jpeg-xl/lib/jxl/alpha.cc",\n',
|
||||
),
|
||||
(
|
||||
"media/jxl/moz.build",
|
||||
SAMPLE_JPEGXL_MOZBUILD,
|
||||
"third_party/jpeg-xl/lib/jxl/header1.hpp",
|
||||
"media/jxl/",
|
||||
"third-party/jpeg-xl/",
|
||||
' "/third_party/jpeg-xl/lib/jxl/header1.hpp",\n',
|
||||
),
|
||||
]
|
||||
|
||||
for vector in test_vectors:
|
||||
(
|
||||
mozbuild_path,
|
||||
mozbuild_contents,
|
||||
file_to_remove,
|
||||
moz_yaml_dir,
|
||||
vendoring_dir,
|
||||
replace_str,
|
||||
) = vector
|
||||
|
||||
startdir = os.getcwd()
|
||||
try:
|
||||
mozbuild_dir = _make_mozbuild_directory_structure(
|
||||
mozbuild_path, mozbuild_contents
|
||||
)
|
||||
os.chdir(mozbuild_dir.name)
|
||||
|
||||
mu.remove_file_from_moz_build_file(
|
||||
file_to_remove,
|
||||
moz_yaml_dir=moz_yaml_dir,
|
||||
vendoring_dir=vendoring_dir,
|
||||
)
|
||||
|
||||
with open(os.path.join(mozbuild_dir.name, mozbuild_path)) as file:
|
||||
contents = file.read()
|
||||
|
||||
expected_output = mozbuild_contents.replace(replace_str, "")
|
||||
if contents != expected_output:
|
||||
print("File to remove:", file_to_remove)
|
||||
print("Contents:")
|
||||
print("-------------------")
|
||||
print(contents)
|
||||
print("-------------------")
|
||||
print("Expected:")
|
||||
print("-------------------")
|
||||
print(expected_output)
|
||||
print("-------------------")
|
||||
self.assertEqual(contents, expected_output)
|
||||
finally:
|
||||
os.chdir(startdir)
|
||||
|
||||
def test_mozbuild_adding(self):
|
||||
test_vectors = [
|
||||
(
|
||||
"media/dav1d/moz.build",
|
||||
SAMPLE_DAV1D_MOZBUILD,
|
||||
"third_party/dav1d/src/cdf2.c",
|
||||
"media/dav1d/",
|
||||
"third-party/dav1d/",
|
||||
"cdf.c',\n",
|
||||
"cdf.c',\n '../../third_party/dav1d/src/cdf2.c',\n",
|
||||
),
|
||||
(
|
||||
"media/dav1d/moz.build",
|
||||
SAMPLE_DAV1D_MOZBUILD,
|
||||
"third_party/dav1d/src/header3.h",
|
||||
"media/dav1d/",
|
||||
"third-party/dav1d/",
|
||||
"header2.h',\n",
|
||||
"header2.h',\n '../../third_party/dav1d/src/header3.h',\n",
|
||||
),
|
||||
(
|
||||
"media/jxl/moz.build",
|
||||
SAMPLE_JPEGXL_MOZBUILD,
|
||||
"third_party/jpeg-xl/lib/jxl/alpha2.cc",
|
||||
"media/jxl/",
|
||||
"third-party/jpeg-xl/",
|
||||
'alpha.cc",\n',
|
||||
'alpha.cc",\n "/third_party/jpeg-xl/lib/jxl/alpha2.cc",\n',
|
||||
),
|
||||
(
|
||||
"media/jxl/moz.build",
|
||||
SAMPLE_JPEGXL_MOZBUILD,
|
||||
"third_party/jpeg-xl/lib/jxl/header3.hpp",
|
||||
"media/jxl/",
|
||||
"third-party/jpeg-xl/",
|
||||
'header2.h",\n',
|
||||
'header2.h",\n "/third_party/jpeg-xl/lib/jxl/header3.hpp",\n',
|
||||
),
|
||||
]
|
||||
|
||||
for vector in test_vectors:
|
||||
(
|
||||
mozbuild_path,
|
||||
mozbuild_contents,
|
||||
file_to_add,
|
||||
moz_yaml_dir,
|
||||
vendoring_dir,
|
||||
search_str,
|
||||
replace_str,
|
||||
) = vector
|
||||
|
||||
startdir = os.getcwd()
|
||||
try:
|
||||
mozbuild_dir = _make_mozbuild_directory_structure(
|
||||
mozbuild_path, mozbuild_contents
|
||||
)
|
||||
os.chdir(mozbuild_dir.name)
|
||||
|
||||
mu.add_file_to_moz_build_file(
|
||||
file_to_add, moz_yaml_dir=moz_yaml_dir, vendoring_dir=vendoring_dir
|
||||
)
|
||||
|
||||
with open(os.path.join(mozbuild_dir.name, mozbuild_path)) as file:
|
||||
contents = file.read()
|
||||
|
||||
expected_output = mozbuild_contents.replace(search_str, replace_str)
|
||||
if contents != expected_output:
|
||||
print("File to add:", file_to_add)
|
||||
print("Contents:")
|
||||
print("-------------------")
|
||||
print(contents)
|
||||
print("-------------------")
|
||||
print("Expected:")
|
||||
print("-------------------")
|
||||
print(expected_output)
|
||||
print("-------------------")
|
||||
self.assertEqual(contents, expected_output)
|
||||
finally:
|
||||
os.chdir(startdir)
|
||||
|
||||
# This test is legacy. I'm keeping it around, but new test vectors should be added to the
|
||||
# non-internal test to exercise the public API.
|
||||
def test_mozbuild_adding_internal(self):
|
||||
test_vectors = [
|
||||
# (
|
||||
# mozbuild_contents
|
||||
# unnormalized_filename_to_add
|
||||
# unnormalized_filename_to_add,
|
||||
# unnormalized_list_of_files
|
||||
# expected_output
|
||||
# )
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-sse2-more.c",
|
||||
["pixman-sse2.c"],
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
"SOURCES += ['pixman-sse2.c']",
|
||||
"SOURCES += ['pixman-sse2-more.c','pixman-sse2.c']",
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-trap-more.c",
|
||||
[
|
||||
"pixman-region32.c",
|
||||
|
@ -176,36 +370,33 @@ class TestUtils(unittest.TestCase):
|
|||
"pixman-x86.c",
|
||||
"pixman.c",
|
||||
],
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
"'pixman-trap.c',", "'pixman-trap-more.c',\n 'pixman-trap.c',"
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-arm-neon-asm-more.S",
|
||||
[
|
||||
"pixman-arm-neon-asm-bilinear.S",
|
||||
"pixman-arm-neon-asm.S",
|
||||
],
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
["pixman-arm-neon-asm-bilinear.S", "pixman-arm-neon-asm.S"],
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
'"pixman-arm-neon-asm.S"',
|
||||
'"pixman-arm-neon-asm-more.S",\n "pixman-arm-neon-asm.S"',
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-arm-simd-asm-smore.S",
|
||||
["pixman-arm-simd-asm-scaled.S", "pixman-arm-simd-asm.S"],
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
"'pixman-arm-simd-asm.S'",
|
||||
"'pixman-arm-simd-asm-smore.S',\n 'pixman-arm-simd-asm.S'",
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-arm-simd-asn.S",
|
||||
["pixman-arm-simd-asm-scaled.S", "pixman-arm-simd-asm.S"],
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
"'pixman-arm-simd-asm.S'",
|
||||
"'pixman-arm-simd-asm.S',\n 'pixman-arm-simd-asn.S'",
|
||||
),
|
||||
|
@ -246,7 +437,9 @@ class TestUtils(unittest.TestCase):
|
|||
print("-------------------")
|
||||
self.assertEqual(contents, expected_output)
|
||||
|
||||
def test_mozbuild_removing(self):
|
||||
# This test is legacy. I'm keeping it around, but new test vectors should be added to the
|
||||
# non-internal test to exercise the public API.
|
||||
def test_mozbuild_removing_internal(self):
|
||||
test_vectors = [
|
||||
# (
|
||||
# mozbuild_contents
|
||||
|
@ -254,41 +447,35 @@ class TestUtils(unittest.TestCase):
|
|||
# expected_output
|
||||
# )
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-sse2.c",
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
"SOURCES += ['pixman-sse2.c']",
|
||||
"SOURCES += []",
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
"SOURCES += ['pixman-sse2.c']", "SOURCES += []"
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-trap.c",
|
||||
SAMPLE_MOZBUILD.replace(" 'pixman-trap.c',\n", ""),
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(" 'pixman-trap.c',\n", ""),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-arm-neon-asm.S",
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
' "pixman-arm-neon-asm.S",\n',
|
||||
"",
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
' "pixman-arm-neon-asm.S",\n', ""
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-arm-simd-asm.S",
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
" 'pixman-arm-simd-asm.S'",
|
||||
" ",
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace(
|
||||
" 'pixman-arm-simd-asm.S'", " "
|
||||
),
|
||||
),
|
||||
(
|
||||
SAMPLE_MOZBUILD,
|
||||
SAMPLE_PIXMAN_MOZBUILD,
|
||||
"pixman-region32.c",
|
||||
SAMPLE_MOZBUILD.replace(
|
||||
"'pixman-region32.c',",
|
||||
"",
|
||||
),
|
||||
SAMPLE_PIXMAN_MOZBUILD.replace("'pixman-region32.c',", ""),
|
||||
),
|
||||
]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче