Skip to content
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

[Environment] Fixed if scope=None #17251

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 = scope or "build" # let's assume build context is scope=None
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
if scope.startswith("build"):
the_os = conanfile.settings_build.get_safe("os")
if the_os is None:
Expand Down
56 changes: 56 additions & 0 deletions test/integration/toolchains/env/test_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import platform
import textwrap

from conan.test.utils.tools import TestClient


def test_env_and_scope_none():
"""
Check scope=None does not append foo=var to conan{build|run}.{bat|sh|ps1}
"""
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")
""")
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}")


# TODO: Change this test when we refactor EnvVars. The UX leaves much to be desired
def test_envvars_and_scope_none_apply():
"""
Applying env context if scope=None

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")
with env1.vars(self, scope=None).apply():
import os
assert os.environ["foo"] == "var"
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
""")
client.save({"conanfile.py": conanfile})
client.run("install .")