Exemple #1
0
 def help_test(self):
     deps_env_info = DepsEnvInfo()
     deps_cpp_info = DepsCppInfo()
     deps_cpp_info.includedirs.append("C:/whatever")
     deps_cpp_info.includedirs.append("C:/whenever")
     deps_cpp_info.libdirs.append("C:/other")
     deps_cpp_info.libs.extend(["math", "winsock", "boost"])
     child = DepsCppInfo()
     child.includedirs.append("F:/ChildrenPath")
     child.cppflags.append("cxxmyflag")
     deps_cpp_info._dependencies["Boost"] = child
     fakeconan = namedtuple(
         "Conanfile", "deps_cpp_info cpp_info deps_env_info env_info")
     output = TXTGenerator(
         fakeconan(deps_cpp_info, None, deps_env_info, None)).content
     deps_cpp_info2 = DepsCppInfo.loads(output)
     self.assertEqual(deps_cpp_info.configs, deps_cpp_info2.configs)
     self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs)
     self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs)
     self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs)
     self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs)
     self.assertEqual(len(deps_cpp_info._dependencies),
                      len(deps_cpp_info2._dependencies))
     self.assertEqual(deps_cpp_info["Boost"].includedirs,
                      deps_cpp_info2["Boost"].includedirs)
     self.assertEqual(deps_cpp_info["Boost"].cppflags,
                      deps_cpp_info2["Boost"].cppflags)
     self.assertEqual(deps_cpp_info["Boost"].cppflags, ["cxxmyflag"])
Exemple #2
0
 def help_test(self):
     deps_env_info = DepsEnvInfo()
     deps_cpp_info = DepsCppInfo()
     deps_cpp_info.includedirs.append("C:/whatever")
     deps_cpp_info.includedirs.append("C:/whenever")
     deps_cpp_info.libdirs.append("C:/other")
     deps_cpp_info.libs.extend(["math", "winsock", "boost"])
     child = DepsCppInfo()
     child.includedirs.append("F:/ChildrenPath")
     child.cppflags.append("cxxmyflag")
     deps_cpp_info._dependencies["Boost"] = child
     fakeconan = namedtuple("Conanfile", "deps_cpp_info cpp_info deps_env_info env_info")
     output = TXTGenerator(fakeconan(deps_cpp_info, None, deps_env_info, None)).content
     deps_cpp_info2 = DepsCppInfo.loads(output)
     self.assertEqual(deps_cpp_info.configs, deps_cpp_info2.configs)
     self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs)
     self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs)
     self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs)
     self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs)
     self.assertEqual(len(deps_cpp_info._dependencies),
                      len(deps_cpp_info2._dependencies))
     self.assertEqual(deps_cpp_info["Boost"].includedirs,
                      deps_cpp_info2["Boost"].includedirs)
     self.assertEqual(deps_cpp_info["Boost"].cppflags,
                      deps_cpp_info2["Boost"].cppflags)
     self.assertEqual(deps_cpp_info["Boost"].cppflags, ["cxxmyflag"])
Exemple #3
0
 def _check_individual_deps(self, client):
     self.assertIn("INCLUDE [", client.user_io.out)
     self.assertIn(".conan/data/Hello0/0.1/lasote/stable",
                   client.user_io.out)
     build_file = os.path.join(client.current_folder, BUILD_INFO)
     content = load(build_file)
     cmakebuildinfo = load(
         os.path.join(client.current_folder, BUILD_INFO_CMAKE))
     self.assertIn(
         "set(CONAN_LIBS helloHello3 helloHello1 helloHello2 helloHello0",
         cmakebuildinfo)
     self.assertIn("set(CONAN_DEPENDENCIES Hello3 Hello1 Hello2 Hello0)",
                   cmakebuildinfo)
     deps_cpp_info = DepsCppInfo.loads(content)
     self.assertEqual(len(deps_cpp_info.include_paths), 4)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertEqual(len(deps_cpp_info[dep].lib_paths), 1)
         self.assertEqual(deps_cpp_info[dep].libs, ["hello%s" % dep])
     build_file = os.path.join(client.current_folder, BUILD_INFO_CMAKE)
     content = load(build_file)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertIn("set(CONAN_INCLUDE_DIRS_%s " % dep.upper(), content)
         self.assertIn("set(CONAN_LIBS_%s hello%s)" % (dep.upper(), dep),
                       content)
