Example #1
0
def _load_export_conanfile(conanfile_path, output, name, version):
    conanfile = load_conanfile_class(conanfile_path)

    for field in ["url", "license", "description"]:
        field_value = getattr(conanfile, field, None)
        if not field_value:
            output.warn("Conanfile doesn't have '%s'.\n"
                        "It is recommended to add it as attribute" % field)

    try:
        # Exports is the only object field, we need to do this, because conan export needs it
        conanfile.exports = create_exports(conanfile)
        conanfile.exports_sources = create_exports_sources(conanfile)
    except Exception as e:  # re-raise with file name
        raise ConanException("%s: %s" % (conanfile_path, str(e)))

    # check name and version were specified
    if not conanfile.name:
        if name:
            conanfile.name = name
        else:
            raise ConanException("conanfile didn't specify name")
    elif name and name != conanfile.name:
        raise ConanException("Package recipe exported with name %s!=%s" % (name, conanfile.name))

    if not conanfile.version:
        if version:
            conanfile.version = version
        else:
            raise ConanException("conanfile didn't specify version")
    elif version and version != conanfile.version:
        raise ConanException("Package recipe exported with version %s!=%s"
                             % (version, conanfile.version))

    return conanfile
Example #2
0
def load_export_conanfile(conanfile_path, output):
    conanfile = load_conanfile_class(conanfile_path)

    for field in ["url", "license", "description"]:
        field_value = getattr(conanfile, field, None)
        if not field_value:
            output.warn("Conanfile doesn't have '%s'.\n"
                        "It is recommended to add it as attribute" % field)
    if getattr(conanfile, "conan_info", None):
        output.warn(
            "conan_info() method is deprecated, use package_id() instead")

    try:
        # Exports is the only object field, we need to do this, because conan export needs it
        conanfile.exports = create_exports(conanfile)
        conanfile.exports_sources = create_exports_sources(conanfile)
    except Exception as e:  # re-raise with file name
        raise ConanException("%s: %s" % (conanfile_path, str(e)))

    # check name and version were specified

    if not hasattr(conanfile, "name") or not conanfile.name:
        raise ConanException("conanfile didn't specify name")
    if not hasattr(conanfile, "version") or not conanfile.version:
        raise ConanException("conanfile didn't specify version")

    return conanfile
Example #3
0
def load_export_conanfile(conanfile_path, output):
    conanfile = load_conanfile_class(conanfile_path)

    for field in ["url", "license", "description"]:
        field_value = getattr(conanfile, field, None)
        if not field_value:
            output.warn("Conanfile doesn't have '%s'.\n"
                        "It is recommended to add it as attribute" % field)
    if getattr(conanfile, "conan_info", None):
        output.warn("conan_info() method is deprecated, use package_id() instead")

    try:
        # Exports is the only object field, we need to do this, because conan export needs it
        conanfile.exports = create_exports(conanfile)
        conanfile.exports_sources = create_exports_sources(conanfile)
    except Exception as e:  # re-raise with file name
        raise ConanException("%s: %s" % (conanfile_path, str(e)))

    # check name and version were specified

    if not hasattr(conanfile, "name") or not conanfile.name:
        raise ConanException("conanfile didn't specify name")
    if not hasattr(conanfile, "version") or not conanfile.version:
        raise ConanException("conanfile didn't specify version")

    return conanfile
Example #4
0
def load_cf_class(path, conan_api):
    client_version = get_client_version()
    client_version = Version(client_version)
    if client_version < Version("1.7.0"):
        from conans.client.loader_parse import load_conanfile_class
        return load_conanfile_class(path)
    elif client_version < Version("1.14.0"):
        return conan_api._loader.load_class(path)
    elif client_version < Version("1.15.0"):
        remotes = conan_api._cache.registry.remotes.list
        for remote in remotes:
            conan_api.python_requires.enable_remotes(remote_name=remote)
        return conan_api._loader.load_class(path)
    elif client_version < Version("1.16.0"):
        remotes = conan_api._cache.registry.load_remotes()
        conan_api.python_requires.enable_remotes(remotes=remotes)
        return conan_api._loader.load_class(path)
    elif client_version < Version("1.18.0"):
        remotes = conan_api._cache.registry.load_remotes()
        conan_api._python_requires.enable_remotes(remotes=remotes)
        return conan_api._loader.load_class(path)
    else:
        if not conan_api.app:
            conan_api.create_app()
        remotes = conan_api.app.cache.registry.load_remotes()
        conan_api.app.python_requires.enable_remotes(remotes=remotes)
        conan_api.app.pyreq_loader.enable_remotes(remotes=remotes)
        if client_version < Version("1.20.0"):
            return conan_api.app.loader.load_class(path)
        elif client_version < Version("1.21.0"):
            return conan_api.app.loader.load_basic(path)
        else:
            return conan_api.app.loader.load_named(path, None, None, None,
                                                   None)
Example #5
0
def confirm(files):
    conanfile = load_conanfile_class(os.path.join(__dir__, 'conanfile.py'))
    m.info('''
    version: %s bumped. the following files has been modified, please verify.    
    ''' % conanfile.version)

    res = prompt('commit this change(yes) or rollback (no)?', ['yes', 'no'])
    if res == 'yes':

        call('git commit -a -m "bumps to version %s"' % conanfile.version)
        call('git tag v{0} -m "bumps to version {0}"'.format(
            conanfile.version))
        m.success('version %s has been bumped.' % conanfile.version)
        m.info('''
        Now we will push the commit to remote
        ''')
        os.system('git push')
        m.info('''
        Now we will push the commit and tags to remote
        ''')
        os.system('git push --tags')

        m.warn('DO NOT forget change the branch to dev version.')

    else:
        for filename in files:
            call('git checkout -- %s' % filename)
        m.warn('version bump canceled, all changed file reverted.')
