conan-package-tools icon indicating copy to clipboard operation
conan-package-tools copied to clipboard

Add support for switching between non user/channel and user/channel mode

Open tonka3000 opened this issue 3 years ago • 3 comments

Hey 👋 ,

I build conan center index recipes in-house, so that we get all our required build for our compilers. This works great, but one thing always occur.

The build script looks like

import os
import shutil
from cpt.packager import ConanMultiPackager
from conans import tools

def create_clean_build_folder(folder):
    if os.path.exists(folder):
        shutil.rmtree(folder)
    os.makedirs(folder)

if __name__ == "__main__":
    url = "https://github.com/conan-io/conan-center-index/archive/master.zip"
    recipe_folder = "conan-center-index-master/recipes/zlib/1.2.8"
    build_folder = "_build"
    reference="zlib/1.2.8@"

    tools.rmdir(build_folder)
    os.makedirs(build_folder)

    # download the conan index as zip and extract to a sub directory
    tools.get(
        url,
        filename="conan-index.zip",
        destination=build_folder,
        pattern=os.path.join(recipe_folder, "*"), # extract just zlib/1.2.8
        retry=2,
        retry_wait=5
    )
    conanfile = os.path.join(build_folder, recipe_folder, "conanfile.py")

    # normal cpt build, but with the downloaded conanfile
    builder = ConanMultiPackager(conanfile=conanfile, reference=reference)
    builder.add_common_builds()
    builder.run()

When we do this in the past we used channels to switch between channels. A half year ago we want to have the same reference as used in conan center index mypackage/0.1.2@ without channel and username and only upload on stable. This approach works but is not optimal for testing, because we need from time to time that the user can try out the new testing branch.

We think about using following approach in the near future:

stable branch: mypackage/0.1.2@ testing branch: mypackage/0.1.2@company/testing

We can do this in every build script and it would work but we have to do this over and over again. It would be nice when cpt would support that as well. I've check the source code and see that the actual impl. would not allow that because when it sees the @ in the reference it don't ask for the username/channel.

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(os.path.join(self.cwd, self.conanfile)):
                raise Exception("Conanfile not found, specify a 'reference' "
                                "parameter with name and version")

I think with a minimal modification this could be support.

What are you thinking about that?

Greetings Michael

tonka3000 avatar Mar 12 '21 11:03 tonka3000

It's not clear for me your problem... What do you propose?

uilianries avatar Mar 15 '21 14:03 uilianries

Hey @uilianries ,

I want to be able to use cpt to switch between

stable branch: mypackage/0.1.2@ testing branch: mypackage/0.1.2@company/testing

by just using cpt environment variables

variables:
  CONAN_REFERENCE: "mypackage/0.1.0"
  CONAN_USERNAME: "company"
  CONAN_CHANNEL: "testing"
  CONAN_STABLE_BRANCH_PATTERN: "main"
  CONAN_STABLE_CHANNEL: "" # <= this seems not to work right now

tonka3000 avatar Mar 26 '21 08:03 tonka3000

@tonka3000 Now it's much clear. Thank you!

uilianries avatar Mar 29 '21 18:03 uilianries