1
0
mirror of https://github.com/facebook/proxygen.git synced 2025-08-08 18:02:05 +03:00
Files
proxygen/build/fbcode_builder/getdeps/test/manifest_test.py
Alex Hornby 88f96e63cb extract get_dependencies method
Summary:
A number of places were extracting dependencies from manifests, but only one was adding in the implicit dependencies for build tools.

Extract the logic to one place and use so that a change in a tool like cmake will now correctly affect all tools using cmake, as it will be taken into account as a dependency hash when the manifest's hash is computed.

Tests for this change revealed that install_dirs needed to be populated in reverse order from the manifest topo-sort, so have also addressed that

Reviewed By: wittgenst

Differential Revision: D32730717

fbshipit-source-id: 1b2a25e460de6085d274c99acfd391b3bd259264
2022-01-07 01:33:09 -08:00

234 lines
5.3 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
import unittest
from ..load import load_all_manifests, patch_loader
from ..manifest import ManifestParser
class ManifestTest(unittest.TestCase):
def test_missing_section(self):
with self.assertRaisesRegex(
Exception, "manifest file test is missing required section manifest"
):
ManifestParser("test", "")
def test_missing_name(self):
with self.assertRaisesRegex(
Exception,
"manifest file test section 'manifest' is missing required field 'name'",
):
ManifestParser(
"test",
"""
[manifest]
""",
)
def test_minimal(self):
p = ManifestParser(
"test",
"""
[manifest]
name = test
""",
)
self.assertEqual(p.name, "test")
self.assertEqual(p.fbsource_path, None)
def test_minimal_with_fbsource_path(self):
p = ManifestParser(
"test",
"""
[manifest]
name = test
fbsource_path = fbcode/wat
""",
)
self.assertEqual(p.name, "test")
self.assertEqual(p.fbsource_path, "fbcode/wat")
def test_unknown_field(self):
with self.assertRaisesRegex(
Exception,
(
"manifest file test section 'manifest' contains "
"unknown field 'invalid.field'"
),
):
ManifestParser(
"test",
"""
[manifest]
name = test
invalid.field = woot
""",
)
def test_invalid_section_name(self):
with self.assertRaisesRegex(
Exception, "manifest file test contains unknown section 'invalid.section'"
):
ManifestParser(
"test",
"""
[manifest]
name = test
[invalid.section]
foo = bar
""",
)
def test_value_in_dependencies_section(self):
with self.assertRaisesRegex(
Exception,
(
"manifest file test section 'dependencies' has "
"'foo = bar' but this section doesn't allow "
"specifying values for its entries"
),
):
ManifestParser(
"test",
"""
[manifest]
name = test
[dependencies]
foo = bar
""",
)
def test_invalid_conditional_section_name(self):
with self.assertRaisesRegex(
Exception,
(
"manifest file test section 'dependencies.=' "
"has invalid conditional: expected "
"identifier found ="
),
):
ManifestParser(
"test",
"""
[manifest]
name = test
[dependencies.=]
""",
)
def test_section_as_args(self):
p = ManifestParser(
"test",
"""
[manifest]
name = test
[dependencies]
a
b
c
[dependencies.test=on]
foo
""",
)
self.assertEqual(p.get_section_as_args("dependencies"), ["a", "b", "c"])
self.assertEqual(
p.get_section_as_args("dependencies", {"test": "off"}), ["a", "b", "c"]
)
self.assertEqual(
p.get_section_as_args("dependencies", {"test": "on"}),
["a", "b", "c", "foo"],
)
p2 = ManifestParser(
"test",
"""
[manifest]
name = test
[autoconf.args]
--prefix=/foo
--with-woot
""",
)
self.assertEqual(
p2.get_section_as_args("autoconf.args"), ["--prefix=/foo", "--with-woot"]
)
def test_section_as_dict(self):
p = ManifestParser(
"test",
"""
[manifest]
name = test
[cmake.defines]
foo = bar
[cmake.defines.test=on]
foo = baz
""",
)
self.assertEqual(p.get_section_as_dict("cmake.defines", {}), {"foo": "bar"})
self.assertEqual(
p.get_section_as_dict("cmake.defines", {"test": "on"}), {"foo": "baz"}
)
p2 = ManifestParser(
"test",
"""
[manifest]
name = test
[cmake.defines.test=on]
foo = baz
[cmake.defines]
foo = bar
""",
)
self.assertEqual(
p2.get_section_as_dict("cmake.defines", {"test": "on"}),
{"foo": "bar"},
msg="sections cascade in the order they appear in the manifest",
)
def test_parse_common_manifests(self):
patch_loader(__name__)
manifests = load_all_manifests(None)
self.assertNotEqual(0, len(manifests), msg="parsed some number of manifests")
def test_mismatch_name(self):
with self.assertRaisesRegex(
Exception,
"filename of the manifest 'foo' does not match the manifest name 'bar'",
):
ManifestParser(
"foo",
"""
[manifest]
name = bar
""",
)
def test_duplicate_manifest(self):
patch_loader(__name__, "fixtures/duplicate")
with self.assertRaisesRegex(Exception, "found duplicate manifest 'foo'"):
load_all_manifests(None)
if sys.version_info < (3, 2):
def assertRaisesRegex(self, *args, **kwargs):
return self.assertRaisesRegexp(*args, **kwargs)