Example #6
0
    def copy(self, reference, package_ids, username, channel, force=False):
        """ Copy or move conanfile (exported) and packages to another user and or channel
        @param reference: ConanFileReference containing the packages to be moved
        @param package_ids: list of ids or [] for all list
        @param username: Destination username
        @param channel: Destination channel
        @param remote: install only from that remote
        """
        # It is necessary to make sure the sources are complete before proceeding
        remote_proxy = ConanProxy(self._client_cache, self._user_io,
                                  self._remote_manager, None)

        # Now we can actually copy
        conan_file_path = self._client_cache.conanfile(reference)
        conanfile = load_conanfile_class(conan_file_path)
        remote_proxy.complete_recipe_sources(reference,
                                             short_paths=conanfile.short_paths)
        copier = PackageCopier(self._client_cache, self._user_io,
                               conanfile.short_paths)
        if not package_ids:
            packages = self._client_cache.packages(reference)
            if os.path.exists(packages):
                package_ids = os.listdir(packages)
            else:
                package_ids = []
        copier.copy(reference, package_ids, username, channel, force)
Example #7
0
    def package(self, reference, package_id):
        # Package paths
        conan_file_path = self._client_cache.conanfile(reference)
        if not os.path.exists(conan_file_path):
            raise ConanException("Package recipe '%s' does not exist" %
                                 str(reference))

        conanfile = load_conanfile_class(conan_file_path)
        if hasattr(conanfile, "build_id"):
            raise ConanException(
                "package command does not support recipes with 'build_id'\n"
                "To repackage them use 'conan install'")

        if not package_id:
            packages = [
                PackageReference(reference, packid)
                for packid in self._client_cache.conan_builds(reference)
            ]
            if not packages:
                raise NotFoundException(
                    "%s: Package recipe has not been built locally\n"
                    "Please read the 'conan package' command help\n"
                    "Use 'conan install' or 'conan test_package' to build and "
                    "create binaries" % str(reference))
        else:
            packages = [PackageReference(reference, package_id)]

        package_source_folder = self._client_cache.source(
            reference, conanfile.short_paths)
        for package_reference in packages:
            build_folder = self._client_cache.build(package_reference,
                                                    short_paths=None)
            if not os.path.exists(build_folder):
                raise NotFoundException(
                    "%s: Package binary '%s' folder doesn't exist\n"
                    "Please read the 'conan package' command help\n"
                    "Use 'conan install' or 'conan test_package' to build and "
                    "create binaries" %
                    (str(reference), package_reference.package_id))
            # The package already exist, we can use short_paths if they were defined
            package_folder = self._client_cache.package(package_reference,
                                                        short_paths=None)
            # Will read current conaninfo with specified options and load conanfile with them
            output = ScopedOutput(str(reference), self._user_io.out)
            output.info("Re-packaging %s" % package_reference.package_id)
            conanfile = load_consumer_conanfile(conan_file_path,
                                                build_folder,
                                                self._client_cache.settings,
                                                self._runner,
                                                output,
                                                reference=reference)
            rmdir(package_folder)
            if getattr(conanfile, 'no_copy_source', False):
                source_folder = package_source_folder
            else:
                source_folder = build_folder
            with environment_append(conanfile.env):
                packager.create_package(conanfile, source_folder, build_folder,
                                        package_folder, output)
Example #8
0
def _prepare_sources(client_cache, user_io, remote_manager, reference):
    remote_proxy = ConanProxy(client_cache, user_io, remote_manager, None)
    conan_file_path = client_cache.conanfile(reference)
    conanfile = load_conanfile_class(conan_file_path)
    remote_proxy.complete_recipe_sources(conanfile,
                                         reference,
                                         short_paths=conanfile.short_paths)
    return conanfile.short_paths
