Skip to content

Commit

Permalink
Fixed buildifier defects
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Feb 11, 2022
1 parent 3e78dc5 commit b6ec062
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
3 changes: 0 additions & 3 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,6 @@ def _make_link_flags_default(linker_input):
ret.extend(_portable_link_flags(lib))
return ret

def _libraries_dirnames(linker_input):
return [get_preferred_artifact(lib).dirname for lib in linker_input.libraries]

def _add_native_link_flags(args, dep_info, linkstamp_outs, crate_type, toolchain, cc_toolchain, feature_configuration):
"""Adds linker flags for all dependencies of the current target.
Expand Down
13 changes: 3 additions & 10 deletions rust/private/rustdoc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load("//rust/private:common.bzl", "rust_common")
load("//rust/private:rustdoc.bzl", "rustdoc_compile_action")
load("//rust/private:utils.bzl", "dedent", "find_toolchain")

def _construct_writer_arguments(ctx, test_runner, action, crate_info, rust_toolchain):
def _construct_writer_arguments(ctx, test_runner, action, crate_info):
"""Construct arguments and environment variables specific to `rustdoc_test_writer`.
This is largely solving for the fact that tests run from a runfiles directory
Expand All @@ -30,28 +30,22 @@ def _construct_writer_arguments(ctx, test_runner, action, crate_info, rust_toolc
test_runner (File): The test_runner output file declared by `rustdoc_test`.
action (struct): Action arguments generated by `rustdoc_compile_action`.
crate_info (CrateInfo): The provider of the crate who's docs are being tested.
rust_toolchain (rust_toolchain): The currently configured `rust_toolchain`.
Returns:
tuple: A tuple of `rustdoc_test_writer` specific inputs
- Args: Arguments for the test writer
- dict: Required environment variables
"""

# Set the SYSROOT to the directory of the rust_lib files passed to the toolchain
env = {
"SYSROOT": "${{pwd}}/{}".format(rust_toolchain.sysroot),
}

writer_args = ctx.actions.args()

# Track the output path where the test writer should write the test
writer_args.add("--output={}".format(test_runner.path))

# Track what environment variables should be written to the test runner
writer_args.add("--action_env=DEVELOPER_DIR")
writer_args.add("--action_env=SDKROOT")
writer_args.add("--action_env=PATHEXT")
writer_args.add("--action_env=SDKROOT")
writer_args.add("--action_env=SYSROOT")
for var in action.env.keys():
writer_args.add("--action_env={}".format(var))
Expand Down Expand Up @@ -113,7 +107,7 @@ def _rust_doc_test_impl(ctx):

action = rustdoc_compile_action(
ctx = ctx,
toolchain = find_toolchain(ctx),
toolchain = toolchain,
crate_info = crate_info,
rustdoc_flags = rustdoc_flags,
is_test = True,
Expand All @@ -126,7 +120,6 @@ def _rust_doc_test_impl(ctx):
test_runner = test_runner,
action = action,
crate_info = crate_info,
rust_toolchain = toolchain,
)

# Allow writer environment variables to override those from the action.
Expand Down
48 changes: 26 additions & 22 deletions test/unit/native_deps/native_deps_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ def _rlib_has_no_native_libs_test_impl(ctx):
assert_argv_contains_prefix_not(env, action, "--codegen=linker=")
return analysistest.end(env)

def _dylib_has_native_libs_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
action = tut.actions[0]
assert_argv_contains(env, action, "--crate-type=dylib")
assert_argv_contains(env, action, "-lstatic=native_dep")
assert_argv_contains_prefix(env, action, "--codegen=linker=")
return analysistest.end(env)

def _cdylib_has_native_libs_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
Expand Down Expand Up @@ -118,24 +109,37 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx):
tut = analysistest.target_under_test(env)
action = tut.actions[0]

linker_args = _extract_linker_args(action.argv)

if ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo]):
# Determine the macos min version
macosx_version_min = "12.1"
for linker_arg in linker_args:
for arg in linker_arg.split(" "):
if "-mmacosx-version-min" in arg:
_, _, val = arg.partition("=")
macosx_version_min = val

want = [
"-lstatic=native_dep",
"link-args=-lc++ -fobjc-link-runtime -headerpad_max_install_names -no-canonical-prefixes -target x86_64-apple-macosx -mmacosx-version-min={} -lc++ -target x86_64-apple-macosx".format(macosx_version_min),
"link-arg=bazel-out/darwin-fastbuild/bin/test/unit/native_deps/libnative_dep.a",
"link-arg=-Wl,-force_load,bazel-out/darwin-fastbuild/bin/test/unit/native_deps/libalwayslink.lo",
]
elif ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]):
want = [
"-lstatic=native_dep",
"link-args=/nologo /SUBSYSTEM:CONSOLE /MACHINE:X64 /DEFAULTLIB:msvcrt.lib /DEBUG:FASTLINK /INCREMENTAL:NO",
"link-arg=bazel-out/x64_windows-fastbuild/bin/test/unit/native_deps/native_dep.lib",
"link-arg=/WHOLEARCHIVE:bazel-out/x64_windows-fastbuild/bin/test/unit/native_deps/alwayslink.lo.lib",
]
else:
want = [
"link-args=-fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -lstdc++ -lm",
"link-arg=bazel-out/k8-fastbuild/bin/test/unit/native_deps/libnative_dep.a",
"link-arg=-Wl,--whole-archive",
"link-arg=bazel-out/k8-fastbuild/bin/test/unit/native_deps/libalwayslink.lo",
"link-arg=-Wl,--no-whole-archive",
]
asserts.equals(env, want, _extract_linker_args(action.argv))
asserts.equals(env, want, linker_args)
return analysistest.end(env)

rlib_has_no_native_libs_test = analysistest.make(_rlib_has_no_native_libs_test_impl)
Expand All @@ -159,7 +163,7 @@ bin_has_native_dep_and_alwayslink_test = analysistest.make(_bin_has_native_dep_a
"_macos_constraint": attr.label(default = Label("@platforms//os:macos")),
"_windows_constraint": attr.label(default = Label("@platforms//os:windows")),
})
cdylib_has_native_dep_and_alwayslink_test = analysistest.make(_cdylib_has_native_libs_test_impl, attrs = {
cdylib_has_native_dep_and_alwayslink_test = analysistest.make(_cdylib_has_native_dep_and_alwayslink_test_impl, attrs = {
"_macos_constraint": attr.label(default = Label("@platforms//os:macos")),
"_windows_constraint": attr.label(default = Label("@platforms//os:windows")),
})
Expand Down Expand Up @@ -336,7 +340,7 @@ def _additional_deps_test():
cc_library(
name = "additional_deps_cc",
srcs = ["native_dep.cc"],
linkopts = ["-L$(location :dynamic.lds)"],
linkopts = ["-L$(execpath :dynamic.lds)"],
deps = [":dynamic.lds"],
)

Expand Down Expand Up @@ -368,16 +372,16 @@ def native_deps_test_suite(name):
native.test_suite(
name = name,
tests = [
":rlib_has_no_native_libs_test",
":staticlib_has_native_libs_test",
":cdylib_has_native_libs_test",
":proc_macro_has_native_libs_test",
":bin_has_native_libs_test",
":bin_has_native_dep_and_alwayslink_test",
":cdylib_has_native_dep_and_alwayslink_test",
":native_linkopts_propagate_test",
":bin_has_additional_deps_test",
":bin_has_native_dep_and_alwayslink_test",
":bin_has_native_libs_test",
":cdylib_has_additional_deps_test",
":cdylib_has_native_dep_and_alwayslink_test",
":cdylib_has_native_libs_test",
":lib_has_no_additional_deps_test",
":native_linkopts_propagate_test",
":proc_macro_has_native_libs_test",
":rlib_has_no_native_libs_test",
":staticlib_has_native_libs_test",
],
)

0 comments on commit b6ec062

Please sign in to comment.