8000 #354 Add CONAN_CONANFILE option by uilianries · Pull Request #357 · conan-io/conan-package-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#354 Add CONAN_CONANFILE option #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ Using **CONAN_CLANG_VERSIONS** env variable in Travis ci or Appveyor:
- "outdated": Build only missing or if the available package is not built with the current recipe. Useful to upload new configurations, e.j packages for a new compiler without
rebuild all packages.
- **test_folder**: Custom test folder consumed by Conan create, e.j .conan/test_package
- **conanfile**: Custom conanfile consumed by Conan create. e.j. conanfile.py
- **config_url**: Conan config URL be installed before to build e.j https://github.com/bincrafters/conan-config.git

Upload related parameters:
Expand Down Expand Up @@ -1189,6 +1190,7 @@ This is especially useful for CI integration.
- **CONAN_CONFIG_URL**: Conan config URL be installed before to build e.j https://github.com/bincrafters/conan-config.git
- **CONAN_BASE_PROFILE**: Apply options, settings, etc. to this profile instead of `default`.
- **CONAN_IGNORE_SKIP_CI**: Ignore `[skip ci]` in commit message.
- **CONAN_CONANFILE**: Custom conanfile consumed by Conan create. e.j. conanfile.py
- **CPT_TEST_FOLDER**: Custom test_package path, e.j .conan/test_package


Expand Down
19 changes: 11 additions & 8 deletions cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self, username=None, channel=None, runner=None,
always_update_conan_in_docker=False,
conan_api=None,
client_cache=None,
conanfile=None,
ci_manager=None,
out=None,
test_folder=None,
Expand Down Expand Up @@ -150,8 +151,7 @@ def __init__(self, username=None, channel=None, runner=None,
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._update_conan_in_docker = always_update_conan_in_docker or get_bool_from_env("CONAN_ALWAYS_UPDATE_CONAN_DOCKER")

self._platform_info = platform_info or PlatformInfo()

Expand All @@ -163,6 +163,7 @@ def __init__(self, username=None, channel=None, runner=None,
self.stable_channel = self.stable_channel.rstrip()
self.channel = self._get_channel(self.specified_channel, self.stable_channel, self.upload_only_when_tag)
self.partial_reference = reference or os.getenv("CONAN_REFERENCE", None)
self.conanfile = conanfile or os.getenv("CONAN_CONANFILE", "conanfile.py")

if self.partial_reference:
if "@" in self.partial_reference:
Expand All @@ -171,11 +172,11 @@ def __init__(self, username=None, channel=None, runner=None,
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, "conanfile.py")):
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")

conanfile = load_cf_class(os.path.join(self.cwd, "conanfile.py"), self.conan_api)
conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile), self.conan_api)
name, version = conanfile.name, conanfile.version
if name and version:
self.reference = ConanFileReference(name, version, self.username, self.channel)
Expand Down Expand Up @@ -392,8 +393,8 @@ def add_common_builds(self, shared_option_name=None, pure_c=True,
raise Exception("Specify a CONAN_REFERENCE or name and version fields in the recipe")

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

Expand Down Expand Up @@ -542,7 +543,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None):
upload=self._upload_enabled(),
test_folder=self.test_folder,
config_url=self.config_url,
upload_dependencies=self.upload_dependencies)
upload_dependencies=self.upload_dependencies,
conanfile=self.conanfile)
r.run()
else:
docker_image = self._get_docker_image(build)
Expand All @@ -566,7 +568,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None):
test_folder=self.test_folder,
pip_install=self.pip_install,
config_url=self.config_url,
upload_dependencies=self.upload_dependencies)
upload_dependencies=self.upload_dependencies,
conanfile=self.conanfile)

r.run(pull_image=not pulled_docker_images[docker_image],
docker_entry_script=self.docker_entry_script)
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 @@ -34,6 +34,7 @@ def run():
base_profile_text = unscape_env(os.getenv("CPT_BASE_PROFILE"))
config_url = unscape_env(os.getenv("CPT_CONFIG_URL"))
upload_dependencies = unscape_env(os.getenv("CPT_UPLOAD_DEPENDENCIES"))
conanfile = unscape_env(os.getenv("CPT_CONANFILE"))
if base_profile_text:
base_profile_name = unscape_env(os.getenv("CPT_BASE_PROFILE_NAME"))
tools.save(os.path.join(client_cache.profiles_path, base_profile_name),
Expand All @@ -43,7 +44,7 @@ def run():
runner = CreateRunner(abs_profile_path, reference, conan_api, uploader,
build_policy=build_policy, printer=printer, upload=upload,
test_folder=test_folder, config_url=config_url,
upload_dependencies=upload_dependencies)
upload_dependencies=upload_dependencies, conanfile=conanfile)
runner.run()


