Example #1
0
    def test_value_duplicated_None(self):
        self._save_profile(compiler_cppstd="None", cppstd="None")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        r.process_settings(self.cache)
        self.assertEqual(r.settings["compiler.cppstd"], "None")
        self.assertEqual(r.settings["cppstd"], "None")
Example #2
0
    def test_value_valid(self):
        self._save_profile(compiler_cppstd="11")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        r.process_settings(self.cache)
        self.assertEqual(r.settings["compiler.cppstd"], "11")
        self.assertNotIn("cppstd", r.settings)
Example #3
0
    def test(self,
             path,
             reference,
             profile_name=None,
             settings=None,
             options=None,
             env=None,
             remote=None,
             update=False,
             build_modes=None,
             cwd=None,
             test_build_folder=None):

        settings = settings or []
        options = options or []
        env = env or []

        conanfile_path = _get_conanfile_path(path, cwd, py=True)
        cwd = cwd or get_cwd()
        profile = profile_from_args(profile_name, settings, options, env, cwd,
                                    self._client_cache)
        reference = ConanFileReference.loads(reference)
        recorder = ActionRecorder()
        manager = self._init_manager(recorder)
        pt = PackageTester(manager, self._user_io)
        pt.install_build_and_test(conanfile_path,
                                  reference,
                                  profile,
                                  remote,
                                  update,
                                  build_modes=build_modes,
                                  test_build_folder=test_build_folder)
Example #4
0
    def install(self, path="", settings=None, options=None, env=None, scope=None,
                remote=None, werror=False, verify=None, manifests=None,
                manifests_interactive=None, build=None, profile_name=None,
                update=False, generators=None, no_imports=False, filename=None,
                install_folder=None):

        self._user_io.out.werror_active = werror

        cwd = os.getcwd()
        install_folder = self._abs_relative_to(install_folder, cwd, default=cwd)
        conanfile_folder = self._abs_relative_to(path, cwd, default=cwd)

        manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests

        profile = profile_from_args(profile_name, settings, options, env, scope, cwd,
                                    self._client_cache)

        self._manager.install(reference=conanfile_folder,
                              install_folder=install_folder,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              filename=filename,
                              update=update,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              generators=generators,
                              no_imports=no_imports)
Example #5
0
    def info_nodes_to_build(self,
                            reference,
                            build_modes,
                            settings=None,
                            options=None,
                            env=None,
                            scope=None,
                            profile_name=None,
                            filename=None,
                            remote=None,
                            check_updates=None,
                            build_folder=None):

        current_path = os.getcwd()
        try:
            reference = ConanFileReference.loads(reference)
        except:
            reference = os.path.normpath(os.path.join(current_path, reference))

        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, build_folder, self._client_cache)
        ret = self._manager.info_nodes_to_build(reference, profile, filename,
                                                build_modes, remote,
                                                check_updates)
        ref_list, project_reference = ret
        return ref_list, project_reference
Example #6
0
    def info_get_graph(self,
                       reference,
                       remote=None,
                       settings=None,
                       options=None,
                       env=None,
                       scope=None,
                       profile_name=None,
                       update=False,
                       filename=None,
                       build_folder=None):

        current_path = os.getcwd()
        try:
            reference = ConanFileReference.loads(reference)
        except:
            reference = os.path.normpath(os.path.join(current_path, reference))

        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, build_folder, self._client_cache)
        ret = self._manager.info_get_graph(reference=reference,
                                           remote=remote,
                                           profile=profile,
                                           check_updates=update,
                                           filename=filename)
        deps_graph, graph_updates_info, project_reference = ret
        return deps_graph, graph_updates_info, project_reference
Example #7
0
    def install_reference(self, reference, settings=None, options=None, env=None,
                          remote=None, verify=None, manifests=None,
                          manifests_interactive=None, build=None, profile_name=None,
                          update=False, generators=None, install_folder=None, cwd=None):

        cwd = cwd or os.getcwd()
        install_folder = _make_abs_path(install_folder, cwd)

        manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests

        profile = profile_from_args(profile_name, settings, options, env, cwd,
                                    self._client_cache)

        if not generators:  # We don't want the default txt
            generators = False

        mkdir(install_folder)
        self._manager.install(reference=reference, install_folder=install_folder, remote=remote,
                              profile=profile, build_modes=build, update=update,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              generators=generators,
                              install_reference=True)
