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

proposal for source() buildenv discussion #15153

Merged
merged 15 commits into from
Dec 14, 2023
Merged
5 changes: 3 additions & 2 deletions conan/tools/env/virtualbuildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class VirtualBuildEnv:
.bat or .sh script
"""

def __init__(self, conanfile):
def __init__(self, conanfile, skip_auto_generate=True):
memsharded marked this conversation as resolved.
Show resolved Hide resolved
self._conanfile = conanfile
self._conanfile.virtualbuildenv = False
if skip_auto_generate:
self._conanfile.virtualbuildenv = False
self.basename = "conanbuildenv"
self.configuration = None
self.arch = None
Expand Down
6 changes: 1 addition & 5 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ def __init__(self, conanfile, backend=None):
compilers_by_conf = self._conanfile.conf.get("tools.build:compiler_executables", default={},
check_type=dict)
# Read the VirtualBuildEnv to update the variables
# FIXME: This VirtualBuildEnv instance is breaking things!!
# FIXME: It shouldn't be used here, not intended for this use case
prev_status = self._conanfile.virtualbuildenv
build_env = VirtualBuildEnv(self._conanfile).vars()
self._conanfile.virtualbuildenv = prev_status
build_env = VirtualBuildEnv(self._conanfile, skip_auto_generate=False).vars()
#: Sets the Meson ``c`` variable, defaulting to the ``CC`` build environment value.
#: If provided as a blank-separated string, it will be transformed into a list.
#: Otherwise, it remains a single string.
Expand Down
4 changes: 1 addition & 3 deletions conans/client/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ def config_source(export_source_folder, conanfile, hook_manager):
# Now move the export-sources to the right location
merge_directories(export_source_folder, conanfile.folders.base_source)
if getattr(conanfile, "source_buildenv", True):
prev_status = conanfile.virtualbuildenv
with VirtualBuildEnv(conanfile).vars().apply():
with VirtualBuildEnv(conanfile, skip_auto_generate=False).vars().apply():
run_source_method(conanfile, hook_manager)
conanfile.virtualbuildenv = prev_status
else:
run_source_method(conanfile, hook_manager)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,48 +144,3 @@ def source(self):
c.run("install .")
c.run("source .")
assert "MY-TOOL! tool/0.1" in c.out


"""
ALTERNATIVE 1: in recipe, explicit
def source(self):
cmd = "mytool.bat" if platform.system() == "Windows" else "mytool.sh"
with VirtualBuildEnv(conanfile).vars().apply():
self.run(cmd)

- Need to bypass ``settings`` restriction in ``source()``
- we can make a nice helper ``with buildenv``
"""

"""
ALTERNATIVE 2: in recipe, attribute
inject_source_buildenv = True

def source(self):
cmd = "mytool.bat" if platform.system() == "Windows" else "mytool.sh"
self.run(cmd)

- No need to bypass ``settings`` restriction in ``source()``
"""

"""
ALTERNATIVE 3: always, this should be the expected default behavior

def source(self):
cmd = "mytool.bat" if platform.system() == "Windows" else "mytool.sh"
self.run(cmd)

- No need to bypass ``settings`` restriction in ``source()``
- We might want to do an opt-out, just in case?
"""

"""
ALTERNATIVE 4: global, controlled by conf

def source(self):
cmd = "mytool.bat" if platform.system() == "Windows" else "mytool.sh"
self.run(cmd)

- No need to bypass ``settings`` restriction in ``source()``
- [conf] core.source:inject_buildenv=True/False
"""