Skip to content

Commit

Permalink
Feature/support require override (#597)
Browse files Browse the repository at this point in the history
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
boussaffawalid and uilianries authored Mar 30, 2022
1 parent 6069d0e commit 507826a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ Using **CONAN_CLANG_VERSIONS** env variable in Travis ci or Appveyor:
- ["pattern\*", "another_pattern\*"]: will build only the packages with the reference matching these patterns. Equivalent to `--build pattern* --build another_pattern*`
- ["pattern\*", "outdated"]: `--build pattern* --build outdated`
Check [Conan Build policies](https://docs.conan.io/en/latest/mastering/policies.html) for more details.
- **require_overrides** List containing overrides requirement to the consumer conanfile. e.j ["foo/0.1@user/channel", "bar/1.2@bar/channel"]
- **test_folder**: Custom test folder consumed by Conan create, e.j .conan/test_package
- **lockfile**: Custom conan lockfile to be used, e.j. conan.lock. Default [None]
- **conanfile**: Custom conanfile consumed by Conan create. e.j. conanfile.py
Expand Down Expand Up @@ -1352,6 +1353,7 @@ This is especially useful for CI integration.
- "pattern\*,another_pattern\*": will build only the packages with the reference matching these patterns. Equivalent to `--build pattern* --build another_pattern*`
- "pattern\*,outdated": Equivalent to `--build pattern* --build outdated`
Check [Conan Build policies](https://docs.conan.io/en/latest/mastering/policies.html) for more details.
- **CONAN_REQUIRE_OVERRIDES**: Comma separated list of requirement overrides.
- **CONAN_CONFIG_URL**: Conan config URL be installed before to build e.j https://github.com/bincrafters/conan-config.git
- **CONAN_CONFIG_ARGS**: Conan config arguments used when installing conan config
- **CONAN_BASE_PROFILE**: Apply options, settings, etc. to this profile instead of `default`.
Expand Down
8 changes: 7 additions & 1 deletion cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __init__(self, username=None, channel=None, runner=None,
docker_shell=None,
pip_install=None,
build_policy=None,
require_overrides=None,
always_update_conan_in_docker=False,
conan_api=None,
client_cache=None,
Expand Down Expand Up @@ -254,6 +255,8 @@ def __init__(self, username=None, channel=None, runner=None,
if isinstance(self.build_policy, list):
self.build_policy = ",".join(self.build_policy)

self.require_overrides = require_overrides or split_colon_env("CONAN_REQUIRE_OVERRIDES") or None

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 ""
Expand Down Expand Up @@ -687,6 +690,7 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None,
self.uploader,
exclude_vcvars_precommand=self.exclude_vcvars_precommand,
build_policy=self.build_policy,
require_overrides=self.require_overrides,
runner=self.runner,
cwd=self.cwd,
printer=self.printer,
Expand All @@ -700,7 +704,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None,
lockfile=self.lockfile,
skip_recipe_export=skip_recipe_export,
update_dependencies=self.update_dependencies,
profile_build_abs_path=profile_build_abs_path)
profile_build_abs_path=profile_build_abs_path,
)
r.run()
self._packages_summary.append({"configuration": build, "package" : r.results})
else:
Expand All @@ -714,6 +719,7 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None,
docker_image_skip_update=self._docker_image_skip_update,
docker_image_skip_pull=self._docker_image_skip_pull,
build_policy=self.build_policy,
require_overrides=self.require_overrides,
always_update_conan_in_docker=self._update_conan_in_docker,
upload=self._upload_enabled(),
upload_retry=self.upload_retry,
Expand Down
3 changes: 2 additions & 1 deletion cpt/run_in_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def run():
upload_force = os.getenv("CPT_UPLOAD_FORCE")
uploader = Uploader(conan_api, remotes_manager, auth_manager, printer, upload_retry, upload_force)
build_policy = unscape_env(os.getenv("CPT_BUILD_POLICY"))
require_overrides = unscape_env(os.getenv("CPT_REQUIRE_OVERRIDES"))
test_folder = unscape_env(os.getenv("CPT_TEST_FOLDER"))
reference = ConanFileReference.loads(os.getenv("CONAN_REFERENCE"))

Expand All @@ -60,7 +61,7 @@ def run():

upload = os.getenv("CPT_UPLOAD_ENABLED")
runner = CreateRunner(abs_profile_path, reference, conan_api, uploader,
build_policy=build_policy, printer=printer, upload=upload,
build_policy=build_policy, require_overrides=require_overrides, printer=printer, upload=upload,
upload_only_recipe=upload_only_recipe,
test_folder=test_folder, config_url=config_url, config_args=config_args,
upload_dependencies=upload_dependencies, conanfile=conanfile,
Expand Down
12 changes: 10 additions & 2 deletions cpt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class CreateRunner(object):

def __init__(self, profile_abs_path, reference, conan_api, uploader,
exclude_vcvars_precommand=False, build_policy=None, runner=None,
exclude_vcvars_precommand=False, build_policy=None, require_overrides=None, runner=None,
cwd=None, printer=None, upload=False, upload_only_recipe=None,
test_folder=None, config_url=None, config_args=None,
upload_dependencies=None, conanfile=None, skip_recipe_export=False,
Expand All @@ -36,6 +36,9 @@ def __init__(self, profile_abs_path, reference, conan_api, uploader,
self._build_policy = build_policy.split(",") if \
isinstance(build_policy, str) else \
build_policy
self._require_overrides = require_overrides.split(",") if \
isinstance(require_overrides, str) else \
require_overrides
self._runner = PrintRunner(runner or os.system, self.printer)
self._test_folder = test_folder
self._config_url = config_url
Expand Down Expand Up @@ -111,6 +114,7 @@ def run(self):
with tools.environment_append({"_CONAN_CREATE_COMMAND_": "1"}):
params = {"name": name, "version": version, "user": user,
"channel": channel, "build_modes": self._build_policy,
"require_overrides": self._require_overrides,
"profile_name": self._profile_abs_path,
"profile_build_name": self._profile_build_abs_path}
self.printer.print_message("Calling 'conan create'")
Expand All @@ -127,6 +131,7 @@ def run(self):
self._results = self._conan_api.create(self._conanfile, name=name, version=version,
user=user, channel=channel,
build_modes=self._build_policy,
require_overrides=self._require_overrides,
profile_name=self._profile_abs_path,
test_folder=self._test_folder,
not_export=self.skip_recipe_export,
Expand All @@ -145,6 +150,7 @@ def run(self):
self._results = self._conan_api.create(self._conanfile, name=name, version=version,
user=user, channel=channel,
build_modes=self._build_policy,
require_overrides=self._require_overrides,
profile_names=[self._profile_abs_path],
test_folder=self._test_folder,
not_export=self.skip_recipe_export,
Expand Down Expand Up @@ -184,7 +190,7 @@ class DockerCreateRunner(object):
def __init__(self, profile_text, base_profile_text, base_profile_name, reference,
conan_pip_package=None, docker_image=None, sudo_docker_command=None,
sudo_pip_command=False,
docker_image_skip_update=False, build_policy=None,
docker_image_skip_update=False, build_policy=None, require_overrides=None,
docker_image_skip_pull=False,
always_update_conan_in_docker=False,
upload=False, upload_retry=None, upload_only_recipe=None,
Expand Down Expand Up @@ -217,6 +223,7 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
self._reference = reference
self._conan_pip_package = conan_pip_package
self._build_policy = build_policy
self._require_overrides = require_overrides
self._docker_image = docker_image
self._always_update_conan_in_docker = always_update_conan_in_docker
self._docker_image_skip_update = docker_image_skip_update
Expand Down Expand Up @@ -376,6 +383,7 @@ def get_env_vars(self):
ret["CPT_UPLOAD_ONLY_RECIPE"] = self._upload_only_recipe
ret["CPT_UPLOAD_FORCE"] = self._upload_force
ret["CPT_BUILD_POLICY"] = escape_env(self._build_policy)
ret["CPT_REQUIRE_OVERRIDES"] = escape_env(self._require_overrides)
ret["CPT_TEST_FOLDER"] = escape_env(self._test_folder)
ret["CPT_CONFIG_URL"] = escape_env(self._config_url)
ret["CPT_CONFIG_ARGS"] = escape_env(self._config_args)
Expand Down
42 changes: 42 additions & 0 deletions cpt/test/integration/require_overrides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest

from cpt.test.utils.tools import TestClient
from cpt.test.test_client.tools import get_patched_multipackager


class RequireOverridesTest(unittest.TestCase):
def test_require_overrides(self):
conanfile_bar = """from conans import ConanFile
class Pkg(ConanFile):
name = "bar"
version = "0.1.0"
def build(self):
pass
"""

conanfile = """from conans import ConanFile
class Pkg(ConanFile):
name = "foobar"
version = "2.0"
requires = "bar/0.1.0@foo/stable"
def build(self):
self.output.warn("BUILDING")
"""

client = TestClient()
client.save({"conanfile_bar.py": conanfile_bar})
client.run("export conanfile_bar.py foo/stable")
client.run("export conanfile_bar.py foo/testing")

client.save({"conanfile.py": conanfile})
mulitpackager = get_patched_multipackager(client, username="user",
channel="testing",
build_policy="missing",
require_overrides=["bar/0.1.0@foo/testing"],
exclude_vcvars_precommand=True)
mulitpackager.add({}, {})
mulitpackager.run()

self.assertIn("requirement bar/0.1.0@foo/stable overridden by your conanfile to bar/0.1.0@foo/testing", client.out)

0 comments on commit 507826a

Please sign in to comment.