Example #8
0
    def install_reference(self, reference, settings=None, options=None, env=None,
                          remote_name=None, verify=None, manifests=None,
                          manifests_interactive=None, build=None, profile_name=None,
                          update=False, generators=None, install_folder=None, cwd=None):

        try:
            recorder = ActionRecorder()
            cwd = cwd or os.getcwd()
            install_folder = _make_abs_path(install_folder, cwd)

            manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
            manifest_folder, manifest_interactive, manifest_verify = manifests

            profile = profile_from_args(profile_name, settings, options, env, cwd,
                                        self._client_cache)

            if not generators:  # We don't want the default txt
                generators = False

            mkdir(install_folder)
            manager = self._init_manager(recorder)
            manager.install(reference=reference, install_folder=install_folder,
                            remote_name=remote_name, profile=profile, build_modes=build,
                            update=update, manifest_folder=manifest_folder,
                            manifest_verify=manifest_verify,
                            manifest_interactive=manifest_interactive,
                            generators=generators)
            return recorder.get_info()
        except ConanException as exc:
            recorder.error = True
            exc.info = recorder.get_info()
            raise
Example #9
0
    def install(self, path="", settings=None, options=None, env=None,
                remote=None, verify=None, manifests=None,
                manifests_interactive=None, build=None, profile_name=None,
                update=False, generators=None, no_imports=False, install_folder=None, cwd=None):

        cwd = cwd or os.getcwd()
        install_folder = _make_abs_path(install_folder, cwd)
        conanfile_path = _get_conanfile_path(path, cwd, py=None)

        manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests

        profile = profile_from_args(profile_name, settings, options, env, cwd,
                                    self._client_cache)

        self._manager.install(reference=conanfile_path,
                              install_folder=install_folder,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              update=update,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              generators=generators,
                              no_imports=no_imports)
Example #10
0
    def test(self,
             path,
             profile_name=None,
             settings=None,
             options=None,
             env=None,
             remote=None,
             update=False,
             user=None,
             channel=None,
             name=None,
             version=None,
             build_modes=None):

        settings = settings or []
        options = options or []
        env = env or []
        cwd = os.getcwd()
        base_folder = self._abs_relative_to(path, cwd, default=cwd)
        conanfile_abs_path = self._get_conanfile_path(base_folder,
                                                      "conanfile.py")

        profile = profile_from_args(profile_name, settings, options, env, None,
                                    cwd, self._client_cache)

        pt = PackageTester(self._manager, self._user_io)
        pt.install_build_and_test(conanfile_abs_path,
                                  profile,
                                  name,
                                  version,
                                  user,
                                  channel,
                                  remote,
                                  update,
                                  build_modes=build_modes)
Example #11
0
    def test_no_value(self):
        self._save_profile()

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        r.process_settings(self.cache)
        self.assertNotIn("compiler.cppstd", r.settings)
        self.assertNotIn("cppstd", r.settings)
Example #12
0
    def test_value_invalid(self):
        self._save_profile(compiler_cppstd="13")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        with six.assertRaisesRegex(self, ConanException, "Invalid setting '13' is not a valid "
                                                         "'settings.compiler.cppstd' value"):
            r.process_settings(self.cache)
        self.assertNotIn("cppstd", r.settings)
Example #13
0
    def test_value_from_cppstd(self):
        self._save_profile(cppstd="11")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        with catch_deprecation_warning(self):
            r.process_settings(self.cache)
        self.assertNotIn('compiler.cppstd', r.settings)
        self.assertEqual(r.settings["cppstd"], "11")
Example #14
0
    def test_value_different(self):
        self._save_profile(cppstd="14", compiler_cppstd="11")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        with six.assertRaisesRegex(self, ConanException, "Do not use settings 'compiler.cppstd'"
                                                         " together with 'cppstd'. Use only the"
                                                         " former one"):
            with catch_deprecation_warning(self):
                r.process_settings(self.cache)
