Skip to content

Commit

Permalink
Prepend user-specified PATH to existing PATH (#733)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jheaff1 authored Jul 22, 2021
1 parent c7330fa commit b51f25e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b51f25e

Please sign in to comment.