예제 #1
0
def test_sdk():
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple:sdk_path=mypath")
    conanfile.conf = conf
    conanfile.settings = MockSettings({"os": "Macos", "os.sdk": "macosx"})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    # sdk_path takes preference
    assert "SDKROOT=mypath " in conanfile.command
    conf = ConfDefinition()
    conanfile.conf = conf
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=macosx " in conanfile.command
    conanfile.settings = MockSettings({
        "os": "Macos",
        "os.sdk": "macosx",
        "os.sdk_version": "12.1"
    })
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=macosx12.1 " in conanfile.command
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT" not in conanfile.command
예제 #2
0
def test_apple_arch_flag():
    conanfile = ConanFileMock()
    conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"}
    conanfile.settings_build = MockSettings({
        "build_type": "Debug",
        "os": "Macos",
        "arch": "x86_64"
    })
    conanfile.settings = MockSettings({
        "build_type": "Debug",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    expected = "-arch arm64"
    assert be.apple_arch_flag == expected
    env = be.vars()
    assert expected in env["CXXFLAGS"]
    assert expected in env["CFLAGS"]
    assert expected in env["LDFLAGS"]

    # Only set when crossbuilding
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({
        "build_type": "Debug",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    assert be.apple_arch_flag is None
예제 #3
0
def test_apple_isysrootflag():
    """Even when no cross building it is adjusted because it could target a Mac version"""
    conanfile = ConanFileMock()
    conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"}
    conanfile.settings_build = MockSettings({
        "build_type": "Debug",
        "os": "Macos",
        "arch": "x86_64"
    })
    conanfile.settings = MockSettings({
        "build_type": "Debug",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    expected = "-isysroot /path/to/sdk"
    assert be.apple_isysroot_flag == expected
    env = be.vars()
    assert expected in env["CXXFLAGS"]
    assert expected in env["CFLAGS"]
    assert expected in env["LDFLAGS"]

    # Only set when crossbuilding
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({
        "build_type": "Debug",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    assert be.apple_isysroot_flag is None
예제 #4
0
 def test_conf_skip_test(self):
     conf = ConfDefinition()
     conf.loads("tools.build:skip_test=1")
     conanfile = ConanFileMock()
     conanfile.settings = Settings()
     conanfile.conf = conf.get_conanfile_conf(None)
     meson = Meson(conanfile)
     meson.test()
     self.assertIsNone(conanfile.command)
예제 #5
0
def test_none():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count is None
def test_none():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs is None
예제 #7
0
def test_sdk_path():
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple:sdk_path=mypath")
    conanfile.conf = conf
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=mypath " in conanfile.command
def conanfile():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:jobs=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    return conanfile
def test_tools_ning():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.ninja:jobs=23
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs == "-j23"
예제 #10
0
def test_tools_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count == "/m:10"
예제 #11
0
def test_tools_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs == "-j10"
예제 #12
0
def test_tools_ning():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.microsoft.msbuild:max_cpu_count=23
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count == "/m:23"
예제 #13
0
def test_sudo_str(sudo, sudo_askpass, expected_str):
    conanfile = ConanFileMock()
    conanfile.conf = Conf()
    conanfile.settings = Settings()
    conanfile.conf["tools.system.package_manager:sudo"] = sudo
    conanfile.conf["tools.system.package_manager:sudo_askpass"] = sudo_askpass
    with mock.patch('conans.ConanFile.context',
                    new_callable=PropertyMock) as context_mock:
        context_mock.return_value = "host"
        apt = Apt(conanfile)
    assert apt.sudo_str == expected_str
예제 #14
0
def test_tools_check(tool_class, result):
    conanfile = ConanFileMock()
    conanfile.conf = Conf()
    conanfile.settings = Settings()
    conanfile.conf["tools.system.package_manager:tool"] = tool_class.tool_name
    with mock.patch('conans.ConanFile.context',
                    new_callable=PropertyMock) as context_mock:
        context_mock.return_value = "host"
        tool = tool_class(conanfile)
        tool.check(["package"])
    assert tool._conanfile.command == result
예제 #15
0
def test_msys2():
    with mock.patch("platform.system", return_value="Windows"):
        with mock.patch('conans.ConanFile.context',
                        new_callable=PropertyMock) as context_mock:
            context_mock.return_value = "host"
            conanfile = ConanFileMock()
            conanfile.conf = Conf()
            conanfile.settings = Settings()
            conanfile.conf["tools.microsoft.bash:subsystem"] = "msys2"
            manager = _SystemPackageManagerTool(conanfile)
            assert manager.get_default_tool() == "pacman"
예제 #16
0
def test_apt_install_recommends(recommends, recommends_str):
    conanfile = ConanFileMock()
    conanfile.conf = Conf()
    conanfile.settings = Settings()
    conanfile.conf["tools.system.package_manager:tool"] = "apt-get"
    conanfile.conf["tools.system.package_manager:mode"] = "install"
    with mock.patch('conans.ConanFile.context',
                    new_callable=PropertyMock) as context_mock:
        context_mock.return_value = "host"
        apt = Apt(conanfile)
        apt.install(["package1", "package2"], recommends=recommends)
    assert apt._conanfile.command == "apt-get install -y {}package1 package2".format(
        recommends_str)
예제 #17
0
def conanfile():
    c = ConfDefinition()
    c.loads(
        textwrap.dedent("""\
        tools.gnu.make:jobs=40
        tools.ninja:jobs=30
        tools.microsoft.msbuild:max_cpu_count=20
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    return conanfile
예제 #18
0
def test_bazel_command_with_empty_config():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.google.bazel:config=
        tools.google.bazel:bazelrc_path=
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)

    bazel = Bazel(conanfile)
    bazel.build(label='//test:label')

    assert 'bazel  build  //test:label' == str(conanfile.command)
예제 #19
0
def test_installation_path_in_conf():
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({
        "compiler.version": "2021.3",
        "compiler.mode": "classic",
        "os": "Windows"
    })
    fake_path = "mysuper/path/to/intel/oneapi"
    conanfile.conf = ConfDefinition()
    conanfile.conf.loads(
        textwrap.dedent("""\
        tools.intel:installation_path=%s
    """ % fake_path))
    assert IntelCC(conanfile).installation_path == fake_path
예제 #20
0
def test_custom_defines():
    conanfile = ConanFileMock()
    conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"}
    conanfile.settings = MockSettings({
        "build_type": "RelWithDebInfo",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    be.defines = ["MyDefine1", "MyDefine2"]
    env = be.vars()
    assert "-DMyDefine1" in env["CPPFLAGS"]
    assert "-DMyDefine2" in env["CPPFLAGS"]
    assert "-DNDEBUG" in env["CPPFLAGS"]
예제 #21
0
def test_verbosity(mode):
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple.xcodebuild:verbosity={}".format(mode))
    conanfile.conf = conf
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    if mode != "invalid":
        xcodebuild.build("app.xcodeproj")
        assert "-{}".format(mode) in conanfile.command
    else:
        with pytest.raises(ConanException) as excinfo:
            xcodebuild.build("app.xcodeproj")
        assert "Value {} for 'tools.apple.xcodebuild:verbosity' is not valid".format(
            mode) == str(excinfo.value)
예제 #22
0
def test_unix_path(subsystem, expected_path):
    c = ConfDefinition()
    c.loads(
        textwrap.dedent("""\
        tools.microsoft.bash:subsystem={}
    """.format(subsystem)))

    settings = MockSettings({"os": "Windows"})
    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    conanfile.settings = settings
    conanfile.settings_build = settings
    conanfile.win_bash = True

    path = unix_path(conanfile, "c:/path/to/stuff")
    assert expected_path == path
예제 #23
0
def test_env_win_bash():
    conanfile = ConanFileMock()
    conanfile.win_bash = True
    conanfile.conf = {"tools.microsoft.bash:subsystem": "msys2"}
    folder = temp_folder()
    env = Environment(conanfile)
    env.define("MyVar", "MyValue")
    env.define_path("MyPath", "c:/path/to/something")
    env.append("MyPath", "D:/Otherpath")
    sh_path = os.path.join(folder, "foo.sh")
    with mock.patch("platform.system", side_effect=lambda: "Windows"):
        env.save_sh(sh_path)
    with open(sh_path) as f:
        content = f.read()
        assert 'MyVar="MyValue"' in content
        assert 'MyPath="/c/path/to/something:/d/otherpath"' in content
예제 #24
0
def test_target_triple():
    f = temp_folder()
    chdir(f)
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"})
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    conanfile.conf = Conf()
    conanfile.conf["tools.gnu:make_program"] = "my_make"
    conanfile.conf["tools.gnu.make:jobs"] = "23"

    be = AutotoolsToolchain(conanfile)
    be.make_args = ["foo", "var"]
    be.generate_args()
    obj = load_toolchain_args()
    assert "--host=x86_64-linux-gnu" in obj["configure_args"]
    assert "--build=i686-solaris" in obj["configure_args"]
    assert obj["make_args"].replace("'", "") == "foo var"
예제 #25
0
def test_apple_min_os_flag():
    """Even when no cross building it is adjusted because it could target a Mac version"""
    conanfile = ConanFileMock()
    conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"}
    conanfile.settings = MockSettings({
        "build_type": "Debug",
        "os": "Macos",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    expected = "-mmacosx-version-min=14"
    assert be.apple_min_version_flag == expected
    env = be.vars()
    assert expected in env["CXXFLAGS"]
    assert expected in env["CFLAGS"]
    assert expected in env["LDFLAGS"]
예제 #26
0
def test_tools_update_mode_check(tool_class):
    conanfile = ConanFileMock()
    conanfile.conf = Conf()
    conanfile.settings = Settings()
    conanfile.conf["tools.system.package_manager:tool"] = tool_class.tool_name
    conanfile.conf["tools.system.package_manager:mode"] = "check"
    with mock.patch('conans.ConanFile.context',
                    new_callable=PropertyMock) as context_mock:
        context_mock.return_value = "host"
        tool = tool_class(conanfile)
        with pytest.raises(ConanException) as exc_info:
            tool.update()
        assert exc_info.value.args[0] == "Can't update because tools.system.package_manager:mode is " \
                                         "'check'.Please update packages manually or set " \
                                         "'tools.system.package_manager:mode' to 'install' in the [conf] " \
                                         "section of the profile, or in the command line using " \
                                         "'-c tools.system.package_manager:mode=install'"
예제 #27
0
def test_env_win_bash():
    conanfile = ConanFileMock()
    conanfile.settings_build = MockSettings({"os": "Windows"})
    conanfile.win_bash = True
    conanfile.conf = {"tools.microsoft.bash:subsystem": "msys2"}
    folder = temp_folder()
    conanfile.folders.generators = folder
    env = Environment()
    env.define("MyVar", "MyValue")
    env.define_path("MyPath", "c:/path/to/something")
    env.append("MyPath", "D:/Otherpath")
    env_vars = env.vars(conanfile)
    env_vars.save_script("foo")
    content = open(os.path.join(folder, "foo.sh")).read()
    assert 'MyVar="MyValue"' in content
    # Note the unit letter is lowercase
    assert 'MyPath="/c/path/to/something:/d/otherpath"' in content
예제 #28
0
def test_custom_ldflags():
    conanfile = ConanFileMock()
    conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"}
    conanfile.settings = MockSettings({
        "build_type": "RelWithDebInfo",
        "os": "iOS",
        "os.version": "14",
        "arch": "armv8"
    })
    be = AutotoolsToolchain(conanfile)
    be.ldflags = ["MyFlag1", "MyFlag2"]
    env = be.vars()
    assert "MyFlag1" in env["LDFLAGS"]
    assert "MyFlag2" in env["LDFLAGS"]
    assert "-mios-version-min=14" in env["LDFLAGS"]

    assert "MyFlag" not in env["CXXFLAGS"]
    assert "MyFlag" not in env["CFLAGS"]
예제 #29
0
def test_setvars_command_with_custom_arguments(platform_system, os_,
                                               call_command, setvars_file):
    platform_system.return_value = os_
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({
        "compiler.version": "2021.3",
        "compiler.mode": "icx",
        "os": os_
    })
    fake_path = "mysuper/path/to/intel/oneapi"
    args = "arg1 arg2 --force"
    conanfile.conf = ConfDefinition()
    conanfile.conf.loads(
        textwrap.dedent("""\
        tools.intel:installation_path=%s
        tools.intel:setvars_args=%s
    """ % (fake_path, args)))
    expected = '%s "%s" %s' % (call_command,
                               os.path.join(fake_path, setvars_file), args)
    assert IntelCC(conanfile).command == expected
예제 #30
0
def test_meson_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.ninja:jobs=23
        tools.build:processes=10
    """))

    settings = MockSettings({"build_type": "Release",
                             "compiler": "gcc",
                             "compiler.version": "7",
                             "os": "Linux",
                             "arch": "x86_64"})
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.display_name = 'test'
    conanfile.conf = c.get_conanfile_conf(None)

    meson = Meson(conanfile)
    meson.build()
    
    assert '-j23' in str(conanfile.command)