Example #15
0
    def export_pkg(self, conanfile_path, name, channel, source_folder=None, build_folder=None,
                   package_folder=None, install_folder=None, profile_name=None, settings=None,
                   options=None, env=None, force=False, user=None, version=None, cwd=None):

        settings = settings or []
        options = options or []
        env = env or []
        cwd = cwd or get_cwd()

        # Checks that info files exists if the install folder is specified
        if install_folder and not existing_info_files(_make_abs_path(install_folder, cwd)):
            raise ConanException("The specified install folder doesn't contain '%s' and '%s' "
                                 "files" % (CONANINFO, BUILD_INFO))

        conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True)

        if package_folder:
            if build_folder or source_folder:
                raise ConanException("package folder definition incompatible with build and source folders")
            package_folder = _make_abs_path(package_folder, cwd)

        build_folder = _make_abs_path(build_folder, cwd)
        install_folder = _make_abs_path(install_folder, cwd, default=build_folder)
        source_folder = _make_abs_path(source_folder, cwd, default=os.path.dirname(conanfile_path))

        # Checks that no both settings and info files are specified
        if install_folder and existing_info_files(install_folder) and \
                (profile_name or settings or options or env):
            raise ConanException("%s and %s are found, at '%s' folder, so specifying profile, "
                                 "settings, options or env is not allowed" % (CONANINFO, BUILD_INFO,
                                                                              install_folder))

        infos_present = existing_info_files(install_folder)
        if not infos_present:
            profile = profile_from_args(profile_name, settings, options, env=env,
                                        cwd=cwd, client_cache=self._client_cache)
        else:
            profile = read_conaninfo_profile(install_folder)

        conanfile = load_conanfile_class(conanfile_path)
        if (name and conanfile.name and conanfile.name != name) or \
           (version and conanfile.version and conanfile.version != version):
            raise ConanException("Specified name/version doesn't match with the "
                                 "name/version in the conanfile")
        cmd_export(conanfile_path, name, version, user, channel, False,
                   self._user_io.out, self._client_cache)

        if not (name and version):
            name = conanfile.name
            version = conanfile.version

        reference = ConanFileReference(name, version, user, channel)
        recorder = ActionRecorder()
        manager = self._init_manager(recorder)
        manager.export_pkg(reference, source_folder=source_folder, build_folder=build_folder,
                           package_folder=package_folder, install_folder=install_folder,
                           profile=profile, force=force)
Example #16
0
    def create(self, conanfile_path, name=None, version=None, user=None, channel=None,
               profile_name=None, settings=None,
               options=None, env=None, test_folder=None, not_export=False,
               build_modes=None,
               keep_source=False, keep_build=False, verify=None,
               manifests=None, manifests_interactive=None,
               remote_name=None, update=False, cwd=None, test_build_folder=None):
        """
        API method to create a conan package

        :param test_folder: default None   - looks for default 'test' or 'test_package' folder),
                                    string - test_folder path
                                    False  - disabling tests
        """
        settings = settings or []
        options = options or []
        env = env or []

        try:
            cwd = cwd or os.getcwd()
            recorder = ActionRecorder()
            conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True)

            reference, conanfile = self._loader.load_export(conanfile_path, name, version, user,
                                                            channel)

            # Make sure keep_source is set for keep_build
            keep_source = keep_source or keep_build
            # Forcing an export!
            if not not_export:
                cmd_export(conanfile_path, conanfile, reference, keep_source, self._user_io.out,
                           self._client_cache, self._plugin_manager)

            if build_modes is None:  # Not specified, force build the tested library
                build_modes = [conanfile.name]

            manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
            manifest_folder, manifest_interactive, manifest_verify = manifests
            profile = profile_from_args(profile_name, settings, options, env,
                                        cwd, self._client_cache)

            manager = self._init_manager(recorder)
            recorder.add_recipe_being_developed(reference)

            create(reference, manager, self._user_io, profile, remote_name, update, build_modes,
                   manifest_folder, manifest_verify, manifest_interactive, keep_build,
                   test_build_folder, test_folder, conanfile_path)

            return recorder.get_info()

        except ConanException as exc:
            recorder.error = True
            exc.info = recorder.get_info()
            raise
Example #17
0
    def _get_profile(self, profile_name, settings, options, env, cwd, install_folder):

        infos_present = existing_info_files(install_folder)

        if not infos_present:
            profile = profile_from_args(profile_name, settings, options, env=env, scope=None,
                                        cwd=cwd, client_cache=self._client_cache)
        else:
            profile = read_conaninfo_profile(install_folder)

        return profile
Example #18
0
    def _info_get_profile(self, reference, install_folder, profile_name, settings, options, env):
        cwd = os.getcwd()
        try:
            reference = ConanFileReference.loads(reference)
        except ConanException:
            reference = _get_conanfile_path(reference, cwd=None, py=None)
            if install_folder or not (profile_name or settings or options or env):
                # When not install folder is specified but neither any setting, we try to read the
                # info from cwd
                install_folder = _make_abs_path(install_folder, cwd)
                if existing_info_files(install_folder):
                    return reference, read_conaninfo_profile(install_folder)

        return reference, profile_from_args(profile_name, settings, options, env=env,
                                            cwd=cwd, client_cache=self._client_cache)
    def test_value_duplicated(self):
        self._save_profile(compiler_cppstd="11", cppstd="11")

        r = profile_from_args([
            "default",
        ], [], [], [], [],
                              cwd=self.tmp_folder,
                              cache=self.cache)
        with six.assertRaisesRegex(
                self, ConanException, "Do not use settings 'compiler.cppstd'"
                " together with 'cppstd'. Use only the"
                " former one."):
            r.process_settings(self.cache)
        self.assertEqual(r.settings["compiler.cppstd"], "11")
        self.assertEqual(r.settings["cppstd"], "11")