Exemple #4
0
    def build(self, conanfile_path, current_path, test=False, filename=None, profile_name=None):
        """ Call to build() method saved on the conanfile.py
        param conanfile_path: the original source directory of the user containing a
                            conanfile.py
        """
        logger.debug("Building in %s" % current_path)
        logger.debug("Conanfile in %s" % conanfile_path)

        if filename and filename.endswith(".txt"):
            raise ConanException("A conanfile.py is needed to call 'conan build'")

        conanfile_file = os.path.join(conanfile_path, filename or CONANFILE)

        try:
            output = ScopedOutput("Project", self._user_io.out)
            conan_file = self._loader(current_path).load_conan(conanfile_file, output,
                                                               consumer=True)
        except NotFoundException:
            # TODO: Auto generate conanfile from requirements file
            raise ConanException("'%s' file is needed for build.\n"
                                 "Create a '%s' and move manually the "
                                 "requirements and generators from '%s' file"
                                 % (CONANFILE, CONANFILE, CONANFILE_TXT))
        try:
            build_info_file = os.path.join(current_path, BUILD_INFO)
            if os.path.exists(build_info_file):
                try:
                    deps_cpp_info = DepsCppInfo.loads(load(build_info_file))
                    conan_file.deps_cpp_info = deps_cpp_info
                except:
                    pass

            env_file = os.path.join(current_path, "conanenv.txt")
            if os.path.exists(env_file):
                try:
                    deps_env_info = DepsEnvInfo.loads(load(env_file))
                    conan_file.deps_env_info = deps_env_info
                except:
                    pass

            os.chdir(current_path)
            conan_file._conanfile_directory = conanfile_path
            # Append env_vars to execution environment and clear when block code ends
            profile = self._read_profile(profile_name)
            env_vars = self._read_profile_env_vars(profile)
            with environment_append(env_vars):
                conan_file.build()

            if test:
                conan_file.test()
        except ConanException:
            raise  # Raise but not let to reach the Exception except (not print traceback)
        except Exception:
            import traceback
            trace = traceback.format_exc().split('\n')
            raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
Exemple #5
0
 def help_test(self):
     imports = DepsCppInfo()
     imports.includedirs.append("C:/whatever")
     imports.includedirs.append("C:/whenever")
     imports.libdirs.append("C:/other")
     imports.libs.extend(["math", "winsock", "boost"])
     child = DepsCppInfo()
     child.includedirs.append("F:/ChildrenPath")
     child.cppflags.append("cxxmyflag")
     imports._dependencies["Boost"] = child
     output = repr(imports)
     imports2 = DepsCppInfo.loads(output)
     self._equal(imports, imports2)
Exemple #6
0
 def help_test(self):
     imports = DepsCppInfo()
     imports.includedirs.append("C:/whatever")
     imports.includedirs.append("C:/whenever")
     imports.libdirs.append("C:/other")
     imports.libs.extend(["math", "winsock", "boost"])
     child = DepsCppInfo()
     child.includedirs.append("F:/ChildrenPath")
     child.cppflags.append("cxxmyflag")
     imports._dependencies["Boost"] = child
     output = repr(imports)
     imports2 = DepsCppInfo.loads(output)
     self._equal(imports, imports2)
