Example #1
0
    def test_toolchain_win_debug(self):
        client = TestClient(path_with_spaces=False)
        settings = {
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "compiler.toolset": "v140",
            "compiler.runtime": "MDd",
            "build_type": "Debug",
            "arch": "x86_64"
        }

        # Build the profile according to the settings provided
        settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                            if v)

        client.run("new hello/0.1 -s")
        client.run("create . hello/0.1@ %s" % (settings, ))

        # Prepare the actual consumer package
        client.save(
            {
                "conanfile.py": self.conanfile,
                "MyProject.sln": sln_file,
                "MyApp/MyApp.vcxproj": myapp_vcxproj,
                "MyApp/MyApp.cpp": self.app
            },
            clean_first=True)

        # Run the configure corresponding to this test case
        client.run("install . %s -if=conan" % (settings, ))
        self.assertIn(
            "conanfile.py: MSBuildToolchain created conan_toolchain_debug_x64.props",
            client.out)
        vs_path = vs_installation_path("15")
        vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")

        # FIXME: This is cheating, pass the toolset on the command line, nothing that devs would do
        cmd = (
            'set "VSCMD_START_DIR=%%CD%%" && '
            '"%s" x64 && '
            'msbuild "MyProject.sln" /p:Configuration=Debug /p:PlatformToolset="v140"'
            % vcvars_path)
        client.run_command(cmd)
        self.assertIn("Visual Studio 2017", client.out)
        self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'",
                      client.out)
        self._run_app(client, "x64", "Debug")
        self.assertIn("AppMSCVER 15!!", client.out)
        self.assertIn("AppCppStd 14!!!", client.out)

        cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
               '"%s" x64 && dumpbin /dependents "x64\\Debug\\MyApp.exe"' %
               vcvars_path)
        client.run_command(cmd)
        self.assertIn("MSVCP140D.dll", client.out)
        self.assertIn("VCRUNTIME140D.dll", client.out)
Example #2
0
    def test_toolchain_win_multi(self):
        client = TestClient(path_with_spaces=False)
        settings = {
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "compiler.cppstd": "17"
        }
        settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                            if v)
        client.run("new hello/0.1 -s")
        configs = [("Release", "x86"), ("Release", "x86_64"), ("Debug", "x86"),
                   ("Debug", "x86_64")]
        for build_type, arch in configs:
            # Build the profile according to the settings provided
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s"
                % (settings, build_type, arch, runtime))

        # Prepare the actual consumer package
        client.save(
            {
                "conanfile.py": self.conanfile,
                "MyProject.sln": sln_file,
                "MyApp/MyApp.vcxproj": myapp_vcxproj,
                "MyApp/MyApp.cpp": self.app
            },
            clean_first=True)

        # Run the configure corresponding to this test case
        for build_type, arch in configs:
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "install . %s -s build_type=%s -s arch=%s -s compiler.runtime=%s -if=conan"
                % (settings, build_type, arch, runtime))

        vs_path = vs_installation_path("15")
        vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")

        for build_type, arch in configs:
            platform_arch = "x86" if arch == "x86" else "x64"
            cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
                   '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s '
                   '/p:Platform=%s ' %
                   (vcvars_path, build_type, platform_arch))
            client.run_command(cmd)
            self.assertIn("Visual Studio 2017", client.out)
            self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'",
                          client.out)
            self._run_app(client, arch, build_type)
            version = re.search("main _MSC_VER19([0-9]*)",
                                str(client.out)).group(1)
            version = int(version)
            self.assertTrue(10 <= version < 20)
            self.assertIn("main _MSVC_LANG2017", client.out)
