Esempio n. 1
0
    def loads(text, filter_empty=False):
        user_info_host_idx = text.find("[{}_".format(TXTGenerator._USER_INFO_HOST_PREFIX))
        deps_env_info_idx = text.find("[ENV_")
        user_info_build_idx = text.find("[{}_".format(TXTGenerator._USER_INFO_BUILD_PREFIX))

        user_info_host_txt = deps_env_info_txt = ""

        # Get chunk with deps_cpp_info: from the beginning to the first one of the others
        last_idx = next((x for x in [user_info_host_idx, deps_env_info_idx, user_info_build_idx]
                         if x != -1), None)
        deps_cpp_info_txt = text[:last_idx]

        if user_info_host_idx != -1:
            last_idx = next((x for x in [deps_env_info_idx, user_info_build_idx] if x != -1), None)
            user_info_host_txt = text[user_info_host_idx:last_idx]

        if deps_env_info_idx != -1:
            last_idx = next((x for x in [user_info_build_idx] if x != -1), None)
            deps_env_info_txt = text[deps_env_info_idx:last_idx]

        user_info_build = None
        if user_info_build_idx != -1:
            user_info_build_txt = text[user_info_build_idx:]
            user_info_build = TXTGenerator._loads_user_info(user_info_build_txt,
                                                            TXTGenerator._USER_INFO_BUILD_PREFIX)

        deps_cpp_info = TXTGenerator._loads_cpp_info(deps_cpp_info_txt, filter_empty=filter_empty)
        deps_user_info = TXTGenerator._loads_user_info(user_info_host_txt,
                                                       TXTGenerator._USER_INFO_HOST_PREFIX)
        deps_env_info = DepsEnvInfo.loads(deps_env_info_txt)
        return deps_cpp_info, deps_user_info, deps_env_info, user_info_build
Esempio n. 2
0
    def loads(text):
        user_defines_index = text.find("[USER_")
        env_defines_index = text.find("[ENV_")
        if user_defines_index != -1:
            deps_cpp_info_txt = text[:user_defines_index]
            if env_defines_index != -1:
                user_info_txt = text[user_defines_index:env_defines_index]
                deps_env_info_txt = text[env_defines_index:]
            else:
                user_info_txt = text[user_defines_index:]
                deps_env_info_txt = ""
        else:
            if env_defines_index != -1:
                deps_cpp_info_txt = text[:env_defines_index]
                deps_env_info_txt = text[env_defines_index:]
            else:
                deps_cpp_info_txt = text
                deps_env_info_txt = ""

            user_info_txt = ""

        deps_cpp_info = TXTGenerator._loads_cpp_info(deps_cpp_info_txt)
        deps_user_info = TXTGenerator._loads_deps_user_info(user_info_txt)
        deps_env_info = DepsEnvInfo.loads(deps_env_info_txt)
        return deps_cpp_info, deps_user_info, deps_env_info
Esempio n. 3
0
    def loads(text):
        user_defines_index = text.find("[USER_")
        env_defines_index = text.find("[ENV_")
        if user_defines_index != -1:
            deps_cpp_info_txt = text[:user_defines_index]
            if env_defines_index != -1:
                user_info_txt = text[user_defines_index:env_defines_index]
                deps_env_info_txt = text[env_defines_index:]
            else:
                user_info_txt = text[user_defines_index:]
                deps_env_info_txt = ""
        else:
            if env_defines_index != -1:
                deps_cpp_info_txt = text[:env_defines_index]
                deps_env_info_txt = text[env_defines_index:]
            else:
                deps_cpp_info_txt = text
                deps_env_info_txt = ""

            user_info_txt = ""

        deps_cpp_info = TXTGenerator._loads_cpp_info(deps_cpp_info_txt)
        deps_user_info = TXTGenerator._loads_deps_user_info(user_info_txt)
        deps_env_info = DepsEnvInfo.loads(deps_env_info_txt)
        return deps_cpp_info, deps_user_info, deps_env_info
Esempio n. 4
0
 def test_loads(self):
     # string
     text = "[ENV_libname]\nvar1=value1"
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': 'value1'})
     
     # string with spaces
     text = "[ENV_libname]\nvar1=value 1"
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': 'value 1'})
     
     # quoted string
     text = "[ENV_libname]\nvar1=\"value 1\""
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': '\"value 1\"'})
     
     # quoted string
     text = "[ENV_libname]\nvar1='value 1'"
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': '\'value 1\''})
     
     # number
     text = "[ENV_libname]\nvar1=123"
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': '123'})
     
     # empty
     text = "[ENV_libname]\nvar1="
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': ''})
     
     # mixed
     text = "[ENV_libname]\nvar1=value1\nvar2=\nvar3=\"value3\""
     ret = DepsEnvInfo.loads(text)
     self.assertDictEqual(ret.vars, {'var1': 'value1', 'var2': '', 'var3': '\"value3\"'})
Esempio n. 5
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:]))
Esempio n. 6
0
    def pythonpath_test(self):
        """
        Check PYTHONPATH env variable
        """
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues.loads("PYTHONPATH=[1,2,three]"))
        conanfile.deps_env_info = DepsEnvInfo.loads(
            '[ENV_A]\nPYTHONPATH=["DepAPath"]\n[ENV_B]\nPYTHONPATH=["DepBPath"]'
        )
        gen = VirtualEnvPythonGenerator(conanfile)
        gen.output_path = "not-used"
        content = gen.content

        self.assertIn('PYTHONPATH="1":"2":"three":"DepAPath":"DepBPath"${PYTHONPATH+:$PYTHONPATH}',
                      content["environment_run_python.sh.env"])
Esempio n. 7
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))