Exemple #7
0
 def help_test(self):
     deps_cpp_info = DepsCppInfo()
     deps_cpp_info.includedirs.append("C:/whatever")
     deps_cpp_info.includedirs.append("C:/whenever")
     deps_cpp_info.libdirs.append("C:/other")
     deps_cpp_info.libs.extend(["math", "winsock", "boost"])
     child = DepsCppInfo()
     child.includedirs.append("F:/ChildrenPath")
     child.cppflags.append("cxxmyflag")
     deps_cpp_info._dependencies["Boost"] = child
     fakeconan = namedtuple("Conanfile", "deps_cpp_info cpp_info")
     output = TXTGenerator(fakeconan(deps_cpp_info, None)).content
     deps_cpp_info2 = DepsCppInfo.loads(output)
     self._equal(deps_cpp_info, deps_cpp_info2)
Exemple #8
0
    def parse_test(self):
        text = """[includedirs]
C:/Whenever
[includedirs_Boost]
F:/ChildrenPath
[includedirs_My_Lib]
mylib_path
[includedirs_My_Other_Lib]
otherlib_path
        """
        deps_info = DepsCppInfo.loads(text)
        self.assertEqual(deps_info.includedirs, ['C:/Whenever'])
        self.assertEqual(deps_info["Boost"].includedirs, ['F:/ChildrenPath'])
        self.assertEqual(deps_info["My_Lib"].includedirs, ['mylib_path'])
        self.assertEqual(deps_info["My_Other_Lib"].includedirs, ['otherlib_path'])
Exemple #9
0
    def parse_test(self):
        text = """[includedirs]
C:/Whenever
[includedirs_Boost]
F:/ChildrenPath
[includedirs_My_Lib]
mylib_path
[includedirs_My_Other_Lib]
otherlib_path
        """
        deps_info = DepsCppInfo.loads(text)
        self.assertEqual(deps_info.includedirs, ['C:/Whenever'])
        self.assertEqual(deps_info["Boost"].includedirs, ['F:/ChildrenPath'])
        self.assertEqual(deps_info["My_Lib"].includedirs, ['mylib_path'])
        self.assertEqual(deps_info["My_Other_Lib"].includedirs,
                         ['otherlib_path'])
Exemple #10
0
 def _check_individual_deps(self, client):
     self.assertIn("INCLUDE [", client.user_io.out)
     self.assertIn(".conan/data/Hello0/0.1/lasote/stable", client.user_io.out)
     build_file = os.path.join(client.current_folder, BUILD_INFO)
     content = load(build_file)
     deps_cpp_info = DepsCppInfo.loads(content)
     self.assertEqual(len(deps_cpp_info.include_paths), 4)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertEqual(len(deps_cpp_info[dep].lib_paths), 1)
         self.assertEqual(deps_cpp_info[dep].libs, ["hello%s" % dep])
     build_file = os.path.join(client.current_folder, BUILD_INFO_CMAKE)
     content = load(build_file)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertIn("set(CONAN_INCLUDE_DIRS_%s " % dep.upper(), content)
         self.assertIn("set(CONAN_LIBS_%s hello%s)" % (dep.upper(), dep), content)
Exemple #11
0
    def build(self, conanfile_path, current_path, test=False, filename=None):
        """ Call to build() method saved on the conanfile.py
        param conanfile_path: the original source directory of the user containing a
                            conanfile.py
        """
        logger.debug("Building in %s" % current_path)
        logger.debug("Conanfile in %s" % conanfile_path)

        if filename and filename.endswith(".txt"):
            raise ConanException(
                "A conanfile.py is needed to call 'conan build'")

        conanfile_file = os.path.join(conanfile_path, filename or CONANFILE)

        try:
            output = ScopedOutput("Project", self._user_io.out)
            conan_file = self._loader(current_path).load_conan(conanfile_file,
                                                               output,
                                                               consumer=True)
        except NotFoundException:
            # TODO: Auto generate conanfile from requirements file
            raise ConanException("'%s' file is needed for build.\n"
                                 "Create a '%s' and move manually the "
                                 "requirements and generators from '%s' file" %
                                 (CONANFILE, CONANFILE, CONANFILE_TXT))
        try:
            build_info_file = os.path.join(current_path, BUILD_INFO)
            if os.path.exists(build_info_file):
                try:
                    deps_cpp_info = DepsCppInfo.loads(load(build_info_file))
                    conan_file.deps_cpp_info = deps_cpp_info
                except:
                    pass

            os.chdir(current_path)
            conan_file._conanfile_directory = conanfile_path
            conan_file.build()
            if test:
                conan_file.test()
        except ConanException:
            raise  # Raise but not let to reach the Exception except (not print traceback)
        except Exception:
            import traceback
            trace = traceback.format_exc().split('\n')
            raise ConanException("Unable to build it successfully\n%s" %
                                 '\n'.join(trace[3:]))