Example #3
0
    def test_toolchain_win(self):
        client = TestClient(path_with_spaces=False)
        settings = {
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "compiler.cppstd": "17",
            "compiler.runtime": "MT",
            "build_type": "Release",
            "arch": "x86"
        }

        # Build the profile according to the settings provided
        settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                            if v)

        client.run("new hello/0.1 -s")
        client.run("create . hello/0.1@ %s" % (settings, ))

        # Prepare the actual consumer package
        client.save(
            {
                "conanfile.py": self.conanfile,
                "MyProject.sln": sln_file,
                "MyApp/MyApp.vcxproj": myapp_vcxproj,
                "MyApp/MyApp.cpp": self.app
            },
            clean_first=True)

        # Run the configure corresponding to this test case
        client.run("install . %s -if=conan" % (settings, ))
        self.assertIn(
            "conanfile.py: MSBuildToolchain created "
            "conan_toolchain_release_win32.props", client.out)
        vs_path = vs_installation_path("15")
        vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")

        cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
               '"%s" x86 && msbuild "MyProject.sln" /p:Configuration=Release' %
               vcvars_path)
        client.run_command(cmd)
        self.assertIn("Visual Studio 2017", client.out)
        self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'",
                      client.out)
        self._run_app(client, "x86", "Release")
        self.assertIn("AppMSCVER 17!!", client.out)
        self.assertIn("AppCppStd 17!!!", client.out)

        cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
               '"%s" x86 && dumpbin /dependents "Release\\MyApp.exe"' %
               vcvars_path)
        client.run_command(cmd)
        # No other DLLs dependencies rather than kernel, it was MT, statically linked
        self.assertIn("KERNEL32.dll", client.out)
        self.assertEqual(1, str(client.out).count(".dll"))
Example #4
0
def _vcvars_path(version, vs_install_path):
    # TODO: This comes from conans/client/tools/win.py vcvars_command()
    vs_path = vs_install_path or vs_installation_path(version)
    if not vs_path or not os.path.isdir(vs_path):
        raise ConanException("VS non-existing installation: Visual Studio %s" % version)

    if int(version) > 14:
        vcpath = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")
    else:
        vcpath = os.path.join(vs_path, "VC/vcvarsall.bat")
    return vcpath
Example #5
0
    def test_toolchain_win_multi(self):
        client = TestClient(path_with_spaces=False)
        settings = {
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "compiler.cppstd": "17"
        }
        settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                            if v)
        client.run("new hello/0.1 -s")
        configs = [("Release", "x86", True), ("Release", "x86_64", True),
                   ("Debug", "x86", False), ("Debug", "x86_64", False)]
        for build_type, arch, shared in configs:
            # Build the profile according to the settings provided
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s "
                " -o hello:shared=%s" %
                (settings, build_type, arch, runtime, shared))

        # Prepare the actual consumer package
        client.save(
            {
                "conanfile.py": self.conanfile,
                "MyProject.sln": sln_file,
                "MyApp/MyApp.vcxproj": myapp_vcxproj,
                "MyApp/MyApp.cpp": self.app
            },
            clean_first=True)

        # Run the configure corresponding to this test case
        for build_type, arch, shared in configs:
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "install . %s -s build_type=%s -s arch=%s -s compiler.runtime=%s -if=conan"
                " -o hello:shared=%s" %
                (settings, build_type, arch, runtime, shared))

        vs_path = vs_installation_path("15")
        vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")

        for build_type, arch, shared in configs:
            platform_arch = "x86" if arch == "x86" else "x64"
            if build_type == "Release" and shared:
                configuration = "ReleaseShared"
            else:
                configuration = build_type

            # The "conan build" command is not good enough, cannot do the switch between configs
            cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
                   '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s '
                   '/p:Platform=%s ' %
                   (vcvars_path, configuration, platform_arch))
            client.run_command(cmd)
            self.assertIn("Visual Studio 2017", client.out)
            self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'",
                          client.out)

            self._run_app(client, arch, build_type, shared)
            check_exe_run(client.out, "main", "msvc", "19.1", build_type, arch,
                          "17", {
                              "DEFINITIONS_BOTH": "True",
                              "DEFINITIONS_CONFIG": build_type
                          })

            new_cmd = "conan\\%s\\%s\\MyApp.exe" % (arch, configuration)
            vcvars = vcvars_command(version="15", architecture="amd64")
            cmd = ('%s && dumpbin /dependents "%s"' % (vcvars, new_cmd))
            client.run_command(cmd)
            if shared:
                self.assertIn("hello.dll", client.out)
            else:
                self.assertNotIn("hello.dll", client.out)
            self.assertIn("KERNEL32.dll", client.out)