-
Notifications
You must be signed in to change notification settings - Fork 427
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
Fix: Build environments not activated #4665
Changes from all commits
9fde4c1
9fd7165
7f047c7
060f10f
ba9c666
73c2802
998597c
1ebe72c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -950,11 +950,10 @@ def get_build_folders(croot): | |
|
||
|
||
def prepend_bin_path(env, prefix, prepend_prefix=False): | ||
# bin_dirname takes care of bin on *nix, Scripts on win | ||
env['PATH'] = join(prefix, bin_dirname) + os.pathsep + env['PATH'] | ||
env['PATH'] = join(prefix, "bin") + os.pathsep + env['PATH'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if sys.platform == "win32": | ||
env['PATH'] = join(prefix, "Library", "mingw-w64", "bin") + os.pathsep + \ | ||
join(prefix, "Library", "usr", "bin") + os.pathsep + os.pathsep + \ | ||
join(prefix, "Library", "usr", "bin") + os.pathsep + \ | ||
join(prefix, "Library", "bin") + os.pathsep + \ | ||
join(prefix, "Scripts") + os.pathsep + \ | ||
env['PATH'] | ||
|
@@ -985,9 +984,10 @@ def sys_path_prepended(prefix): | |
|
||
|
||
@contextlib.contextmanager | ||
def path_prepended(prefix): | ||
def path_prepended(prefix, prepend_prefix=True): | ||
# FIXME: Unclear why prepend_prefix=True for all platforms. | ||
old_path = os.environ['PATH'] | ||
os.environ['PATH'] = prepend_bin_path(os.environ.copy(), prefix, True)['PATH'] | ||
os.environ['PATH'] = prepend_bin_path(os.environ.copy(), prefix, prepend_prefix)['PATH'] | ||
Comment on lines
+987
to
+990
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea why this is |
||
try: | ||
yield | ||
finally: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Enhancements | ||
|
||
* <news item> | ||
|
||
### Bug fixes | ||
|
||
* Fix build/host environment activation broken in >=3.23.0,<=3.23.2 | ||
* Add PREFIX/bin to PATH on Windows and remove PREFIX root from PATH on Unix | ||
|
||
### Deprecations | ||
|
||
* <news item> | ||
|
||
### Docs | ||
|
||
* <news item> | ||
|
||
### Other | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
from conda_build.render import finalize_metadata | ||
from conda_build.utils import (copy_into, on_win, check_call_env, convert_path_for_cygwin_or_msys2, | ||
package_has_file, check_output_env, get_conda_operation_locks, rm_rf, | ||
walk, env_var, FileNotFoundError) | ||
prepend_bin_path, walk, env_var, FileNotFoundError) | ||
from conda_build.os_utils.external import find_executable | ||
from conda_build.exceptions import (DependencyNeedsBuildingError, CondaBuildException, | ||
OverLinkingError, OverDependingError) | ||
|
@@ -1652,3 +1652,41 @@ def assert_keyword(keyword): | |
assert_keyword('<hidden>') | ||
finally: | ||
os.environ.pop(token) | ||
|
||
|
||
@pytest.mark.slow | ||
def test_activated_prefixes_in_actual_path(testing_config, testing_metadata): | ||
""" | ||
Check if build and host env are properly added to PATH in the correct order. | ||
Do this in an actual build and not just in a unit test to avoid regression. | ||
Currently only tests for single non-"outputs" recipe with build/host split | ||
and proper env activation (Metadata.is_cross and Config.activate both True). | ||
""" | ||
file = "env-path-dump" | ||
testing_metadata.config.activate = True | ||
meta = testing_metadata.meta | ||
meta["requirements"]["host"] = [] | ||
meta["build"]["script"] = [ | ||
f"echo %PATH%>%PREFIX%/{file}" if on_win else f"echo $PATH>$PREFIX/{file}" | ||
] | ||
outputs = api.build(testing_metadata) | ||
env = {"PATH": ""} | ||
# We get the PATH entries twice: (which we should fix at some point) | ||
# 1. from the environment activation hooks, | ||
# 2. also beforehand from utils.path_prepended at the top of | ||
# - build.write_build_scripts on Unix | ||
# - windows.build on Windows | ||
# And apparently here the previously added build env gets deactivated | ||
# from the activation hook, hence only host is on PATH twice. | ||
Comment on lines
+1679
to
+1680
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
prepend_bin_path(env, testing_metadata.config.host_prefix) | ||
if not on_win: | ||
prepend_bin_path(env, testing_metadata.config.build_prefix) | ||
prepend_bin_path(env, testing_metadata.config.host_prefix) | ||
prepend_bin_path(env, testing_metadata.config.build_prefix) | ||
expected_paths = [path for path in env["PATH"].split(os.pathsep) if path] | ||
actual_paths = [ | ||
path | ||
for path in package_has_file(outputs[0], file).strip().split(os.pathsep) | ||
if path in expected_paths | ||
] | ||
assert actual_paths == expected_paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before removing this in a future release, we should add more test cases.
The test added in this PR only checks for the case when there is
build
+host
,activate=True
and nooutputs
.Other configurations that should be tested:
activate=False
build
andhost
mergedactivate=True
activate=False
outputs
I consider this out of scope for this PR since we should put out a patch release quickly and because those other cases touch other issues like #3993 -- that's another can of worms (one we should take care of, but not hastily in a small patch release).