Skip to content

Commit

Permalink
[Environment] Fixed if scope=None (#17251)
Browse files Browse the repository at this point in the history
* Fixed if scope=None

* Non-breaking change and simplify test

* typo
  • Loading branch information
franramirez688 authored Oct 30, 2024
1 parent b3ad884 commit b36b2ec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions conans/client/subsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def deduce_subsystem(conanfile, scope):
- Aggregation of envfiles: to map each aggregated path to the subsystem
- unix_path: util for recipes
"""
scope = "build" if scope is None else scope # let's assume build context if scope=None
if scope.startswith("build"):
the_os = conanfile.settings_build.get_safe("os")
if the_os is None:
Expand Down
38 changes: 38 additions & 0 deletions test/integration/toolchains/env/test_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import platform
import textwrap

from conan.test.utils.tools import TestClient


# TODO: Change this test when we refactor EnvVars. The UX leaves much to be desired
def test_env_and_scope_none():
"""
Check scope=None does not append foo=var to conan{build|run}.{bat|sh|ps1}
Issue: https://github.com/conan-io/conan/issues/17249
"""
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.env import Environment
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
def generate(self):
env1 = Environment()
env1.define("foo", "var")
# Will not append "my_env_file" to "conanbuild.bat|sh|ps1"
envvars = env1.vars(self, scope=None)
envvars.save_script("my_env_file")
# Let's check the apply() function
with env1.vars(self, scope=None).apply():
import os
assert os.environ["foo"] == "var"
""")
client.save({"conanfile.py": conanfile})
client.run("install .")
ext = ".bat" if platform.system() == "Windows" else ".sh"
assert "my_env_file" not in client.load(f"conanbuild{ext}")
assert "my_env_file" not in client.load(f"conanrun{ext}")

0 comments on commit b36b2ec

Please sign in to comment.