summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/test/backend/test_visualstudio.py
blob: 14cccb484b8026e7501e6a911e42b98e36975d9e (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
# 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 unittest
from xml.dom.minidom import parse

from mozunit import main

from mozbuild.backend.visualstudio import VisualStudioBackend
from mozbuild.test.backend.common import BackendTester


class TestVisualStudioBackend(BackendTester):
    @unittest.skip("Failing inconsistently in automation.")
    def test_basic(self):
        """Ensure we can consume our stub project."""

        env = self._consume("visual-studio", VisualStudioBackend)

        msvc = os.path.join(env.topobjdir, "msvc")
        self.assertTrue(os.path.isdir(msvc))

        self.assertTrue(os.path.isfile(os.path.join(msvc, "mozilla.sln")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "mozilla.props")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "mach.bat")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "binary_my_app.vcxproj")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "target_full.vcxproj")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "library_dir1.vcxproj")))
        self.assertTrue(os.path.isfile(os.path.join(msvc, "library_dir1.vcxproj.user")))

        d = parse(os.path.join(msvc, "library_dir1.vcxproj"))
        self.assertEqual(d.documentElement.tagName, "Project")
        els = d.getElementsByTagName("ClCompile")
        self.assertEqual(len(els), 2)

        # mozilla-config.h should be explicitly listed as an include.
        els = d.getElementsByTagName("NMakeForcedIncludes")
        self.assertEqual(len(els), 1)
        self.assertEqual(
            els[0].firstChild.nodeValue, "$(TopObjDir)\\dist\\include\\mozilla-config.h"
        )

        # LOCAL_INCLUDES get added to the include search path.
        els = d.getElementsByTagName("NMakeIncludeSearchPath")
        self.assertEqual(len(els), 1)
        includes = els[0].firstChild.nodeValue.split(";")
        self.assertIn(os.path.normpath("$(TopSrcDir)/includeA/foo"), includes)
        self.assertIn(os.path.normpath("$(TopSrcDir)/dir1"), includes)
        self.assertIn(os.path.normpath("$(TopObjDir)/dir1"), includes)
        self.assertIn(os.path.normpath("$(TopObjDir)\\dist\\include"), includes)

        # DEFINES get added to the project.
        els = d.getElementsByTagName("NMakePreprocessorDefinitions")
        self.assertEqual(len(els), 1)
        defines = els[0].firstChild.nodeValue.split(";")
        self.assertIn("DEFINEFOO", defines)
        self.assertIn("DEFINEBAR=bar", defines)


if __name__ == "__main__":
    main()