Skip to content

Commit

Permalink
Fix non-activate prepend_bin_path, path_prepended
Browse files Browse the repository at this point in the history
- Prefix "bin" directory get added on all platforms
- Prefix root directory should only be added on Windows
  • Loading branch information
mbargull committed Dec 4, 2022
1 parent 73c2802 commit 36133a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2587,8 +2587,8 @@ def write_build_scripts(m, script, build_file):
# TODO: Prepending the prefixes here should probably be guarded by
# if not m.activate_build_script:
# Leaving it as is, for now, since we need a quick, non-disruptive patch release.
with utils.path_prepended(m.config.host_prefix):
with utils.path_prepended(m.config.build_prefix):
with utils.path_prepended(m.config.host_prefix, False):
with utils.path_prepended(m.config.build_prefix, False):
env = environ.get_dict(m=m)
env["CONDA_BUILD_STATE"] = "BUILD"

Expand Down
10 changes: 5 additions & 5 deletions conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
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']
Expand Down Expand Up @@ -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']
try:
yield
finally:
Expand Down
15 changes: 11 additions & 4 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,16 @@ def test_activated_prefixes_in_actual_path(testing_config, testing_metadata):
]
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.write_build_scripts on Windows
# And apparently here the previously added build env gets deactivated
# from the activation hook, hence only host is on PATH twice.
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]
Expand All @@ -1673,7 +1683,4 @@ def test_activated_prefixes_in_actual_path(testing_config, testing_metadata):
for path in package_has_file(outputs[0], file).strip().split(os.pathsep)
if path in expected_paths
]
# We get the PATH entries twice:
# 1. from the environment activation hooks,
# 2. also beforehand from utils.path_prepended at the top of build.write_build_scripts
assert actual_paths == expected_paths * 2
assert actual_paths == expected_paths

0 comments on commit 36133a6

Please sign in to comment.