Exemple #12
0
def _load_info_file(current_path, conanfile, output, error):
    if not current_path:
        return
    info_file_path = os.path.join(current_path, BUILD_INFO)
    try:
        deps_info = DepsCppInfo.loads(load(info_file_path))
        conanfile.deps_cpp_info = deps_info
    except IOError:
        error_msg = ("%s file not found in %s\nIt is %s for this command\n"
                     "You can generate it using 'conan install -g %s'" %
                     (BUILD_INFO, current_path,
                      "required" if error else "recommended", "txt"))
        if not error:
            output.warn(error_msg)
        else:
            raise ConanException(error_msg)
    except ConanException:
        raise ConanException("Parse error in '%s' file in %s" %
                             (BUILD_INFO, current_path))
Exemple #13
0
    def build(self, conanfile_path, current_path, test=False):
        """ Call to build() method saved on the conanfile.py
        param conanfile_path: the original source directory of the user containing a
                            conanfile.py
        """
        logger.debug("Building in %s" % current_path)
        logger.debug("Conanfile in %s" % conanfile_path)
        conanfile_file = os.path.join(conanfile_path, CONANFILE)

        try:
            conan_file = self._loader(current_path).load_conan(conanfile_file, consumer=True)
        except NotFoundException:
            # TODO: Auto generate conanfile from requirements file
            raise ConanException("'%s' file is needed for build.\n"
                               "Create a '%s' and move manually the "
                               "requirements and generators from '%s' file"
                               % (CONANFILE, CONANFILE, CONANFILE_TXT))
        try:
            build_info_file = os.path.join(current_path, BUILD_INFO)
            if os.path.exists(build_info_file):
                try:
                    deps_cpp_info = DepsCppInfo.loads(load(build_info_file))
                    conan_file.deps_cpp_info = deps_cpp_info
                except:
                    pass

            os.chdir(current_path)
            conan_file.build()
            if test:
                conan_file.test()
        except ConanException:
            raise  # Raise but not let to reach the Exception except (not print traceback)
        except Exception:
            import traceback
            trace = traceback.format_exc().split('\n')
            raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
Exemple #14
0
    def _load_deps_info(self, current_path, conanfile, output):
        build_info_file = os.path.join(current_path, BUILD_INFO)
        if os.path.exists(build_info_file):
            try:
                deps_cpp_info = DepsCppInfo.loads(load(build_info_file))
                conanfile.deps_cpp_info = deps_cpp_info
            except:
                output.error("Parse error in '%s' file in %s" % (BUILD_INFO, current_path))
        else:
            output.warn("%s file not found in %s\nIt is recommended for source, build and package "
                        "commands\nYou can generate it using 'conan install -g env -g txt'"
                        % (BUILD_INFO, current_path))

        env_file = os.path.join(current_path, CONANENV)
        if os.path.exists(env_file):
            try:
                deps_env_info = DepsEnvInfo.loads(load(env_file))
                conanfile.deps_env_info = deps_env_info
            except:
                output.error("Parse error in '%s' file in %s" % (CONANENV, current_path))
        else:
            output.warn("%s file not found in %s\nIt is recommended for source, build and package "
                        "commands\nYou can generate it using 'conan install -g env -g txt'"
                        % (CONANENV, current_path))