Skip to content

Commit

Permalink
Get 'pure_c' from environment variable CONAN_PURE_C (#587)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitriy Vetutnev <[email protected]>
  • Loading branch information
uilianries and dvetutnev authored Nov 1, 2021
1 parent e2e0970 commit 1865407
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ Check [Conan Build policies](https://docs.conan.io/en/latest/mastering/policies.
- **CONAN_FORCE_SELINUX**: Force docker to relabel file objects on the shared volumes
- **CONAN_SKIP_RECIPE_EXPORT**: If defined, the package recipe will only be exported on the first build.
- **CPT_UPDATE_DEPENDENCIES**: Update all dependencies before building e.g conan create -u
- **CONAN_PURE_C**: Set `pure_c` by environment variable, default `True`


# Full example
Expand Down
5 changes: 4 additions & 1 deletion cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def named_builds(self, confs):
def login(self, remote_name):
self.auth_manager.login(remote_name)

def add_common_builds(self, shared_option_name=None, pure_c=True,
def add_common_builds(self, shared_option_name=None, pure_c=None,
dll_with_static_runtime=False, reference=None, header_only=True,
build_all_options_values=None):
if reference:
Expand All @@ -468,6 +468,9 @@ def add_common_builds(self, shared_option_name=None, pure_c=True,
env_shared_option_name = os.getenv("CONAN_SHARED_OPTION_NAME", None)
shared_option_name = env_shared_option_name if str(env_shared_option_name).lower() != "false" else False

if pure_c is None:
pure_c = get_custom_bool_from_env("CONAN_PURE_C", True)

build_all_options_values = build_all_options_values or split_colon_env("CONAN_BUILD_ALL_OPTIONS_VALUES") or []
if not isinstance(build_all_options_values, list):
raise Exception("'build_all_options_values' must be a list. e.g. ['foo:opt', 'foo:bar']")
Expand Down
46 changes: 46 additions & 0 deletions cpt/test/unit/packager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,52 @@ def test_lockfile(self):
builder.run()
self.assertEquals("couse.lock", self.conan_api.calls[-1].kwargs["lockfile"])

def test_pure_c_env_var(self):

builder = ConanMultiPackager(gcc_versions=["8"], archs=["x86_64"], build_types=["Release"],
username="Pepe", channel="testing",
reference="Hello/0.1",
platform_info=platform_mock_for("Linux"),
ci_manager=self.ci_manager)
builder.add_common_builds()
expected = [({'arch': 'x86_64', 'build_type': 'Release',
'compiler': 'gcc',
'compiler.version': '8'},
{},
{},
{})]
self.assertEquals([tuple(a) for a in builder.builds], expected)

builder.builds = []
with tools.environment_append({"CONAN_PURE_C": "True"}):
builder.add_common_builds()
expected = [({'arch': 'x86_64', 'build_type': 'Release',
'compiler': 'gcc',
'compiler.version': '8'},
{},
{},
{})]
self.assertEquals([tuple(a) for a in builder.builds], expected)

builder.builds = []
with tools.environment_append({"CONAN_PURE_C": "False"}):
builder.add_common_builds()
expected = [({'arch': 'x86_64', 'build_type': 'Release',
'compiler': 'gcc',
'compiler.version': '8',
'compiler.libcxx': "libstdc++"},
{},
{},
{}),
({'arch': 'x86_64', 'build_type': 'Release',
'compiler': 'gcc',
'compiler.version': '8',
'compiler.libcxx': "libstdc++11"},
{},
{},
{})]
self.assertEquals([tuple(a) for a in builder.builds], expected)

def test_docker_cwd(self):
cwd = os.path.join(os.getcwd(), 'subdir')
self.packager = ConanMultiPackager(username="lasote",
Expand Down

0 comments on commit 1865407

Please sign in to comment.