{"action":"created","issue":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/4643","repository_url":"https://api.github.com/repos/bazelbuild/bazel","labels_url":"https://api.github.com/repos/bazelbuild/bazel/issues/4643/labels{/name}","comments_url":"https://api.github.com/repos/bazelbuild/bazel/issues/4643/comments","events_url":"https://api.github.com/repos/bazelbuild/bazel/issues/4643/events","html_url":"https://github.com/bazelbuild/bazel/issues/4643","id":297546358,"number":4643,"title":"--action_env results in confusing and inconsistent behavior","user":{"login":"crorvick","id":824726,"avatar_url":"https://avatars2.githubusercontent.com/u/824726?v=4","gravatar_id":"","url":"https://api.github.com/users/crorvick","html_url":"https://github.com/crorvick","followers_url":"https://api.github.com/users/crorvick/followers","following_url":"https://api.github.com/users/crorvick/following{/other_user}","gists_url":"https://api.github.com/users/crorvick/gists{/gist_id}","starred_url":"https://api.github.com/users/crorvick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crorvick/subscriptions","organizations_url":"https://api.github.com/users/crorvick/orgs","repos_url":"https://api.github.com/users/crorvick/repos","events_url":"https://api.github.com/users/crorvick/events{/privacy}","received_events_url":"https://api.github.com/users/crorvick/received_events","type":"User","site_admin":false},"labels":[{"id":192364241,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/P3","name":"P3","color":"fbca04","default":false},{"id":392619826,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/category:%20rules%20%3E%20C++","name":"category: rules > C++","color":"d4c5f9","default":false},{"id":106503259,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/type:%20bug","name":"type: bug","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":{"login":"mhlopko","id":814566,"avatar_url":"https://avatars0.githubusercontent.com/u/814566?v=4","gravatar_id":"","url":"https://api.github.com/users/mhlopko","html_url":"https://github.com/mhlopko","followers_url":"https://api.github.com/users/mhlopko/followers","following_url":"https://api.github.com/users/mhlopko/following{/other_user}","gists_url":"https://api.github.com/users/mhlopko/gists{/gist_id}","starred_url":"https://api.github.com/users/mhlopko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhlopko/subscriptions","organizations_url":"https://api.github.com/users/mhlopko/orgs","repos_url":"https://api.github.com/users/mhlopko/repos","events_url":"https://api.github.com/users/mhlopko/events{/privacy}","received_events_url":"https://api.github.com/users/mhlopko/received_events","type":"User","site_admin":false},"assignees":[{"login":"mhlopko","id":814566,"avatar_url":"https://avatars0.githubusercontent.com/u/814566?v=4","gravatar_id":"","url":"https://api.github.com/users/mhlopko","html_url":"https://github.com/mhlopko","followers_url":"https://api.github.com/users/mhlopko/followers","following_url":"https://api.github.com/users/mhlopko/following{/other_user}","gists_url":"https://api.github.com/users/mhlopko/gists{/gist_id}","starred_url":"https://api.github.com/users/mhlopko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhlopko/subscriptions","organizations_url":"https://api.github.com/users/mhlopko/orgs","repos_url":"https://api.github.com/users/mhlopko/repos","events_url":"https://api.github.com/users/mhlopko/events{/privacy}","received_events_url":"https://api.github.com/users/mhlopko/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-02-15T18:17:29Z","updated_at":"2018-05-25T02:19:25Z","closed_at":null,"author_association":"NONE","body":"### Description of the problem / feature request:\r\n\r\nBazel has two forms for passing environment variables into the build via the `--action_env` command-line parameter:\r\n\r\n- **NAME only:** the variable is passed into Bazel, getting the value from the user's environment.\r\n- **NAME=value:** the variable is passed into Bazel with the explicitly provided value\r\n\r\nI have stumbled into some surprising observations:\r\n\r\n- Variables passed via `--action_env` are not set in all task environments (e.g., compiling for host.)\r\n- Which tasks have the variable in their environment is dependent on which form is used.\r\n\r\nBoth of these appear to be bugs based on my understanding of how `--action_env` should work from the documentation.\r\n\r\n### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.\r\nExample 1:\r\n```\r\n$ git clone https://github.com/crorvick/bazel-hello.git\r\n$ cd bazel-hello\r\n$ bazel build --action_env=MY_VARIABLE=nothing_special -s //src/hello\r\n```\r\nExample 2:\r\n```\r\n$ bazel clean\r\n$ bazel shutdown\r\n$ MY_VARIABLE=nothing_special bazel build --action_env=MY_VARIABLE -s //src/hello\r\n```\r\nIn both examples tasks are run without `MY_VARIABLE` set in their environments.  The tasks that do see `MY_VARIABLE` are not consistent between the examples (i.e., example 2 sees fewer)\r\n\r\n### What operating system are you running Bazel on?\r\n\r\n1. CentOS 7.4\r\n2. Gentoo\r\n\r\n(reproducible on both)\r\n\r\n### What's the output of `bazel info release`?\r\n\r\n1. CentOS 7.4: `release 0.10.0- (@non-git)`\r\n2. Gentoo: `release 0.7.0- (@non-git)`\r\n\r\n### If `bazel info release` returns \"development version\" or \"(@non-git)\", tell us how you built Bazel.\r\n\r\n1. CentOS 7.4:\r\n   1. download tarball from GitHub (`bazel-0.10.0-dist.zip`)\r\n   2. run `compile.sh` from exploded tarball\r\n\r\n2. Gentoo\r\n   1. run `emerge` with `~amd64` enabled for `dev-util/bazel`\r\n\r\n### Output from example runs\r\n\r\nExample 1:\r\n```\r\n$ bazel build --action_env=MY_VARIABLE=nothing_special -s //src/hello\r\nINFO: Found 1 target...\r\n>>>>> # //src/hello:hello [action 'Creating runfiles tree bazel-out/local-fastbuild/bin/src/hello/hello.runfiles']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    MY_VARIABLE=nothing_special \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  _bin/build-runfiles bazel-out/local-fastbuild/bin/src/hello/hello.runfiles_manifest bazel-out/local-fastbuild/bin/src/hello/hello.runfiles)\r\n>>>>> # //src/optimize:optimize [action 'Creating runfiles tree bazel-out/host/bin/src/optimize/optimize.runfiles [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  _bin/build-runfiles bazel-out/host/bin/src/optimize/optimize.runfiles_manifest bazel-out/host/bin/src/optimize/optimize.runfiles)\r\n>>>>> # //src/optimize:optimize [action 'Compiling src/optimize/main.cc [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections -g0 '-std=c++0x' -g0 -MD -MF bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.d '-frandom-seed=bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.o' -iquote . -iquote bazel-out/host/genfiles -iquote external/bazel_tools -iquote bazel-out/host/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__=\"redacted\"' '-D__TIMESTAMP__=\"redacted\"' '-D__TIME__=\"redacted\"' -c src/optimize/main.cc -o bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.o)\r\n>>>>> # //src/optimize:optimize [action 'Linking src/optimize/optimize [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -o bazel-out/host/bin/src/optimize/optimize '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,--gc-sections -Wl,-S -Wl,@bazel-out/host/bin/src/optimize/optimize-2.params)\r\n>>>>> # //src/hello:hello_optimize [action 'Executing genrule //src/hello:hello_optimize']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    MY_VARIABLE=nothing_special \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/src/optimize/optimize <src/hello/hello.in >bazel-out/local-fastbuild/genfiles/src/hello/hello.cc')\r\n>>>>> # //src/hello:hello [action 'Compiling src/hello/hello.cc']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    MY_VARIABLE=nothing_special \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.d '-frandom-seed=bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.o' -fPIC -iquote . -iquote bazel-out/local-fastbuild/genfiles -iquote external/bazel_tools -iquote bazel-out/local-fastbuild/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__=\"redacted\"' '-D__TIMESTAMP__=\"redacted\"' '-D__TIME__=\"redacted\"' -c bazel-out/local-fastbuild/genfiles/src/hello/hello.cc -o bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.o)\r\n>>>>> # //src/hello:hello [action 'Linking src/hello/hello']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    MY_VARIABLE=nothing_special \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -o bazel-out/local-fastbuild/bin/src/hello/hello '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,-S -Wl,@bazel-out/local-fastbuild/bin/src/hello/hello-2.params)\r\nTarget //src/hello:hello up-to-date:\r\n  bazel-bin/src/hello/hello\r\nINFO: Elapsed time: 1.395s, Critical Path: 0.60s\r\n```\r\nExample 2:\r\n```\r\n$ MY_VARIABLE=nothing_special bazel build --action_env=MY_VARIABLE -s //src/hello\r\nINFO: Found 1 target...\r\n>>>>> # //src/hello:hello [action 'Creating runfiles tree bazel-out/local-fastbuild/bin/src/hello/hello.runfiles']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  _bin/build-runfiles bazel-out/local-fastbuild/bin/src/hello/hello.runfiles_manifest bazel-out/local-fastbuild/bin/src/hello/hello.runfiles)\r\n>>>>> # //src/optimize:optimize [action 'Compiling src/optimize/main.cc [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections -g0 '-std=c++0x' -g0 -MD -MF bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.d '-frandom-seed=bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.o' -iquote . -iquote bazel-out/host/genfiles -iquote external/bazel_tools -iquote bazel-out/host/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__=\"redacted\"' '-D__TIMESTAMP__=\"redacted\"' '-D__TIME__=\"redacted\"' -c src/optimize/main.cc -o bazel-out/host/bin/src/optimize/_objs/optimize/src/optimize/main.o)\r\n>>>>> # //src/optimize:optimize [action 'Creating runfiles tree bazel-out/host/bin/src/optimize/optimize.runfiles [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  _bin/build-runfiles bazel-out/host/bin/src/optimize/optimize.runfiles_manifest bazel-out/host/bin/src/optimize/optimize.runfiles)\r\n>>>>> # //src/optimize:optimize [action 'Linking src/optimize/optimize [for host]']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -o bazel-out/host/bin/src/optimize/optimize '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,--gc-sections -Wl,-S -Wl,@bazel-out/host/bin/src/optimize/optimize-2.params)\r\n>>>>> # //src/hello:hello_optimize [action 'Executing genrule //src/hello:hello_optimize']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    MY_VARIABLE=nothing_special \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/src/optimize/optimize <src/hello/hello.in >bazel-out/local-fastbuild/genfiles/src/hello/hello.cc')\r\n>>>>> # //src/hello:hello [action 'Compiling src/hello/hello.cc']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.d '-frandom-seed=bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.o' -fPIC -iquote . -iquote bazel-out/local-fastbuild/genfiles -iquote external/bazel_tools -iquote bazel-out/local-fastbuild/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__=\"redacted\"' '-D__TIMESTAMP__=\"redacted\"' '-D__TIME__=\"redacted\"' -c bazel-out/local-fastbuild/genfiles/src/hello/hello.cc -o bazel-out/local-fastbuild/bin/src/hello/_objs/hello/src/hello/hello.pic.o)\r\n>>>>> # //src/hello:hello [action 'Linking src/hello/hello']\r\n(cd /home/chris/.cache/bazel/_bazel_chris/009fe0b206b9fa4bf70b52aad8fd454d/execroot/__main__ && \\\r\n  exec env - \\\r\n    PATH=/usr/local/bin:/usr/bin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0:/usr/lib/llvm/5/bin:/usr/lib/llvm/4/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin \\\r\n    PWD=/proc/self/cwd \\\r\n  /usr/bin/gcc -o bazel-out/local-fastbuild/bin/src/hello/hello '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,-S -Wl,@bazel-out/local-fastbuild/bin/src/hello/hello-2.params)\r\nTarget //src/hello:hello up-to-date:\r\n  bazel-bin/src/hello/hello\r\nINFO: Elapsed time: 1.436s, Critical Path: 0.63s\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/comments/391921424","html_url":"https://github.com/bazelbuild/bazel/issues/4643#issuecomment-391921424","issue_url":"https://api.github.com/repos/bazelbuild/bazel/issues/4643","id":391921424,"user":{"login":"crorvick","id":824726,"avatar_url":"https://avatars2.githubusercontent.com/u/824726?v=4","gravatar_id":"","url":"https://api.github.com/users/crorvick","html_url":"https://github.com/crorvick","followers_url":"https://api.github.com/users/crorvick/followers","following_url":"https://api.github.com/users/crorvick/following{/other_user}","gists_url":"https://api.github.com/users/crorvick/gists{/gist_id}","starred_url":"https://api.github.com/users/crorvick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crorvick/subscriptions","organizations_url":"https://api.github.com/users/crorvick/orgs","repos_url":"https://api.github.com/users/crorvick/repos","events_url":"https://api.github.com/users/crorvick/events{/privacy}","received_events_url":"https://api.github.com/users/crorvick/received_events","type":"User","site_admin":false},"created_at":"2018-05-25T02:19:25Z","updated_at":"2018-05-25T02:19:25Z","author_association":"NONE","body":"Could someone summarize the current status of this bug report?"}}
{"actor":{"display_login":"crorvick"}}