Beispiel #1
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
Beispiel #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
Beispiel #3
0
def test_invalid_target_triple():
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({"os": "Linux", "arch": "UNKNOWN_ARCH"})
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    with pytest.raises(ConanException) as excinfo:
        AutotoolsToolchain(conanfile)
    assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \
           "to translate it to the GNU triplet," in str(excinfo)
Beispiel #4
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
Beispiel #5
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"
Beispiel #6
0
def test_modify_environment():
    """We can alter the environment generated by the toolchain passing the env to the generate"""
    f = temp_folder()
    chdir(f)
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"})
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    conanfile.folders.set_base_install(f)
    be = AutotoolsToolchain(conanfile)
    env = be.environment()
    env.define("foo", "var")
    # We can pass the env to the generate once we adjusted or injected anything
    be.generate(env)

    with open("conanautotoolstoolchain.sh") as f:
        content = f.read()
        assert "foo" in content
Beispiel #7
0
def test_env_win_bash():
    conanfile = ConanFileMock()
    conanfile.settings_build = MockSettings({"os": "Windows"})
    conanfile.win_bash = True
    conanfile.conf.define("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
def test_get_gnu_triplet_for_cross_building_raise_error():
    """
    Testing AutotoolsToolchain and _get_gnu_triplet() function raises an error in case of
    having os=Windows, cross compiling and not defined any compiler
    """
    # Issue: https://github.com/conan-io/conan/issues/10139
    settings = MockSettings({"build_type": "Release",
                             "os": "Windows",
                             "arch": "x86_64"})
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    with pytest.raises(ConanException) as conan_error:
        AutotoolsToolchain(conanfile)
        msg = "'compiler' parameter for 'get_gnu_triplet()' is not specified and " \
              "needed for os=Windows"
        assert msg == str(conan_error.value)
def test_get_gnu_triplet_for_cross_building():
    """
    Testing AutotoolsToolchain and _get_gnu_triplet() function in case of
    having os=Windows and cross compiling
    """
    # Issue: https://github.com/conan-io/conan/issues/10139
    settings = MockSettings({"build_type": "Release",
                             "compiler": "gcc",
                             "compiler.version": "10.2",
                             "os": "Windows",
                             "arch": "x86_64"})
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    autotoolschain = AutotoolsToolchain(conanfile)
    assert autotoolschain._host == "x86_64-w64-mingw32"
    assert autotoolschain._build == "i686-solaris"
def test_modify_environment():
    """We can alter the environment generated by the toolchain passing the env to the generate"""
    f = temp_folder()
    chdir(f)
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"})
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    be = AutotoolsToolchain(conanfile)
    env = be.environment()
    env.define("foo", "var")
    # We can pass the env to the generate once we adjusted or injected anything
    be.generate(env)

    bat = "conanautotoolstoolchain.{}".format("bat" if platform.system() ==
                                              "Windows" else "sh")
    with open(bat) as f:
        content = f.read()
        assert "foo" in content
def test_visual_runtime(runtime):
    """
    Testing AutotoolsToolchain with the msvc compiler adjust the runtime
    """
    # Issue: https://github.com/conan-io/conan/issues/10139
    settings = MockSettings({"build_type": "Release",
                             "compiler": "Visual Studio",
                             "compiler.runtime": runtime,
                             "os": "Windows",
                             "arch": "x86_64"})
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.settings_build = settings
    autotoolschain = AutotoolsToolchain(conanfile)
    expected_flag = "-{}".format(runtime)
    assert autotoolschain.msvc_runtime_flag == expected_flag
    env = autotoolschain.environment().vars(conanfile)
    assert expected_flag in env["CFLAGS"]
    assert expected_flag in env["CXXFLAGS"]