Skip to content
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

Introduce 'env_override' parameter #1114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foreign_cc/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def _create_configure_script(configureParameters):
deps = ctx.attr.deps,
inputs = inputs,
env_vars = user_env,
env_vars_override = ctx.attr.env_override,
configure_in_place = ctx.attr.configure_in_place,
prefix_flag = ctx.attr.prefix_flag,
autoconf = ctx.attr.autoconf,
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/make.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _create_make_script(configureParameters):
deps = ctx.attr.deps,
inputs = inputs,
env_vars = user_env,
env_vars_override = ctx.attr.env_override,
make_commands = make_commands,
)

Expand Down
3 changes: 2 additions & 1 deletion foreign_cc/private/configure_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def create_configure_script(
deps,
inputs,
env_vars,
env_vars_override,
configure_in_place,
prefix_flag,
autoconf,
Expand Down Expand Up @@ -70,7 +71,7 @@ def create_configure_script(

script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$")
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs),
env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, env_vars_override, deps, inputs),
prefix = configure_prefix,
configure = configure_path,
prefix_flag = prefix_flag,
Expand Down
7 changes: 7 additions & 0 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
"Variables containing `PATH` (e.g. `PATH`, `LD_LIBRARY_PATH`, `CPATH`) entries will be prepended to the existing variable."
),
),
"env_override": attr.string_list(
doc = (
"List of keys from the 'env' attribute that should override any values set by the underlying C toolchain."
),
mandatory = False,
default = [],
),
"includes": attr.string_list(
doc = (
"Optional list of include dirs to be passed to the dependencies of this library. " +
Expand Down
10 changes: 7 additions & 3 deletions foreign_cc/private/make_env_vars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ def get_make_env_vars(
tools,
flags,
user_vars,
user_vars_override,
deps,
inputs):
vars = _get_make_variables(workspace_name, tools, flags, user_vars)
vars = _get_make_variables(workspace_name, tools, flags, user_vars, user_vars_override)
deps_flags = _define_deps_flags(deps, inputs)

# For cross-compilation.
Expand Down Expand Up @@ -94,7 +95,7 @@ _MAKE_TOOLS = {
# missing: cxx_linker_executable
}

def _get_make_variables(workspace_name, tools, flags, user_env_vars):
def _get_make_variables(workspace_name, tools, flags, user_env_vars, user_vars_override):
vars = {}

for flag in _MAKE_FLAGS:
Expand All @@ -106,7 +107,10 @@ def _get_make_variables(workspace_name, tools, flags, user_env_vars):
for user_var in user_env_vars:
toolchain_val = vars.get(user_var)
if toolchain_val:
vars[user_var] = toolchain_val + [user_env_vars[user_var]]
if user_var in user_vars_override:
vars[user_var] = [user_env_vars[user_var]]
else:
vars[user_var] = toolchain_val + [user_env_vars[user_var]]

tools_dict = {}
for tool in _MAKE_TOOLS:
Expand Down
3 changes: 2 additions & 1 deletion foreign_cc/private/make_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def create_make_script(
flags,
root,
env_vars,
env_vars_override,
deps,
inputs,
make_commands):
Expand All @@ -19,7 +20,7 @@ def create_make_script(
script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$ False".format(root))

script.append("##enable_tracing##")
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs)
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, env_vars_override, deps, inputs)
script.extend(["{env_vars} {command}".format(
env_vars = configure_vars,
command = command,
Expand Down