Example #20
0
    def install(self, path="", settings=None, options=None, env=None,
                remote_name=None, verify=None, manifests=None,
                manifests_interactive=None, build=None, profile_name=None,
                update=False, generators=None, no_imports=False, install_folder=None, cwd=None):

        try:
            recorder = ActionRecorder()
            cwd = cwd or os.getcwd()
            manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
            manifest_folder, manifest_interactive, manifest_verify = manifests

            profile = profile_from_args(profile_name, settings, options, env, cwd,
                                        self._client_cache)

            wspath = _make_abs_path(path, cwd)
            if install_folder:
                if os.path.isabs(install_folder):
                    wsinstall_folder = install_folder
                else:
                    wsinstall_folder = os.path.join(cwd, install_folder)
            else:
                wsinstall_folder = None
            workspace = Workspace.get_workspace(wspath, wsinstall_folder)
            if workspace:
                self._user_io.out.success("Using conanws.yml file from %s" % workspace._base_folder)
                manager = self._init_manager(recorder)
                manager.install_workspace(profile, workspace, remote_name, build, update)
                return

            install_folder = _make_abs_path(install_folder, cwd)
            conanfile_path = _get_conanfile_path(path, cwd, py=None)
            manager = self._init_manager(recorder)
            manager.install(reference=conanfile_path,
                            install_folder=install_folder,
                            remote_name=remote_name,
                            profile=profile,
                            build_modes=build,
                            update=update,
                            manifest_folder=manifest_folder,
                            manifest_verify=manifest_verify,
                            manifest_interactive=manifest_interactive,
                            generators=generators,
                            no_imports=no_imports)
            return recorder.get_info()
        except ConanException as exc:
            recorder.error = True
            exc.info = recorder.get_info()
            raise
Example #21
0
 def test_no_compiler_cppstd(self):
     # https://github.com/conan-io/conan/issues/5128
     fullpath = os.path.join(self.cache.profiles_path, "default")
     t = textwrap.dedent("""
         [settings]
         os=Macos
         arch=x86_64
         compiler=apple-clang
         compiler.libcxx=libc++
         compiler.version=10.0
         compiler.cppstd = 14
         """)
     save(self.cache.settings_path, settings_1_14_0)
     save(fullpath, t)
     r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
     with six.assertRaisesRegex(self, ConanException,
                                "'settings.compiler.cppstd' doesn't exist for 'apple-clang'"):
         r.process_settings(self.cache)
Example #22
0
    def install_reference(self,
                          reference,
                          settings=None,
                          options=None,
                          env=None,
                          scope=None,
                          remote=None,
                          werror=False,
                          verify=None,
                          manifests=None,
                          manifests_interactive=None,
                          build=None,
                          profile_name=None,
                          update=False,
                          generators=None,
                          install_folder=None):

        self._user_io.out.werror_active = werror
        cwd = os.getcwd()
        install_folder = self._abs_relative_to(install_folder,
                                               cwd,
                                               default=cwd)

        manifests = _parse_manifests_arguments(verify, manifests,
                                               manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests

        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, cwd, self._client_cache)

        if not generators:  # We don't want the default txt
            generators = False
        self._manager.install(reference=reference,
                              install_folder=install_folder,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              update=update,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              generators=generators,
                              cwd=cwd,
                              deploy=True)