Expand Down
13 changes: 9 additions & 4 deletions cpt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CreateRunner(object):
def __init__(self, profile_abs_path, reference, conan_api, uploader,
exclude_vcvars_precommand=False, build_policy=None, runner=None,
cwd=None, printer=None, upload=False, test_folder=None, config_url=None,
upload_dependencies=None):
upload_dependencies=None, conanfile=None):

self.printer = printer or Printer()
self._cwd = cwd or os.getcwd()
Expand All @@ -31,10 +31,12 @@ def __init__(self, profile_abs_path, reference, conan_api, uploader,
self._uploader.remote_manager.add_remotes_to_conan()
self._test_folder = test_folder
self._config_url = config_url
self._conanfile = conanfile
self._upload_dependencies = upload_dependencies.split(",") if \
isinstance(upload_dependencies, str) else \
upload_dependencies


patch_default_base_profile(conan_api, profile_abs_path)

if Version(client_version) < Version("1.12.0"):
Expand Down Expand Up @@ -90,13 +92,13 @@ def run(self):

try:
if client_version < Version("1.12.0"):
r = self._conan_api.create(".", name=name, version=version,
r = self._conan_api.create(self._conanfile, name=name, version=version,
user=user, channel=channel,
build_modes=self._build_policy,
profile_name=self._profile_abs_path,
test_folder=self._test_folder)
else:
r = self._conan_api.create(".", name=name, version=version,
r = self._conan_api.create(self._conanfile, name=name, version=version,
user=user, channel=channel,
build_modes=self._build_policy,
profile_names=[self._profile_abs_path],
Expand Down Expand Up @@ -136,7 +138,8 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
test_folder=None,
pip_install=None,
config_url=None,
upload_dependencies=None):
upload_dependencies=None,
conanfile=None):

self.printer = Printer()
self._upload = upload
Expand All @@ -162,6 +165,7 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
self._pip_install = pip_install
self._config_url = config_url
self._upload_dependencies = upload_dependencies
self._conanfile = conanfile

def _pip_update_conan_command(self):
commands = []
Expand Down Expand Up @@ -270,6 +274,7 @@ def get_env_vars(self):
ret["CPT_TEST_FOLDER"] = escape_env(self._test_folder)
ret["CPT_CONFIG_URL"] = escape_env(self._config_url)
ret["CPT_UPLOAD_DEPENDENCIES"] = escape_env(self._upload_dependencies)
ret["CPT_CONANFILE"] = escape_env(self._conanfile)

ret.update({key: value for key, value in os.environ.items() if key.startswith("PIP_")})

Expand Down
24 changes: 24 additions & 0 deletions cpt/test/integration/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,27 @@ class Pkg(ConanFile):
self.packager.add_common_builds()
self.packager.run()

def test_custom_conanfile(self):
conanfile = """from conans import ConanFile
class Pkg(ConanFile):
name = "lib"
version = "1.2"
settings = "os", "compiler", "build_type", "arch"
"""
tools.save(os.path.join(self.tmp_folder, "foobar.py"), conanfile)
with tools.environment_append({"CONAN_CONANFILE": "foobar.py"}):
self.packager = ConanMultiPackager(username="pepe",
channel="mychannel",
out=self.output.write)
self.packager.add({}, {}, {}, {})
self.packager.run()
self.assertIn("conanfile | foobar.py", self.output)

tools.save(os.path.join(self.tmp_folder, "custom_recipe.py"), conanfile)
self.packager = ConanMultiPackager(username="pepe",
channel="mychannel",
conanfile="custom_recipe.py",
out=self.output.write)
self.packager.add({}, {}, {}, {})
self.packager.run()
self.assertIn("conanfile | custom_recipe.py", self.output)
0