Skip to content

Commit

Permalink
Added check for extern flags as well
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Aug 20, 2021
1 parent d590564 commit 295dd31
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def _crate_to_link_flag(crate_info):
Returns:
list: Link flags for the current crate info
"""
return ["--extern", "{}={}".format(crate_info.name, crate_info.dep.output.path)]
return ["--extern={}={}".format(crate_info.name, crate_info.dep.output.path)]

def _get_crate_dirname(crate):
"""A helper macro used by `add_crate_link_flags` for getting the directory name of the current crate's output path
Expand Down
12 changes: 12 additions & 0 deletions test/unit/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def assert_argv_contains_prefix_suffix(env, action, prefix, suffix):
),
)

def assert_argv_contains_prefix(env, action, prefix):
for found_flag in action.argv:
if found_flag.startswith(prefix):
return
unittest.fail(
env,
"Expected an arg with prefix '{prefix}' in {args}".format(
prefix = prefix,
args = action.argv,
),
)

def assert_action_mnemonic(env, action, mnemonic):
if not action.mnemonic == mnemonic:
unittest.fail(
Expand Down
25 changes: 20 additions & 5 deletions test/unit/exports/exports_test.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Unittest to verify re-exported symbols propagate to downstream crates"""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//test/unit:common.bzl", "assert_argv_contains_prefix_suffix")
load("//test/unit:common.bzl", "assert_argv_contains_prefix", "assert_argv_contains_prefix_suffix")

def _exports_test_impl(ctx, deps):
def _exports_test_impl(ctx, dependencies, externs):
env = analysistest.begin(ctx)
target = analysistest.target_under_test(env)

Expand All @@ -13,25 +13,40 @@ def _exports_test_impl(ctx, deps):
# Transitive symbols that get re-exported are expected to be located by a `-Ldependency` flag.
# The assert below ensures that each dependnecy flag is passed to the Rustc action. For details see
# https://doc.rust-lang.org/rustc/command-line-arguments.html#-l-add-a-directory-to-the-library-search-path
for dep in deps:
for dep in dependencies:
assert_argv_contains_prefix_suffix(
env = env,
action = action,
prefix = "-Ldependency",
suffix = dep,
)

for dep in externs:
assert_argv_contains_prefix(
env = env,
action = action,
prefix = "--extern={}=".format(dep),
)

return analysistest.end(env)

def _lib_exports_test_impl(ctx):
# This test is only expected to be used with
# `//test/unit/exports/lib_c`
return _exports_test_impl(ctx, ["lib_a", "lib_b"])
return _exports_test_impl(
ctx = ctx,
dependencies = ["lib_a", "lib_b"],
externs = ["lib_b"],
)

def _test_exports_test_impl(ctx):
# This test is only expected to be used with
# `//test/unit/exports/lib_c:lib_c_test`
return _exports_test_impl(ctx, ["lib_a", "lib_b"])
return _exports_test_impl(
ctx = ctx,
dependencies = ["lib_a", "lib_b"],
externs = ["lib_b"],
)

lib_exports_test = analysistest.make(_lib_exports_test_impl)
test_exports_test = analysistest.make(_test_exports_test_impl)
Expand Down

0 comments on commit 295dd31

Please sign in to comment.