Skip to content

bug(tasks): environment variables broken when defined in surrounding scope #3801

@cbourjau

Description

@cbourjau

1. Issue description

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

Consider the following pixi.toml:

[workspace]
authors = ["Christian Bourjau <[email protected]>"]
channels = ["conda-forge"]
name = "pixi-cmake_args-debug"
platforms = ["osx-arm64"]
version = "0.1.0"

[tasks.foo]
cmd = "echo $CMAKE_ARGS"
[tasks.foo.env]
CMAKE_ARGS = "foo"

[dependencies]
# c-compiler sets CMAKE_ARGS in activation script
c-compiler = ">=1.9.0,<2"

Executing the foo task in a shell (zsh in my case) that does not have CMAKE_ARGS set works as expected (i.e. CMAKE_ARGS is set to the explicit value):

$ pixi run foo
✨ Pixi task (foo): echo $CMAKE_ARGS
foo

However, if CMAKE_ARGS is already set to something else in the executing environment, I observe the following unexpected behavior, where neither the outer nor the explicitly set value is used. Instead, the value from one of the dependencies activation scripts is used:

$ CMAKE_ARGS=bar pixi run foo
✨ Pixi task (foo): echo $CMAKE_ARGS
-DCMAKE_AR=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ar -DCMAKE_CXX_COMPILER_AR=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ar -DCMAKE_C_COMPILER_AR=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ar -DCMAKE_RANLIB=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ranlib -DCMAKE_CXX_COMPILER_RANLIB=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ranlib -DCMAKE_C_COMPILER_RANLIB=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ranlib -DCMAKE_LINKER=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-ld -DCMAKE_STRIP=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-strip -DCMAKE_INSTALL_NAME_TOOL=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-install_name_tool -DCMAKE_LIBTOOL=/Users/c.bourjau/debug/pixi-cmake_args-debug/.pixi/envs/default/bin/arm64-apple-darwin20.0.0-libtool -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

Issue description

I am observing this in zsh on MacOS

Expected behavior

I would expect the explicit value from the toml file to be used regardless of variables in the outer environment or values from activation scripts of dependencies.

Metadata

Metadata

Assignees

Labels

area:tasksRelated to pixi tasksbugSomething isn't workingenv-varsRelated to environment variables

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions