Exemple #1
0
    def test_preprocessor_called_second_api_call(self):
        """"When calling twice to conan create with the Conan python API, the default
        settings shouldn't be cached. To test that the default profile is not cached,
        this test is verifying that the setting preprocessor is adjusting the runtime
        to MDd when build_type=Debug after a different call to conan create that could
        cache the runtime to MD (issue reported at: #4246) """
        tmp = temp_folder()
        with environment_append({"CONAN_USER_HOME": tmp}):
            with chdir(tmp):
                api = ConanAPIV1(output=TestBufferConanOutput())
                api.new(name="lib/1.0@conan/stable", bare=True)

                def get_conaninfo(info):
                    package_id = info["installed"][0]["packages"][0]["id"]
                    pref = PackageReference.loads("lib/1.0@conan/stable:%s" %
                                                  package_id)
                    cache = ClientCache(api.cache_folder,
                                        TestBufferConanOutput())
                    folder = cache.package_layout(pref.ref).package(pref)
                    return load(os.path.join(folder, "conaninfo.txt"))

                settings = [
                    "compiler=Visual Studio", "compiler.version=15",
                    "build_type=Release"
                ]
                info = api.create(".",
                                  name=None,
                                  version=None,
                                  user="******",
                                  channel="stable",
                                  settings=settings)
                self.assertIn("compiler.runtime=MD", get_conaninfo(info))

                settings = [
                    "compiler=Visual Studio", "compiler.version=15",
                    "build_type=Debug"
                ]
                info = api.create(".",
                                  name=None,
                                  version=None,
                                  user="******",
                                  channel="stable",
                                  settings=settings)
                self.assertIn("compiler.runtime=MDd", get_conaninfo(info))
Exemple #2
0
    def test_api_conanfile_loader_shouldnt_cache(self):
        tmp = temp_folder()
        with environment_append({"CONAN_USER_HOME": tmp}):
            with chdir(tmp):
                output = TestBufferConanOutput()
                api = ConanAPIV1(output=output)

                conanfile = dedent("""
                    from conans import ConanFile
                    class Pkg(ConanFile):
                        def build(self):
                            self.output.info("NUMBER 42!!")
                    """)
                save("conanfile.py", conanfile)
                api.create(".", "pkg", "version", "user", "channel")
                self.assertIn("pkg/version@user/channel: NUMBER 42!!", output)
                save("conanfile.py", conanfile.replace("42", "123"))
                api.create(".", "pkg", "version", "user", "channel")
                self.assertIn("pkg/version@user/channel: NUMBER 123!!", output)
Exemple #3
0
 def __init__(self, conan_user_home: types.PATH, cwd: types.PATH):
     self._cwd = cwd
     self.stream = StringIO()
     output = ConanOutput(self.stream, self.stream, color=False)
     conan_api = ConanAPIV1(cache_folder=conan_user_home, output=output)
     self.cmd = Command(conan_api)