示例#1
0
    def test_deprecated_behaviour(self):
        """"Remove when deprecate the old settings parameter to CMake and
        conanfile to configure/build/test"""
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.arch = "x86"
        settings.os = "Windows"

        dot_dir = "." if sys.platform == 'win32' else "'.'"

        cross = "-DCMAKE_SYSTEM_NAME=\"Windows\" " if platform.system(
        ) != "Windows" else ""

        conan_file = ConanFileMock()
        conan_file.settings = settings
        cmake = CMake(settings)
        cmake.configure(conan_file)
        cores = '-DCONAN_CXX_FLAGS="/MP{0}" -DCONAN_C_FLAGS="/MP{0}" '.format(
            tools.cpu_count())
        self.assertEqual(
            'cd {0} && cmake -G "Visual Studio 12 2013" {1}-DCONAN_EXPORTED="1" '
            '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" {2}'
            '-Wno-dev {0}'.format(dot_dir, cross, cores), conan_file.command)

        cmake.build(conan_file)
        self.assertEqual('cmake --build %s' % dot_dir, conan_file.command)
        cmake.test()
        self.assertEqual(
            'cmake --build %s %s' %
            (dot_dir, CMakeTest.scape('--target RUN_TESTS')),
            conan_file.command)
示例#2
0
    def test_deprecated_behaviour(self):
        """"Remove when deprecate the old settings parameter to CMake and conanfile to configure/build/test"""
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.arch = "x86"
        settings.os = "Windows"

        dot_dir = "." if sys.platform == 'win32' else "'.'"

        cross = "-DCMAKE_SYSTEM_NAME=\"Windows\" " if platform.system() != "Windows" else ""

        conan_file = ConanFileMock()
        conan_file.settings = settings
        cmake = CMake(settings)
        cmake.configure(conan_file)
        cores = '-DCONAN_CXX_FLAGS="/MP{0}" -DCONAN_C_FLAGS="/MP{0}" '.format(tools.cpu_count())
        self.assertEqual('cd {0} && cmake -G "Visual Studio 12 2013" {1}-DCONAN_EXPORTED="1" '
                         '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" {2}'
                         '-Wno-dev {0}'.format(dot_dir, cross, cores),
                         conan_file.command)

        cmake.build(conan_file)
        self.assertEqual('cmake --build %s' % dot_dir, conan_file.command)
        cmake.test()
        self.assertEqual('cmake --build %s %s' % (dot_dir, CMakeTest.scape('--target RUN_TESTS')), conan_file.command)
示例#3
0
    def convenient_functions_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.arch = "x86"

        if sys.platform == 'win32':
            dot_dir = "."
            tempdir = self.tempdir
        else:
            dot_dir = "'.'"
            tempdir = "'" + self.tempdir + "'"

        cmake = CMake(settings)
        conan_file = ConanFileMock()

        cross = "-DCMAKE_SYSTEM_NAME=Windows " if platform.system() != "Windows" else ""

        cmake.configure(conan_file)
        self.assertEqual('cd {0} && cmake -G "Visual Studio 12 2013" {1}-DCONAN_EXPORTED=1 '
                         '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" '
                         '-Wno-dev {0}'.format(dot_dir, cross),
                         conan_file.command)

        cmake.build(conan_file)
        self.assertEqual('cmake --build %s' % dot_dir, conan_file.command)

        settings.build_type = "Debug"
        cmake.build(conan_file)
        self.assertEqual('cmake --build %s --config Debug' % dot_dir, conan_file.command)

        cmake.configure(conan_file, source_dir="/source", build_dir=self.tempdir,
                        args=['--foo "bar"'], defs={"SHARED": True})
        if sys.platform == 'win32':
            escaped_args = r'"--foo \"bar\"" -DSHARED=True /source'
        else:
            escaped_args = "'--foo \"bar\"' '-DSHARED=True' '/source'"
        self.assertEqual('cd %s && cmake -G "Visual Studio 12 2013" %s-DCONAN_EXPORTED=1 '
                         '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" '
                         '-Wno-dev %s' % (tempdir, cross, escaped_args),
                         conan_file.command)

        cmake.build(conan_file, args=["--bar 'foo'"], target="install")
        if sys.platform == 'win32':
            escaped_args = '--target install "--bar \'foo\'"'
        else:
            escaped_args = r"'--target' 'install' '--bar '\''foo'\'''"
        self.assertEqual('cmake --build %s --config Debug %s' % (tempdir, escaped_args),
                         conan_file.command)

        settings.build_type = "Release"
        cmake = CMake(settings)
        cmake.build(conan_file)
        self.assertEqual('cmake --build %s --config Release' % dot_dir, conan_file.command)

        cmake.build(conan_file, build_dir=self.tempdir)
        self.assertEqual('cmake --build %s --config Release' % tempdir, conan_file.command)
