Skip to content
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
8 changes: 6 additions & 2 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def __init__(self, name, value=None, separator=" ", path=False):
self._path = path
self._sep = separator

def __bool__(self):
return bool(self._values) # Empty means unset

def dumps(self):
result = []
path = "(path)" if self._path else ""
Expand Down Expand Up @@ -467,7 +470,7 @@ def save_ps1(self, file_location, generate_deactivate=True):
result.append(
f'if ($env:{varname}) {{ $env:{_old_env_prefix(filename)}_{varname} = $env:{varname} }}'
)
if value:
if varvalues:
value = value.replace('"', '`"') # escape quotes
result.append(f'$env:{varname}="{value}"')
else:
Expand Down Expand Up @@ -497,7 +500,7 @@ def save_sh(self, file_location, generate_deactivate=True):
f'export {_old_env_prefix(filename)}_{varname}="${{{varname}}}"; '
f'fi;'
)
if value:
if varvalues:
result.append(f'export {varname}="{value}"')
else:
result.append(f'unset {varname}')
Expand Down Expand Up @@ -617,6 +620,7 @@ def _ps1_deactivate_contents(deactivation_mode, values, filename):
Pop-Location
""")


def _sh_deactivate_contents(deactivation_mode, values, filename):
vars_list = " ".join(quote(v) for v in values.keys())
if deactivation_mode == "function":
Expand Down
17 changes: 17 additions & 0 deletions test/integration/environment/test_buildenv_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,20 @@ def generate(self):
assert "WARN: dep ENV:Foo" in client.out
assert "WARN: pkg ENV:Foo2" in client.out
assert "WARN: None ENV:Var" in client.out


def test_buildenv_error_unset():
# https://github.com/conan-io/conan/issues/19285#issuecomment-3569891282
c = TestClient()
profile = textwrap.dedent("""
[buildenv]
CLASSPATH=!
OTHERPATH=
""")
c.save({"conanfile.txt": "",
"profile": profile})

c.run("install . -pr=profile -s:a os=Linux")
env = c.load("conanbuildenv.sh")
assert "unset CLASSPATH" in env
assert 'export OTHERPATH=""' in env
Loading