Skip to content

Commit

Permalink
Always set use_default_shell_env=True so that action_env is propagate…
Browse files Browse the repository at this point in the history
…d. (#701)
  • Loading branch information
jsharpe authored Jun 28, 2021
1 parent 2caf8db commit c41020e
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,20 @@ def _env_prelude(ctx, lib_name, data_dependencies, target_root):
"export EXT_BUILD_DEPS=$$INSTALLDIR$$.ext_build_deps",
]

if os_name(ctx) == "macos":
env_snippet.extend(["export DEVELOPER_DIR=\"$(xcode-select --print-path)\"", "export SDKROOT=\"$(xcrun --sdk macosx --show-sdk-path)\""])

env = dict()

# Add all environment variables from the cc_toolchain
cc_env = _correct_path_variable(get_env_vars(ctx))
env.update(cc_env)

# Because windows will be using `use_default_shell_env`, any environment variables
# set on the build action will be ignored. To solve for this, we explicitly set
# environment variables to tools for the current cc_toolchain in use.
if "win" in os_name(ctx):
env_snippet.extend(["export {}=\"{}\"".format(key, cc_env[key]) for key in cc_env])

# Capture `action_env` and allow it to take precedence over cc env
env.update(ctx.configuration.default_shell_env)

# Add all user defined variables
attr_env = expand_locations(ctx, ctx.attr.env, data_dependencies)
env_snippet.extend(["export {}=\"{}\"".format(key, _escape_dquote(val)) for key, val in attr_env.items()])
env.update(expand_locations(ctx, ctx.attr.env, data_dependencies))
env_snippet.extend(["export {}=\"{}\"".format(key, _escape_dquote(val)) for key, val in env.items()])

return env_snippet, env
return env_snippet

def cc_external_rule_impl(ctx, attrs):
"""Framework function for performing external C/C++ building.
Expand Down Expand Up @@ -380,7 +374,7 @@ def cc_external_rule_impl(ctx, attrs):
# Also add legacy dependencies while they're still available
data_dependencies += ctx.attr.tools_deps + ctx.attr.additional_tools

env_prelude, env = _env_prelude(ctx, lib_name, data_dependencies, target_root)
env_prelude = _env_prelude(ctx, lib_name, data_dependencies, target_root)

postfix_script = [attrs.postfix_script]
if not attrs.postfix_script:
Expand Down Expand Up @@ -446,12 +440,7 @@ def cc_external_rule_impl(ctx, attrs):
),
command = wrapped_outputs.wrapper_script_file.path,
execution_requirements = execution_requirements,
# TODO: Windows is the only platform which requires this as there's no
# consistent way to get the path to the bash tools that are expected
# to be available by the foreign_cc framework.
use_default_shell_env = "win" in os_name(ctx),
# this is ignored if use_default_shell_env = True
env = env,
use_default_shell_env = True,
progress_message = "Foreign Cc - {configure_name}: Building {target_name}".format(
configure_name = attrs.configure_name,
target_name = ctx.attr.name,
Expand Down

0 comments on commit c41020e

Please sign in to comment.