示例#4
0
    def test_clean_sh_path(self):

        if platform.system() != "Windows":
            return

        os.environ["PATH"] = os.environ.get("PATH",
                                            "") + os.pathsep + self.tempdir
        save(os.path.join(self.tempdir, "sh.exe"), "Fake sh")
        conanfile = ConanFileMock()
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.arch = "x86"
        conanfile.settings = settings

        cmake = CMake(conanfile)
        cmake.configure()
        self.assertIn(self.tempdir, conanfile.path)

        cmake.generator = "MinGW Makefiles"
        cmake.configure()
        self.assertNotIn(self.tempdir, conanfile.path)

        # Automatic gcc
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "gcc"
        settings.compiler.version = "5.4"
        settings.arch = "x86"
        conanfile.settings = settings

        cmake = CMake(conanfile)
        cmake.configure()
        self.assertNotIn(self.tempdir, conanfile.path)
示例#5
0
    def test_clean_sh_path(self):

        if platform.system() != "Windows":
            return

        os.environ["PATH"] = os.environ.get("PATH", "") + os.pathsep + self.tempdir
        save(os.path.join(self.tempdir, "sh.exe"), "Fake sh")
        conanfile = ConanFileMock()
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.arch = "x86"
        conanfile.settings = settings

        cmake = CMake(conanfile)
        cmake.configure()
        self.assertIn(self.tempdir, conanfile.path)

        cmake.generator = "MinGW Makefiles"
        cmake.configure()
        self.assertNotIn(self.tempdir, conanfile.path)

        # Automatic gcc
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "gcc"
        settings.compiler.version = "5.4"
        settings.arch = "x86"
        conanfile.settings = settings

        cmake = CMake(conanfile)
        cmake.configure()
        self.assertNotIn(self.tempdir, conanfile.path)