Example #23
0
    def test_package(self,
                     profile_name=None,
                     settings=None,
                     options=None,
                     env=None,
                     scope=None,
                     test_folder=None,
                     not_export=False,
                     build=None,
                     keep_source=False,
                     verify=None,
                     manifests=None,
                     manifests_interactive=None,
                     remote=None,
                     update=False,
                     cwd=None,
                     user=None,
                     channel=None,
                     name=None,
                     version=None):

        self._user_io.out.warn(
            "THIS METHOD IS DEPRECATED and will be removed. "
            "Use 'conan create' to generate binary packages for a "
            "recipe. If you want to test a package you can use 'conan test' "
            "command.")

        settings = settings or []
        options = options or []
        env = env or []
        cwd = prepare_cwd(cwd)

        if name and version:
            package_name = name
            package_version = version
        else:
            conanfile_path = os.path.join(cwd, "conanfile.py")
            conanfile = load_conanfile_class(conanfile_path)
            package_name = getattr(conanfile, "name", None)
            package_version = getattr(conanfile, "version", None)
        if not package_name or not package_version:
            raise ConanException(
                "conanfile.py doesn't declare package name or version")

        test_folders = [test_folder
                        ] if test_folder else ["test_package", "test"]
        for test_folder_name in test_folders:
            test_folder = os.path.join(cwd, test_folder_name)
            test_conanfile_path = os.path.join(test_folder, "conanfile.py")
            if os.path.exists(test_conanfile_path):
                break
        else:
            raise ConanException("test folder '%s' not available, "
                                 "or it doesn't have a conanfile.py" %
                                 test_folder_name)

        sha = hashlib.sha1("".join(options + settings).encode()).hexdigest()
        build_folder = os.path.join(test_folder, "build", sha)
        rmdir(build_folder)
        # shutil.copytree(test_folder, build_folder)

        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, cwd, self._client_cache)

        loader = self._manager.get_loader(profile)
        test_conanfile = loader.load_conan(test_conanfile_path,
                                           self._user_io.out,
                                           consumer=True)

        try:
            if hasattr(test_conanfile, "requirements"):
                test_conanfile.requirements()
        except Exception as e:
            raise ConanException(
                "Error in test_package/conanfile.py requirements(). %s" %
                str(e))

        requirement = test_conanfile.requires.get(package_name)
        if requirement:
            if requirement.conan_reference.version != package_version:
                raise ConanException(
                    "package version is '%s', but test_package/conanfile "
                    "is requiring version '%s'\n"
                    "You can remove this requirement and use "
                    "'conan test_package user/channel' instead" %
                    (package_version, requirement.conan_reference.version))
            user = user or requirement.conan_reference.user
            channel = channel or requirement.conan_reference.channel

        if not user or not channel:
            raise ConanException("Please specify user and channel")
        conanfile_reference = ConanFileReference(package_name, package_version,
                                                 user, channel)

        # Forcing an export!
        if not not_export:
            self._user_io.out.info("Exporting package recipe")
            self._manager.export(user, channel, cwd, keep_source=keep_source)

        if build is None:  # Not specified, force build the tested library
            build = [package_name]

        manifests = _parse_manifests_arguments(verify, manifests,
                                               manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests
        self._manager.install(inject_require=conanfile_reference,
                              reference=test_folder,
                              install_folder=build_folder,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              update=update,
                              generators=["txt"])

        test_conanfile = os.path.join(test_folder, CONANFILE)
        self._manager.build(test_conanfile,
                            test_folder,
                            build_folder,
                            package_folder=None,
                            install_folder=build_folder,
                            test=str(conanfile_reference))
Example #24
0
    def create(self,
               profile_name=None,
               settings=None,
               options=None,
               env=None,
               scope=None,
               test_folder=None,
               not_export=False,
               build_modes=None,
               keep_source=False,
               verify=None,
               manifests=None,
               manifests_interactive=None,
               remote=None,
               update=False,
               conan_file_path=None,
               filename=None,
               user=None,
               channel=None,
               name=None,
               version=None,
               werror=False):

        settings = settings or []
        options = options or []
        env = env or []
        self._user_io.out.werror_active = werror

        cwd = os.getcwd()
        conanfile_folder = self._abs_relative_to(conan_file_path,
                                                 cwd,
                                                 default=cwd)

        if not name or not version:
            conanfile_abs_path = self._get_conanfile_path(
                conanfile_folder, filename or CONANFILE)
            conanfile = load_conanfile_class(conanfile_abs_path)
            name, version = conanfile.name, conanfile.version
            if not name or not version:
                raise ConanException(
                    "conanfile.py doesn't declare package name or version")

        reference = ConanFileReference(name, version, user, channel)
        scoped_output = ScopedOutput(str(reference), self._user_io.out)
        # Forcing an export!
        if not not_export:
            scoped_output.highlight("Exporting package recipe")
            self._manager.export(user,
                                 channel,
                                 conanfile_folder,
                                 keep_source=keep_source,
                                 name=name,
                                 version=version,
                                 filename=filename)

        if build_modes is None:  # Not specified, force build the tested library
            build_modes = [name]

        manifests = _parse_manifests_arguments(verify, manifests,
                                               manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests
        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, cwd, self._client_cache)
        self._manager.install(
            reference=reference,
            install_folder=None,  # Not output anything
            manifest_folder=manifest_folder,
            manifest_verify=manifest_verify,
            manifest_interactive=manifest_interactive,
            remote=remote,
            profile=profile,
            build_modes=build_modes,
            update=update,
            filename=filename)

        base_folder = self._abs_relative_to(conan_file_path, cwd, default=cwd)

        def get_test_conanfile_path(tf):
            """Searchs in the declared test_folder or in the standard locations"""
            test_folders = [tf] if tf else ["test_package", "test"]

            for test_folder_name in test_folders:
                test_folder = os.path.join(base_folder, test_folder_name)
                test_conanfile_path = os.path.join(test_folder, "conanfile.py")
                if os.path.exists(test_conanfile_path):
                    return test_conanfile_path
            else:
                if tf:
                    raise ConanException("test folder '%s' not available, "
                                         "or it doesn't have a conanfile.py" %
                                         tf)

        test_conanfile_path = get_test_conanfile_path(test_folder)
        if test_conanfile_path:
            pt = PackageTester(self._manager, self._user_io)
            scoped_output.highlight("Testing with 'test_package'")
            pt.install_build_and_test(test_conanfile_path, profile, name,
                                      version, user, channel, remote, update)
Example #25
0
    def create(self, conanfile_path, name=None, version=None, user=None, channel=None,
               profile_name=None, settings=None,
               options=None, env=None, test_folder=None, not_export=False,
               build_modes=None,
               keep_source=False, keep_build=False, verify=None,
               manifests=None, manifests_interactive=None,
               remote=None, update=False, cwd=None, test_build_folder=None):
        """
        API method to create a conan package

        :param test_folder: default None   - looks for default 'test' or 'test_package' folder),
                                    string - test_folder path
                                    False  - disabling tests
        """
        settings = settings or []
        options = options or []
        env = env or []

        cwd = cwd or os.getcwd()
        conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True)

        if not name or not version:
            conanfile = load_conanfile_class(conanfile_path)
            name, version = conanfile.name, conanfile.version
            if not name or not version:
                raise ConanException("conanfile.py doesn't declare package name or version")

        reference = ConanFileReference(name, version, user, channel)
        scoped_output = ScopedOutput(str(reference), self._user_io.out)
        # Make sure keep_source is set for keep_build
        if keep_build:
            keep_source = True
        # Forcing an export!
        if not not_export:
            scoped_output.highlight("Exporting package recipe")
            self._manager.export(conanfile_path, name, version, user, channel, keep_source)

        if build_modes is None:  # Not specified, force build the tested library
            build_modes = [name]

        manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests
        profile = profile_from_args(profile_name, settings, options, env,
                                    cwd, self._client_cache)

        def get_test_conanfile_path(tf):
            """Searches in the declared test_folder or in the standard locations"""

            if tf is False:
                # Look up for testing conanfile can be disabled if tf (test folder) is False
                return None

            test_folders = [tf] if tf else ["test_package", "test"]
            base_folder = os.path.dirname(conanfile_path)
            for test_folder_name in test_folders:
                test_folder = os.path.join(base_folder, test_folder_name)
                test_conanfile_path = os.path.join(test_folder, "conanfile.py")
                if os.path.exists(test_conanfile_path):
                    return test_conanfile_path
            else:
                if tf:
                    raise ConanException("test folder '%s' not available, "
                                         "or it doesn't have a conanfile.py" % tf)

        test_conanfile_path = get_test_conanfile_path(test_folder)

        if test_conanfile_path:
            pt = PackageTester(self._manager, self._user_io)
            pt.install_build_and_test(test_conanfile_path, reference, profile,
                                      remote, update, build_modes=build_modes,
                                      manifest_folder=manifest_folder,
                                      manifest_verify=manifest_verify,
                                      manifest_interactive=manifest_interactive,
                                      keep_build=keep_build,
                                      test_build_folder=test_build_folder)
        else:
            self._manager.install(reference=reference,
                                  install_folder=None,  # Not output anything
                                  manifest_folder=manifest_folder,
                                  manifest_verify=manifest_verify,
                                  manifest_interactive=manifest_interactive,
                                  remote=remote,
                                  profile=profile,
                                  build_modes=build_modes,
                                  update=update,
                                  keep_build=keep_build)