Example #9
0
    def export_pkg(self,
                   path,
                   name,
                   channel,
                   source_folder=None,
                   build_folder=None,
                   install_folder=None,
                   profile_name=None,
                   settings=None,
                   options=None,
                   env=None,
                   force=False,
                   user=None,
                   version=None):

        settings = settings or []
        options = options or []
        env = env or []
        cwd = os.getcwd()

        # Checks that info files exists if the install folder is specified
        self._validate_can_read_infos(install_folder, cwd)

        path = self._abs_relative_to(path, cwd)
        build_folder = self._abs_relative_to(build_folder, cwd, default=cwd)
        install_folder = self._abs_relative_to(install_folder,
                                               cwd,
                                               default=build_folder)
        source_folder = self._abs_relative_to(source_folder,
                                              cwd,
                                              default=build_folder)

        # Checks that no both settings and info files are specified
        self._validate_one_settings_source(install_folder, profile_name,
                                           settings, options, env)

        profile = self._get_profile(profile_name, settings, options, env, cwd,
                                    install_folder)
        conanfile_abs_path = self._get_conanfile_path(path, "conanfile.py")
        conanfile = load_conanfile_class(conanfile_abs_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")
        self._manager.export(user, channel, path, name=name, version=version)

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

        reference = ConanFileReference(name, version, user, channel)
        self._manager.export_pkg(reference,
                                 source_folder=source_folder,
                                 build_folder=build_folder,
                                 install_folder=install_folder,
                                 profile=profile,
                                 force=force)
Example #10
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 #11
0
    def _get_recipe(self, conan_reference):
        output = ScopedOutput(str(conan_reference), self._out)

        # check if it is in disk
        conanfile_path = self._client_cache.conanfile(conan_reference)

        if os.path.exists(conanfile_path):
            log_recipe_got_from_local_cache(conan_reference)
            if self._check_updates:
                ret = self.update_available(conan_reference)
                if ret != 0:  # Found and not equal
                    remote, ref_remote = self._get_remote(conan_reference)
                    if ret == 1:
                        if not self._update:
                            if remote != ref_remote:  # Forced new remote
                                output.warn(
                                    "There is a new conanfile in '%s' remote. "
                                    "Execute 'install -u -r %s' to update it."
                                    % (remote.name, remote.name))
                            else:
                                output.warn(
                                    "There is a new conanfile in '%s' remote. "
                                    "Execute 'install -u' to update it." %
                                    remote.name)
                            output.warn("Refused to install!")
                        else:
                            export_path = self._client_cache.export(
                                conan_reference)
                            DiskRemover(
                                self._client_cache).remove(conan_reference)
                            output.info("Retrieving from remote '%s'..." %
                                        remote.name)
                            self._remote_manager.get_recipe(
                                conan_reference, export_path, remote)
                            output.info("Updated!")
                    elif ret == -1:
                        if not self._update:
                            output.info("Current conanfile is newer "
                                        "than %s's one" % remote.name)
                        else:
                            output.error(
                                "Current conanfile is newer than %s's one. "
                                "Run 'conan remove %s' and run install again "
                                "to replace it." %
                                (remote.name, conan_reference))

        else:
            self._retrieve_recipe(conan_reference, output)

        if self._manifest_manager:
            # Just make sure that the recipe sources are there to check
            conanfile = load_conanfile_class(conanfile_path)
            self.get_recipe_sources(conan_reference, conanfile.short_paths)
            remote = self._registry.get_ref(conan_reference)
            self._manifest_manager.check_recipe(conan_reference, remote)

        return conanfile_path
Example #12
0
    def check_reference(self, conan_reference):
        try:
            conanfile_path = self._paths.conanfile(conan_reference)
            conan_file = load_conanfile_class(conanfile_path)
        except NotFoundException:
            raise NotFoundException("There is no local conanfile exported as %s"
                                    % str(conan_reference))

        # Can't use build_policy_always here because it's not loaded (only load_class)
        if conan_file.build_policy == "always":
            raise ConanException("Conanfile has build_policy='always', "
                                 "no packages can be uploaded")
Example #13
0
def build():
    n = get_build_number()
    conanfile = load_conanfile_class(os.path.join(__dir__, 'conanfile.py'))
    version = conanfile.version
    CONAN_STABLE_CHANNEL = None

    if n == 0:
        CONAN_CHANNEL = 'stable'
        CONAN_UPLOAD_ONLY_WHEN_STABLE = True
    else:
        version = '%s.%d' % (version, n)
        CONAN_CHANNEL = 'testing'
        CONAN_UPLOAD_ONLY_WHEN_STABLE = False
        CONAN_STABLE_CHANNEL = 'testing'
        update_version(version)

    CONAN_UPLOAD = 'https://api.bintray.com/conan/%s/%s' % (CONAN_USERNAME,
                                                            CONAN_CHANNEL)

    builder = ConanMultiPackager(
        channel=CONAN_CHANNEL,
        upload_only_when_stable=CONAN_UPLOAD_ONLY_WHEN_STABLE,
        upload=CONAN_UPLOAD,
        username=CONAN_USERNAME,
        stable_channel=CONAN_STABLE_CHANNEL)

    builder.add_common_builds()
    builds = []
    for settings, options, env_vars, build_requires, reference in builder.items:
        # dynamic only
        if not options["libwebstreamer:shared"]:
            continue
        # release only
        if settings["build_type"] == "Debug":
            continue

        # Visual Sutido 2017 only
        if platform.system() == "Windows":
            if settings["compiler"] == "Visual Studio":
                if settings["compiler.version"] == '14':
                    builds.append(
                        [settings, options, env_vars, build_requires])
        elif platform.system() == "Linux":
            if settings["compiler"] == "gcc":
                if settings["compiler.version"] == '4.9' and settings[
                        "arch"] == 'x86_64':
                    builds.append([
                        settings, options, {
                            'DEPENDENT_BINTRAY_REPO': DEPENDENT_BINTRAY_REPO
                        }, build_requires
                    ])
    builder.builds = builds
    builder.run()
Example #14
0
    def check_reference(self, conan_reference):
        try:
            conanfile_path = self._paths.conanfile(conan_reference)
            conan_file = load_conanfile_class(conanfile_path)
        except NotFoundException:
            raise NotFoundException("There is no local conanfile exported as %s"
                                    % str(conan_reference))

        # Can't use build_policy_always here because it's not loaded (only load_class)
        if conan_file.build_policy == "always":
            raise ConanException("Conanfile has build_policy='always', "
                                 "no packages can be uploaded")
Example #15
0
def download_binaries(reference, package_ids, client_cache, remote_manager, remote, output, recorder):
    conanfile_path = client_cache.conanfile(reference)
    if not os.path.exists(conanfile_path):
        raise Exception("Download recipe first")
    conanfile = load_conanfile_class(conanfile_path)
    short_paths = conanfile.short_paths

    for package_id in package_ids:
        package_ref = PackageReference(reference, package_id)
        package_folder = client_cache.package(package_ref, short_paths=short_paths)
        output.info("Downloading %s" % str(package_ref))
        remote_manager.get_package(package_ref, package_folder, remote, output, recorder)
Example #16
0
    def _get_recipe(self, conan_reference, check_updates, update):
        output = ScopedOutput(str(conan_reference), self._out)
        check_updates = check_updates or update
        # check if it is in disk
        conanfile_path = self._client_cache.conanfile(conan_reference)

        if os.path.exists(conanfile_path):
            if check_updates:
                ret = self.update_available(conan_reference)
                if ret != 0:  # Found and not equal
                    remote, ref_remote = self._get_remote(conan_reference)
                    if ret == 1:
                        if not update:
                            if remote != ref_remote:  # Forced new remote
                                output.warn("There is a new conanfile in '%s' remote. "
                                            "Execute 'install -u -r %s' to update it."
                                            % (remote.name, remote.name))
                            else:
                                output.warn("There is a new conanfile in '%s' remote. "
                                            "Execute 'install -u' to update it."
                                            % remote.name)
                            output.warn("Refused to install!")
                        else:
                            DiskRemover(self._client_cache).remove(conan_reference)
                            output.info("Retrieving from remote '%s'..." % remote.name)
                            self._remote_manager.get_recipe(conan_reference, remote)

                            output.info("Updated!")
                    elif ret == -1:
                        if not update:
                            output.info("Current conanfile is newer than %s's one" % remote.name)
                        else:
                            output.error("Current conanfile is newer than %s's one. "
                                         "Run 'conan remove %s' and run install again "
                                         "to replace it." % (remote.name, conan_reference))

            log_recipe_got_from_local_cache(conan_reference)
            self._recorder.recipe_fetched_from_cache(conan_reference)

        else:
            self._retrieve_recipe(conan_reference, output)

        if self._manifest_manager:
            # Just make sure that the recipe sources are there to check
            conanfile = load_conanfile_class(conanfile_path)
            complete_recipe_sources(self._remote_manager, self._client_cache, self._registry,
                                    conanfile, conan_reference)

            remote = self._registry.get_ref(conan_reference)
            self._manifest_manager.check_recipe(conan_reference, remote)

        return conanfile_path
Example #17
0
    def add_common_builds(self, shared_option_name=None, pure_c=True,
                          dll_with_static_runtime=False, reference=None):

        if shared_option_name is None:
            if os.path.exists("conanfile.py"):
                conanfile = load_conanfile_class("./conanfile.py")
                if hasattr(conanfile, "options") and "shared" in conanfile.options:
                    shared_option_name = "%s:shared" % self.reference.name

        tmp = self.build_generator.get_builds(pure_c, shared_option_name, dll_with_static_runtime,
                                              reference or self.reference)

        self._builds.extend(tmp)
Example #18
0
 def download_packages(self, reference, package_ids):
     assert(isinstance(package_ids, list))
     remote, _ = self._get_remote(reference)
     export_path = self._client_cache.export(reference)
     self._remote_manager.get_recipe(reference, export_path, remote)
     conanfile_path = self._client_cache.conanfile(reference)
     conanfile = load_conanfile_class(conanfile_path)
     short_paths = conanfile.short_paths
     self._registry.set_ref(reference, remote)
     output = ScopedOutput(str(reference), self._out)
     for package_id in package_ids:
         package_ref = PackageReference(reference, package_id)
         package_folder = self._client_cache.package(package_ref, short_paths=short_paths)
         self._retrieve_remote_package(package_ref, package_folder, output, remote)
Example #19
0
 def download_packages(self, reference, package_ids):
     assert(isinstance(package_ids, list))
     remote, _ = self._get_remote(reference)
     export_path = self._client_cache.export(reference)
     self._remote_manager.get_recipe(reference, export_path, remote)
     conanfile_path = self._client_cache.conanfile(reference)
     conanfile = load_conanfile_class(conanfile_path)
     short_paths = conanfile.short_paths
     self._registry.set_ref(reference, remote)
     output = ScopedOutput(str(reference), self._out)
     for package_id in package_ids:
         package_ref = PackageReference(reference, package_id)
         package_folder = self._client_cache.package(package_ref, short_paths=short_paths)
         self._out.info("Downloading %s" % str(package_ref))
         self._retrieve_remote_package(package_ref, package_folder, output, remote)
Example #20
0
 def _upload_recipe(self, conan_reference, retry, retry_wait, skip_upload, no_overwrite, remote):
     conan_file_path = self._client_cache.conanfile(conan_reference)
     current_remote = self._registry.get_ref(conan_reference)
     if remote != current_remote:
         conanfile = load_conanfile_class(conan_file_path)
         complete_recipe_sources(self._remote_manager, self._client_cache, self._registry,
                                 conanfile, conan_reference)
         ignore_deleted_file = None
     else:
         ignore_deleted_file = EXPORT_SOURCES_TGZ_NAME
     result = self._remote_manager.upload_recipe(conan_reference, remote, retry, retry_wait,
                                                 ignore_deleted_file=ignore_deleted_file,
                                                 skip_upload=skip_upload,
                                                 no_overwrite=no_overwrite)
     return result
Example #21
0
    def load_conan(self,
                   conanfile_path,
                   output,
                   consumer=False,
                   reference=None):
        """ loads a ConanFile object from the given file
        """
        result = load_conanfile_class(conanfile_path)
        try:
            # Prepare the settings for the loaded conanfile
            # Mixing the global settings with the specified for that name if exist
            tmp_settings = self._settings.copy()
            if self._package_settings and result.name in self._package_settings:
                # Update the values, keeping old ones (confusing assign)
                values_tuple = self._package_settings[result.name]
                tmp_settings.values = Values.from_list(values_tuple)

            if reference:
                result.name = reference.name
                result.version = reference.version
                user, channel = reference.user, reference.channel
            else:
                user, channel = None, None

            # Instance the conanfile
            result = result(output, self._runner, tmp_settings,
                            os.path.dirname(conanfile_path), user, channel)

            # Assign environment
            result._env_values.update(self._env_values)

            if consumer:
                self._user_options.descope_options(result.name)
                result.options.initialize_upstream(self._user_options)
                self._user_options.clear_unscoped_options()
                # If this is the consumer project, it has no name
                result.scope = self._scopes.package_scope()
            else:
                result.scope = self._scopes.package_scope(result.name)
                result.in_local_cache = True

            if consumer or (self.dev_reference
                            and self.dev_reference == reference):
                result.develop = True

            return result
        except Exception as e:  # re-raise with file name
            raise ConanException("%s: %s" % (conanfile_path, str(e)))
    def __init__(self):
        conanfile_path = os.path.join(os.getcwd(), "conanfile.py")
        self.conanfile = load_conanfile_class(conanfile_path)

        self.options = self.conanfile.options
        self.default_options = {}

        default_options = self.conanfile.default_options
        for dopt in default_options:
            key, value = dopt.split("=")
            self.default_options[key] = value

        self.user = None
        self.channel = None

        self.custom_content = 'This is additional text to insert into the README.'
Example #23
0
def hint():
    conanfile = load_conanfile_class(os.path.join(__dir__,'conanfile.py'))
    m.writeln('')
    m.writeln('WE WILL BUMP THIS REPO TO NEW VERSION AND TAG IT.',
                   Color.BRIGHT_MAGENTA)
    m.writeln('current version : %s\n'%conanfile.version)

    m.info('[major] => %s'%semver.inc(conanfile.version,'major',loose=True))
    m.info('[minor] => %s'%semver.inc(conanfile.version,'minor',loose=True))
    m.info('[patch] => %s'%semver.inc(conanfile.version,'patch',loose=True))
    m.info('[cancel] cancel the version bump\n')
    res = prompt('which version to bump ?',['major','minor','patch','cancel'])
    if res == 'cancel':
        m.warn('you have cancel this version bumping.')
        return None
    return semver.inc(conanfile.version,res,loose=True)
Example #24
0
    def package(self, reference, package_id):
        # Package paths
        conan_file_path = self._client_cache.conanfile(reference)
        if not os.path.exists(conan_file_path):
            raise ConanException("Package recipe '%s' does not exist" % str(reference))

        conanfile = load_conanfile_class(conan_file_path)
        if hasattr(conanfile, "build_id"):
            raise ConanException("package command does not support recipes with 'build_id'\n"
                                 "To repackage them use 'conan install'")

        if not package_id:
            packages = [PackageReference(reference, packid)
                        for packid in self._client_cache.conan_builds(reference)]
            if not packages:
                raise NotFoundException("%s: Package recipe has not been built locally\n"
                                        "Please read the 'conan package' command help\n"
                                        "Use 'conan install' or 'conan test_package' to build and "
                                        "create binaries" % str(reference))
        else:
            packages = [PackageReference(reference, package_id)]

        package_source_folder = self._client_cache.source(reference, conanfile.short_paths)
        for package_reference in packages:
            build_folder = self._client_cache.build(package_reference, short_paths=None)
            if not os.path.exists(build_folder):
                raise NotFoundException("%s: Package binary '%s' folder doesn't exist\n"
                                        "Please read the 'conan package' command help\n"
                                        "Use 'conan install' or 'conan test_package' to build and "
                                        "create binaries"
                                        % (str(reference), package_reference.package_id))
            # The package already exist, we can use short_paths if they were defined
            package_folder = self._client_cache.package(package_reference, short_paths=None)
            # Will read current conaninfo with specified options and load conanfile with them
            output = ScopedOutput(str(reference), self._user_io.out)
            output.info("Re-packaging %s" % package_reference.package_id)
            conanfile = load_consumer_conanfile(conan_file_path, build_folder,
                                                self._client_cache.settings,
                                                self._runner, output, reference)
            rmdir(package_folder)
            if getattr(conanfile, 'no_copy_source', False):
                source_folder = package_source_folder
            else:
                source_folder = build_folder
            with environment_append(conanfile.env):
                packager.create_package(conanfile, source_folder, build_folder, package_folder,
                                        output)
Example #25
0
 def download_packages(self, reference, package_ids):
     assert(isinstance(package_ids, list))
     remote, _ = self._get_remote(reference)
     conanfile_path = self._client_cache.conanfile(reference)
     if not os.path.exists(conanfile_path):
         raise Exception("Download recipe first")
     conanfile = load_conanfile_class(conanfile_path)
     # FIXME: This is a hack to provide a info object in case it fails and raise_package_not_found_error doesnt fail
     conanfile.info = ConanInfo.loads("")
     short_paths = conanfile.short_paths
     self._registry.set_ref(reference, remote)
     output = ScopedOutput(str(reference), self._out)
     for package_id in package_ids:
         package_ref = PackageReference(reference, package_id)
         package_folder = self._client_cache.package(package_ref, short_paths=short_paths)
         self._out.info("Downloading %s" % str(package_ref))
         self._remote_manager.get_package(conanfile, package_ref, package_folder, remote, output, self._recorder)
Example #26
0
    def upload_recipe(self, conan_reference, retry, retry_wait, skip_upload):
        """ upload to defined remote in (-r=remote), to current remote
        or to default remote, in that order.
        If the remote is not set, set it
        """
        conan_file_path = self._client_cache.conanfile(conan_reference)
        conanfile = load_conanfile_class(conan_file_path)
        ignore_deleted_file = self.complete_recipe_sources(conanfile, conan_reference,
                                                           force_complete=False,
                                                           short_paths=conanfile.short_paths)
        remote, ref_remote = self._get_remote(conan_reference)

        result = self._remote_manager.upload_recipe(conan_reference, remote, retry, retry_wait,
                                                    ignore_deleted_file=ignore_deleted_file,
                                                    skip_upload=skip_upload)
        if not ref_remote and not skip_upload:
            self._registry.set_ref(conan_reference, remote)
        return result
Example #27
0
    def download(self, reference, package_ids, remote, recipe):
        """ Download conanfile and specified packages to local repository
        @param reference: ConanFileReference
        @param package_ids: Package ids or empty for download all
        @param remote: install only from that remote
        @param only_recipe: download only the recipe
        """
        assert (isinstance(reference, ConanFileReference))
        remote_proxy = ConanProxy(self._client_cache,
                                  self._user_io,
                                  self._remote_manager,
                                  remote,
                                  recorder=self._recorder)
        remote, _ = remote_proxy._get_remote()
        package = self._remote_manager.search_recipes(remote, reference, None)
        if not package:  # Search the reference first, and raise if it doesn't exist
            raise ConanException("'%s' not found in remote" % str(reference))

        # First of all download package recipe
        remote_proxy.get_recipe(reference)

        if recipe:
            return

        # Download the sources too, don't be lazy
        conan_file_path = self._client_cache.conanfile(reference)
        conanfile = load_conanfile_class(conan_file_path)
        remote_proxy.complete_recipe_sources(conanfile,
                                             reference,
                                             short_paths=conanfile.short_paths)

        if package_ids:
            remote_proxy.download_packages(reference, package_ids)
        else:
            self._user_io.out.info("Getting the complete package list "
                                   "from '%s'..." % str(reference))
            packages_props = self._remote_manager.search_packages(
                remote, reference, None)
            if not packages_props:
                output = ScopedOutput(str(reference), self._user_io.out)
                output.warn("No remote binary packages found in remote")
            else:
                remote_proxy.download_packages(reference,
                                               list(packages_props.keys()))
Example #28
0
    def inherit_short_paths_test(self):
        loader = ConanFileLoader(None, Settings(), Profile())
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = load_conanfile_class(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_conan(conanfile_path, output=None, consumer=True)
        self.assertEqual(result.short_paths, True)
Example #29
0
    def inherit_short_paths_test(self):
        loader = ConanFileLoader(None, Settings(), Profile())
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = load_conanfile_class(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_conan(conanfile_path, output=None, consumer=True)
        self.assertEqual(result.short_paths, True)
Example #30
0
    def upload(self, recorder, reference_or_pattern, package_id=None, all_packages=None,
               force=False, confirm=False, retry=0, retry_wait=0, skip_upload=False,
               integrity_check=False, no_overwrite=None, remote_name=None):
        """If package_id is provided, conan_reference_or_pattern is a ConanFileReference"""

        if package_id and not _is_a_reference(reference_or_pattern):
            raise ConanException("-p parameter only allowed with a valid recipe reference, "
                                 "not with a pattern")
        t1 = time.time()
        if package_id or _is_a_reference(reference_or_pattern):  # Upload package
            ref = ConanFileReference.loads(reference_or_pattern)
            references = [ref, ]
            confirm = True
        else:
            references = self._cache_search.search_recipes(reference_or_pattern)
            if not references:
                raise NotFoundException(("No packages found matching pattern '%s'" %
                                         reference_or_pattern))

        for conan_ref in references:
            upload = True
            if not confirm:
                msg = "Are you sure you want to upload '%s'?" % str(conan_ref)
                upload = self._user_io.request_boolean(msg)
            if upload:
                try:
                    conanfile_path = self._client_cache.conanfile(conan_ref)
                    conan_file = load_conanfile_class(conanfile_path)
                except NotFoundException:
                    raise NotFoundException(("There is no local conanfile exported as %s" %
                                          str(conan_ref)))
                if all_packages:
                    packages_ids = self._client_cache.conan_packages(conan_ref)
                elif package_id:
                    packages_ids = [package_id, ]
                else:
                    packages_ids = []
                self._upload(conan_file, conan_ref, force, packages_ids, retry, retry_wait,
                             skip_upload, integrity_check, no_overwrite, remote_name, recorder)

        logger.debug("====> Time manager upload: %f" % (time.time() - t1))
Example #31
0
    def load_conan(self, conanfile_path, output, consumer=False, reference=None, local=False):
        """ loads a ConanFile object from the given file
        """
        result = load_conanfile_class(conanfile_path)
        try:
            # Prepare the settings for the loaded conanfile
            # Mixing the global settings with the specified for that name if exist
            tmp_settings = self._settings.copy()
            if self._package_settings and result.name in self._package_settings:
                # Update the values, keeping old ones (confusing assign)
                values_tuple = self._package_settings[result.name]
                tmp_settings.values = Values.from_list(values_tuple)

            if reference:
                result.name = reference.name
                result.version = reference.version
                user, channel = reference.user, reference.channel
            else:
                user, channel = None, None

            # Instance the conanfile
            result = result(output, self._runner, tmp_settings, user, channel, local)

            # Assign environment
            result._env_values.update(self._env_values)

            if consumer:
                self._user_options.descope_options(result.name)
                result.options.initialize_upstream(self._user_options, local=local)
                self._user_options.clear_unscoped_options()
            else:
                result.in_local_cache = True

            if consumer or (self.dev_reference and self.dev_reference == reference):
                result.develop = True

            return result
        except Exception as e:  # re-raise with file name
            raise ConanException("%s: %s" % (conanfile_path, str(e)))
Example #32
0
    def add_common_builds(self,
                          shared_option_name=None,
                          pure_c=True,
                          dll_with_static_runtime=False,
                          reference=None):

        if not reference and not self.reference:
            raise Exception(
                "Specify a CONAN_REFERENCE or name and version fields in the recipe"
            )

        if shared_option_name is None:
            if os.path.exists("conanfile.py"):
                conanfile = load_conanfile_class("./conanfile.py")
                if hasattr(conanfile,
                           "options") and "shared" in conanfile.options:
                    shared_option_name = "%s:shared" % self.reference.name

        tmp = self.build_generator.get_builds(pure_c, shared_option_name,
                                              dll_with_static_runtime,
                                              reference or self.reference)
        self._builds.extend(tmp)
Example #33
0
    def copy(self, reference, package_ids, username, channel, force=False):
        """ Copy or move conanfile (exported) and packages to another user and or channel
        @param reference: ConanFileReference containing the packages to be moved
        @param package_ids: list of ids or [] for all list
        @param username: Destination username
        @param channel: Destination channel
        @param remote: install only from that remote
        """
        # It is necessary to make sure the sources are complete before proceeding
        remote_proxy = ConanProxy(self._client_cache, self._user_io, self._remote_manager, None)
        remote_proxy.complete_recipe_sources(reference)

        # Now we can actually copy
        conan_file_path = self._client_cache.conanfile(reference)
        conanfile = load_conanfile_class(conan_file_path)
        copier = PackageCopier(self._client_cache, self._user_io, conanfile.short_paths)
        if not package_ids:
            packages = self._client_cache.packages(reference)
            if os.path.exists(packages):
                package_ids = os.listdir(packages)
            else:
                package_ids = []
        copier.copy(reference, package_ids, username, channel, force)
Example #34
0
    def download(self, reference, package_ids, remote_name, recipe):
        """ Download conanfile and specified packages to local repository
        @param reference: ConanFileReference
        @param package_ids: Package ids or empty for download all
        @param remote: install only from that remote
        @param only_recipe: download only the recipe
        """
        assert(isinstance(reference, ConanFileReference))
        remote_proxy = self.get_proxy(remote_name=remote_name)
        remote, _ = remote_proxy._get_remote()
        package = self._remote_manager.search_recipes(remote, reference, None)
        if not package:  # Search the reference first, and raise if it doesn't exist
            raise ConanException("'%s' not found in remote" % str(reference))

        # First of all download package recipe
        remote_proxy.get_recipe(reference, check_updates=True, update=True)

        if recipe:
            return

        # Download the sources too, don't be lazy
        conan_file_path = self._client_cache.conanfile(reference)
        conanfile = load_conanfile_class(conan_file_path)
        complete_recipe_sources(self._remote_manager, self._client_cache, self._registry,
                                conanfile, reference)

        if package_ids:
            remote_proxy.download_packages(reference, package_ids)
        else:
            self._user_io.out.info("Getting the complete package list "
                                   "from '%s'..." % str(reference))
            packages_props = self._remote_manager.search_packages(remote, reference, None)
            if not packages_props:
                output = ScopedOutput(str(reference), self._user_io.out)
                output.warn("No remote binary packages found in remote")
            else:
                remote_proxy.download_packages(reference, list(packages_props.keys()))
Example #35
0
def download(reference, package_ids, remote_name, recipe, registry, remote_manager,
             client_cache, out, recorder):

    assert(isinstance(reference, ConanFileReference))
    output = ScopedOutput(str(reference), out)
    remote = registry.remote(remote_name) if remote_name else registry.default_remote
    package = remote_manager.search_recipes(remote, reference, None)
    if not package:  # Search the reference first, and raise if it doesn't exist
        raise ConanException("'%s' not found in remote" % str(reference))

    # First of all download package recipe
    remote_manager.get_recipe(reference, remote)
    registry.set_ref(reference, remote)

    if recipe:
        return

    # Download the sources too, don't be lazy
    conan_file_path = client_cache.conanfile(reference)
    conanfile = load_conanfile_class(conan_file_path)
    complete_recipe_sources(remote_manager, client_cache, registry,
                            conanfile, reference)

    if package_ids:
        _download_binaries(reference, package_ids, client_cache, remote_manager,
                           remote, output, recorder)
    else:
        output.info("Getting the complete package list "
                    "from '%s'..." % str(reference))
        packages_props = remote_manager.search_packages(remote, reference, None)
        if not packages_props:
            output = ScopedOutput(str(reference), out)
            output.warn("No remote binary packages found in remote")
        else:
            _download_binaries(reference, list(packages_props.keys()), client_cache,
                               remote_manager, remote, output, recorder)
Example #36
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)
Example #37
0
def load_cf_class(path, conan_api):
    if Version(client_version) < Version("1.7.0"):
        from conans.client.loader_parse import load_conanfile_class
        return load_conanfile_class(path)
    else:
        return conan_api._loader.load_class(path)
Example #38
0
    def __init__(self,
                 args=None,
                 username=None,
                 channel=None,
                 runner=None,
                 gcc_versions=None,
                 visual_versions=None,
                 visual_runtimes=None,
                 apple_clang_versions=None,
                 archs=None,
                 use_docker=None,
                 curpage=None,
                 total_pages=None,
                 docker_image=None,
                 reference=None,
                 password=None,
                 remotes=None,
                 upload=None,
                 stable_branch_pattern=None,
                 vs10_x86_64_enabled=False,
                 mingw_configurations=None,
                 stable_channel=None,
                 platform_info=None,
                 upload_retry=None,
                 clang_versions=None,
                 login_username=None,
                 upload_only_when_stable=None,
                 build_types=None,
                 skip_check_credentials=False,
                 allow_gcc_minors=False,
                 exclude_vcvars_precommand=False,
                 docker_image_skip_update=False,
                 docker_image_skip_pull=False,
                 docker_entry_script=None,
                 docker_32_images=None,
                 build_policy=None,
                 always_update_conan_in_docker=False,
                 conan_api=None,
                 client_cache=None,
                 ci_manager=None,
                 out=None,
                 test_folder=None):

        self.printer = Printer(out)
        self.printer.print_rule()
        self.printer.print_ascci_art()

        if not conan_api:
            self.conan_api, self.client_cache, _ = Conan.factory()
        else:
            self.conan_api = conan_api
            self.client_cache = client_cache

        self.ci_manager = ci_manager or CIManager(self.printer)
        self.remotes_manager = RemotesManager(self.conan_api, self.printer,
                                              remotes, upload)
        self.username = username or os.getenv("CONAN_USERNAME", None)

        if not self.username:
            raise Exception(
                "Instance ConanMultiPackage with 'username' parameter or use "
                "CONAN_USERNAME env variable")
        self.skip_check_credentials = skip_check_credentials or \
                                      os.getenv("CONAN_SKIP_CHECK_CREDENTIALS", False)

        self.auth_manager = AuthManager(
            self.conan_api,
            self.printer,
            login_username,
            password,
            default_username=self.username,
            skip_check_credentials=self.skip_check_credentials)
        self.uploader = Uploader(self.conan_api, self.remotes_manager,
                                 self.auth_manager, self.printer)

        self._builds = []
        self._named_builds = {}

        self._update_conan_in_docker = (
            always_update_conan_in_docker
            or os.getenv("CONAN_ALWAYS_UPDATE_CONAN_DOCKER", False))

        self._platform_info = platform_info or PlatformInfo()

        self.stable_branch_pattern = stable_branch_pattern or \
                                     os.getenv("CONAN_STABLE_BRANCH_PATTERN", None)
        self.specified_channel = channel or os.getenv("CONAN_CHANNEL",
                                                      "testing")
        self.specified_channel = self.specified_channel.rstrip()
        self.stable_channel = stable_channel or os.getenv(
            "CONAN_STABLE_CHANNEL", "stable")
        self.stable_channel = self.stable_channel.rstrip()
        self.channel = self._get_channel(self.specified_channel,
                                         self.stable_channel)
        self.partial_reference = reference or os.getenv(
            "CONAN_REFERENCE", None)

        if self.partial_reference:
            if "@" in self.partial_reference:
                self.reference = ConanFileReference.loads(
                    self.partial_reference)
            else:
                name, version = self.partial_reference.split("/")
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
        else:
            if not os.path.exists("conanfile.py"):
                raise Exception(
                    "Conanfile not found, specify a 'reference' parameter with name and version"
                )
            conanfile = load_conanfile_class("./conanfile.py")
            name, version = conanfile.name, conanfile.version
            if name and version:
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
            else:
                self.reference = None

        # If CONAN_DOCKER_IMAGE is speified, then use docker is True
        self.use_docker = (use_docker or os.getenv("CONAN_USE_DOCKER", False)
                           or os.getenv("CONAN_DOCKER_IMAGE",
                                        None) is not None)

        os_name = self._platform_info.system(
        ) if not self.use_docker else "Linux"
        self.build_generator = BuildGenerator(
            reference, os_name, gcc_versions, apple_clang_versions,
            clang_versions, visual_versions, visual_runtimes,
            vs10_x86_64_enabled, mingw_configurations, archs, allow_gcc_minors,
            build_types)

        build_policy = (build_policy
                        or self.ci_manager.get_commit_build_policy()
                        or os.getenv("CONAN_BUILD_POLICY", None))

        if build_policy:
            if build_policy.lower() not in ("never", "outdated", "missing"):
                raise Exception(
                    "Invalid build policy, valid values: never, outdated, missing"
                )

        self.build_policy = build_policy

        self.sudo_docker_command = ""
        if "CONAN_DOCKER_USE_SUDO" in os.environ:
            self.sudo_docker_command = "sudo -E" if get_bool_from_env(
                "CONAN_DOCKER_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_docker_command = "sudo -E"

        self.sudo_pip_command = ""
        if "CONAN_PIP_USE_SUDO" in os.environ:
            self.sudo_pip_command = "sudo -E" if get_bool_from_env(
                "CONAN_PIP_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_pip_command = "sudo -E"

        self.docker_shell = ""
        self.docker_conan_home = ""

        if self.is_wcow:
            self.docker_conan_home = "C:/Users/ContainerAdministrator"
            self.docker_shell = "cmd /C"
        else:
            self.docker_conan_home = "/home/conan"
            self.docker_shell = "/bin/sh -c"

        self.docker_platform_param = ""
        self.lcow_user_workaround = ""

        if self.is_lcow:
            self.docker_platform_param = "--platform=linux"
            # With LCOW, Docker doesn't respect USER directive in dockerfile yet
            self.lcow_user_workaround = "sudo su conan && "

        self.exclude_vcvars_precommand = (
            exclude_vcvars_precommand
            or os.getenv("CONAN_EXCLUDE_VCVARS_PRECOMMAND", False))
        self._docker_image_skip_update = (
            docker_image_skip_update
            or os.getenv("CONAN_DOCKER_IMAGE_SKIP_UPDATE", False))
        self._docker_image_skip_pull = (docker_image_skip_pull or os.getenv(
            "CONAN_DOCKER_IMAGE_SKIP_PULL", False))

        self.runner = runner or os.system
        self.output_runner = ConanOutputRunner()
        self.args = " ".join(args) if args else " ".join(sys.argv[1:])

        # Upload related variables
        self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3)

        if upload_only_when_stable is not None:
            self.upload_only_when_stable = upload_only_when_stable
        else:
            self.upload_only_when_stable = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_STABLE")

        self.docker_entry_script = docker_entry_script or os.getenv(
            "CONAN_DOCKER_ENTRY_SCRIPT")

        os.environ["CONAN_CHANNEL"] = self.channel

        # If CONAN_DOCKER_IMAGE is speified, then use docker is True
        self.use_docker = use_docker or os.getenv("CONAN_USE_DOCKER", False) or \
                          (os.getenv("CONAN_DOCKER_IMAGE", None) is not None)

        if docker_32_images is not None:
            self.docker_32_images = docker_32_images
        else:
            self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False)

        self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1)
        self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1)
        self._docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE",
                                                       None)

        self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE",
                                           "conan==%s" % client_version)
        if self.conan_pip_package in ("0", "False"):
            self.conan_pip_package = False
        self.vs10_x86_64_enabled = vs10_x86_64_enabled

        self.builds_in_current_page = []

        self.test_folder = test_folder or os.getenv("CPT_TEST_FOLDER", None)

        def valid_pair(var, value):
            return (isinstance(value, six.string_types)
                    or isinstance(value, bool) or isinstance(value, list)
                    ) and not var.startswith("_") and "password" not in var

        with self.printer.foldable_output("local_vars"):
            self.printer.print_dict({
                var: value
                for var, value in self.__dict__.items()
                if valid_pair(var, value)
            })