示例#6
0
    def convenient_functions_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.compiler.runtime = "MDd"
        settings.arch = "x86"
        settings.build_type = None

        if sys.platform == 'win32':
            dot_dir = "."
            tempdir = self.tempdir
        else:
            dot_dir = "'.'"
            tempdir = "'" + self.tempdir + "'"

        conan_file = ConanFileMock()
        conan_file.settings = settings
        cmake = CMake(conan_file)

        cross = "-DCMAKE_SYSTEM_NAME=\"Windows\" -DCMAKE_SYSROOT=\"/path/to/sysroot\" " if platform.system(
        ) != "Windows" else ""
        target_test = CMakeTest.scape('--target RUN_TESTS')

        cmake.configure()

        cores = '-DCONAN_CXX_FLAGS="/MP{0}" -DCONAN_C_FLAGS="/MP{0}" '.format(
            tools.cpu_count())
        self.assertEqual(
            'cd {0} && cmake -G "Visual Studio 12 2013" -DCONAN_LINK_RUNTIME="/MDd" {1}-DCONAN_EXPORTED="1"'
            ' -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" {2}'
            '-Wno-dev {0}'.format(dot_dir, cross, cores), conan_file.command)

        cmake.build()
        self.assertEqual('cmake --build %s' % dot_dir, conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s %s' % (dot_dir, target_test),
                         conan_file.command)

        settings.build_type = "Debug"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual('cmake --build %s --config Debug' % dot_dir,
                         conan_file.command)

        cmake.test()
        self.assertEqual(
            'cmake --build %s --config Debug %s' % (dot_dir, target_test),
            conan_file.command)

        cmake.configure(source_dir="/source",
                        build_dir=self.tempdir,
                        args=['--foo "bar"'],
                        defs={"SHARED": True})
        if sys.platform == 'win32':
            escaped_args = r'"--foo \"bar\"" -DSHARED="True" /source'
        else:
            escaped_args = "'--foo \"bar\"' -DSHARED=\"True\" '/source'"

        self.assertEqual(
            'cd %s && cmake -G "Visual Studio 12 2013" -DCONAN_LINK_RUNTIME="/MDd" %s-DCONAN_EXPORTED="1" '
            '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" %s'
            '-Wno-dev %s' % (tempdir, cross, cores, escaped_args),
            conan_file.command)

        cmake.build(args=["--bar 'foo'"], target="install")
        if sys.platform == 'win32':
            escaped_args = '--target install "--bar \'foo\'"'
        else:
            escaped_args = r"'--target' 'install' '--bar '\''foo'\'''"
        self.assertEqual(
            'cmake --build %s --config Debug %s' % (tempdir, escaped_args),
            conan_file.command)

        cmake.test(args=["--bar 'foo'"])
        if sys.platform == 'win32':
            escaped_args = '%s "--bar \'foo\'"' % target_test
        else:
            escaped_args = r"%s '--bar '\''foo'\'''" % target_test
        self.assertEqual(
            'cmake --build %s --config Debug %s' % (tempdir, escaped_args),
            conan_file.command)

        settings.build_type = "Release"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual('cmake --build %s --config Release' % dot_dir,
                         conan_file.command)

        cmake.test()
        self.assertEqual(
            'cmake --build %s --config Release %s' % (dot_dir, target_test),
            conan_file.command)

        cmake.build(build_dir=self.tempdir)
        self.assertEqual('cmake --build %s --config Release' % tempdir,
                         conan_file.command)

        cmake.test(build_dir=self.tempdir)
        self.assertEqual(
            'cmake --build %s --config Release %s' % (tempdir, target_test),
            conan_file.command)

        settings.compiler = "gcc"
        settings.compiler.version = "5.4"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual(
            'cmake --build %s' % (CMakeTest.scape('. -- -j%i' % cpu_count())),
            conan_file.command)

        cmake.test()
        self.assertEqual(
            'cmake --build %s' %
            (CMakeTest.scape('. --target test -- -j%i' % cpu_count())),
            conan_file.command)

        cmake.build(args=['foo', '--', 'bar'])
        self.assertEqual(
            'cmake --build %s' %
            (CMakeTest.scape('. foo -- bar -j%i' % cpu_count())),
            conan_file.command)

        cmake.test(args=['foo', '--', 'bar'])
        self.assertEqual(
            'cmake --build %s' %
            (CMakeTest.scape('. --target test foo -- bar -j%i' % cpu_count())),
            conan_file.command)

        cmake = CMake(conan_file, parallel=False)
        cmake.build()
        self.assertEqual('cmake --build %s' % CMakeTest.scape('.'),
                         conan_file.command)

        cmake.test()
        self.assertEqual(
            'cmake --build %s' % CMakeTest.scape('. --target test'),
            conan_file.command)
