aboutsummaryrefslogtreecommitdiff
path: root/llvm_tools/manifest_utils_unittest.py
blob: 28179413bd413637f92115cec79266217bdeabf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# Copyright 2023 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Provides utilities to read and edit the ChromiumOS Manifest entries.

While this code reads and edits the internal manifest, it should only operate
on toolchain projects (llvm-project, etc.) which are public.
"""

import unittest
from xml.etree import ElementTree

import manifest_utils


MANIFEST_FIXTURE = """<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <!-- Comment that should not be removed.
       Multiple lines. -->
  <include name="_remotes.xml" />
  <default revision="refs/heads/main"
           remote="cros"
           sync-j="8" />

  <include name="_kernel_upstream.xml" />

  <!-- Common projects for developing CrOS. -->
  <project path="src/repohooks"
           name="chromiumos/repohooks"
           groups="minilayout,paygen,firmware,buildtools,labtools,crosvm" />
  <repo-hooks in-project="chromiumos/repohooks"
              enabled-list="pre-upload" />
  <project path="chromite"
           name="chromiumos/chromite"
           groups="minilayout,paygen,firmware,buildtools,chromeos-admin">
    <copyfile src="AUTHORS" dest="AUTHORS" />
    <copyfile src="LICENSE" dest="LICENSE" />
  </project>
  <project path="src/third_party/llvm-project"
           name="external/github.com/llvm/llvm-project"
           groups="notdefault,bazel"
           revision="abcd" />
  <project path="chromite/third_party/pyelftools"
           name="chromiumos/third_party/pyelftools"
           revision="refs/heads/chromeos-0.22"
           groups="minilayout,paygen,firmware,buildtools" />
</manifest>
"""


class TestManifestUtils(unittest.TestCase):
    """Test manifest_utils."""

    def test_update_chromeos_manifest(self):
        root = ElementTree.fromstring(
            MANIFEST_FIXTURE,
            parser=manifest_utils.make_xmlparser(),
        )
        manifest_utils.update_chromeos_manifest_tree("wxyz", root)
        string_root1 = ElementTree.tostring(root)
        self.assertRegex(
            str(string_root1, encoding="utf-8"),
            r'revision="wxyz"',
        )
        self.assertRegex(
            str(string_root1, encoding="utf-8"),
            r"<!-- Comment that should not be removed.",
        )
        self.assertNotRegex(
            str(string_root1, encoding="utf-8"),
            r'revision="abcd"',
        )
        # Check idempotence.
        manifest_utils.update_chromeos_manifest_tree("wxyz", root)
        string_root2 = ElementTree.tostring(root)
        self.assertEqual(string_root1, string_root2)

    def test_extract_current_llvm_hash(self):
        root = ElementTree.fromstring(
            MANIFEST_FIXTURE,
            parser=manifest_utils.make_xmlparser(),
        )
        self.assertEqual(
            manifest_utils.extract_current_llvm_hash_from_xml(root),
            "abcd",
        )


if __name__ == "__main__":
    unittest.main()