2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-28 08:43:26 +00:00

Prepend user-specified PATH to existing PATH (#733)

If a user specifies a PATH value as part of an `env` attribute, the
value will be prepended to the existing PATH.

An example requirement for this change is that the MSVC build of
OpenSSL requires that the Netwide Assembler (NASM) must be on the
PATH.
This commit is contained in:
jheaff1 2021-07-22 12:30:25 -07:00 committed by GitHub
parent c7330faee5
commit b51f25ee62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,7 +103,8 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
"`$(execpath)` macros may be used to point at files which are listed as `data`, `deps`, or `build_data`, " +
"but unlike with other rules, these will be replaced with absolute paths to those files, " +
"because the build does not run in the exec root. " +
"No other macros are supported."
"No other macros are supported." +
"Variables containing `PATH` (e.g. `PATH`, `LD_LIBRARY_PATH`, `CPATH`) entries will be prepended to the existing variable."
),
),
"lib_name": attr.string(
@ -299,7 +300,14 @@ def get_env_prelude(ctx, lib_name, data_dependencies, target_root):
env.update(cc_env)
# Add all user defined variables
env.update(expand_locations(ctx, ctx.attr.env, data_dependencies))
user_vars = expand_locations(ctx, ctx.attr.env, data_dependencies)
env.update(user_vars)
# If user has defined a PATH variable (e.g. PATH, LD_LIBRARY_PATH, CPATH) prepend it to the existing variable
for user_var in user_vars:
if "PATH" in user_var and cc_env.get(user_var):
env.update({user_var: user_vars.get(user_var) + ":" + cc_env.get(user_var)})
env_snippet.extend(["export {}=\"{}\"".format(key, _escape_dquote(val)) for key, val in env.items()])
return env_snippet