示例#7
0
    def convenient_functions_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "12"
        settings.compiler.runtime = "MDd"
        settings.arch = "x86"
        settings.build_type = None

        if sys.platform == 'win32':
            dot_dir = "."
            tempdir = self.tempdir
        else:
            dot_dir = "'.'"
            tempdir = "'" + self.tempdir + "'"

        conan_file = ConanFileMock()
        conan_file.settings = settings
        cmake = CMake(conan_file)

        cross = "-DCMAKE_SYSTEM_NAME=\"Windows\" -DCMAKE_SYSROOT=\"/path/to/sysroot\" " if platform.system() != "Windows" else ""
        target_test = CMakeTest.scape('--target RUN_TESTS')

        cmake.configure()

        cores = '-DCONAN_CXX_FLAGS="/MP{0}" -DCONAN_C_FLAGS="/MP{0}" '.format(tools.cpu_count())
        self.assertEqual('cd {0} && cmake -G "Visual Studio 12 2013" -DCONAN_LINK_RUNTIME="/MDd" {1}-DCONAN_EXPORTED="1"'
                         ' -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" {2}'
                         '-Wno-dev {0}'.format(dot_dir, cross, cores),
                         conan_file.command)

        cmake.build()
        self.assertEqual('cmake --build %s' % dot_dir, conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s %s' % (dot_dir, target_test), conan_file.command)

        settings.build_type = "Debug"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual('cmake --build %s --config Debug' % dot_dir, conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s --config Debug %s' % (dot_dir, target_test), conan_file.command)

        cmake.configure(source_dir="/source", build_dir=self.tempdir,
                        args=['--foo "bar"'], defs={"SHARED": True})
        if sys.platform == 'win32':
            escaped_args = r'"--foo \"bar\"" -DSHARED="True" /source'
        else:
            escaped_args = "'--foo \"bar\"' -DSHARED=\"True\" '/source'"

        self.assertEqual('cd %s && cmake -G "Visual Studio 12 2013" -DCONAN_LINK_RUNTIME="/MDd" %s-DCONAN_EXPORTED="1" '
                         '-DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="12" %s'
                         '-Wno-dev %s' % (tempdir, cross, cores, escaped_args),
                         conan_file.command)

        cmake.build(args=["--bar 'foo'"], target="install")
        if sys.platform == 'win32':
            escaped_args = '--target install "--bar \'foo\'"'
        else:
            escaped_args = r"'--target' 'install' '--bar '\''foo'\'''"
        self.assertEqual('cmake --build %s --config Debug %s' % (tempdir, escaped_args),
                         conan_file.command)

        cmake.test(args=["--bar 'foo'"])
        if sys.platform == 'win32':
            escaped_args = '%s "--bar \'foo\'"' % target_test
        else:
            escaped_args = r"%s '--bar '\''foo'\'''" % target_test
        self.assertEqual('cmake --build %s --config Debug %s' % (tempdir, escaped_args),
                         conan_file.command)

        settings.build_type = "Release"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual('cmake --build %s --config Release' % dot_dir, conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s --config Release %s' % (dot_dir, target_test), conan_file.command)

        cmake.build(build_dir=self.tempdir)
        self.assertEqual('cmake --build %s --config Release' % tempdir, conan_file.command)

        cmake.test(build_dir=self.tempdir)
        self.assertEqual('cmake --build %s --config Release %s' % (tempdir, target_test), conan_file.command)

        settings.compiler = "gcc"
        settings.compiler.version = "5.4"
        cmake = CMake(conan_file)
        cmake.build()
        self.assertEqual('cmake --build %s' % (CMakeTest.scape('. -- -j%i' % cpu_count())), conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s' % (CMakeTest.scape('. --target test -- -j%i' % cpu_count())), conan_file.command)

        cmake.build(args=['foo', '--', 'bar'])
        self.assertEqual('cmake --build %s' % (CMakeTest.scape('. foo -- bar -j%i' % cpu_count())), conan_file.command)

        cmake.test(args=['foo', '--', 'bar'])
        self.assertEqual('cmake --build %s' % (CMakeTest.scape('. --target test foo -- bar -j%i' % cpu_count())), conan_file.command)

        cmake = CMake(conan_file, parallel=False)
        cmake.build()
        self.assertEqual('cmake --build %s' % CMakeTest.scape('.'), conan_file.command)

        cmake.test()
        self.assertEqual('cmake --build %s' % CMakeTest.scape('. --target test'), conan_file.command)