Example #39
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 []

        try:
            cwd = cwd or os.getcwd()
            recorder = ActionRecorder()
            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")
                cmd_export(conanfile_path, name, version, user, channel,
                           keep_source, self._user_io.out, self._client_cache)

            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)

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

            create(reference, manager, self._user_io, profile, remote, 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 #40
0
    def create(self, profile_name=None, settings=None,
               options=None, env=None, scope=None, test_folder=None, not_export=False, build=None,
               keep_source=False, verify=default_manifest_folder,
               manifests=default_manifest_folder, manifests_interactive=default_manifest_folder,
               remote=None, update=False, cwd=None,
               user=None, channel=None, name=None, version=None):

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

        if not name or not version:
            conanfile_path = os.path.join(cwd, "conanfile.py")
            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)
        # Forcing an export!
        if not not_export:
            scoped_output.highlight("Exporting package recipe")
            self._manager.export(user, channel, cwd, keep_source=keep_source, name=name,
                                 version=version)

        if build is None:  # Not specified, force build the tested library
            build = [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.profiles_path)
        self._manager.install(reference=reference,
                              current_path=cwd,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              update=update
                              )

        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:
            self._user_io.out.warn("test package folder not available, or it doesn't have "
                                   "a conanfile.py\nIt is recommended to set a 'test_package' "
                                   "while creating packages")
            return

        scoped_output.highlight("Testing with 'test_package'")
        sha = hashlib.sha1("".join(options + settings).encode()).hexdigest()
        build_folder = os.path.join(test_folder, "build", sha)
        rmdir(build_folder)

        test_conanfile = os.path.join(test_folder, CONANFILE)
        self._manager.install(inject_require=reference,
                              reference=test_folder,
                              current_path=build_folder,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              remote=remote,
                              profile=profile,
                              update=update,
                              generators=["txt"]
                              )
        self._manager.build(test_conanfile, test_folder, build_folder, package_folder=None,
                            test=str(reference))