Skip to content

Commit

Permalink
prelude/rust: Process CARGO_MANIFEST_DIR during rustdoc test
Browse files Browse the repository at this point in the history
Summary:
Rustdoc tests were not getting the `CARGO_MANIFEST_DIR` processing that
we do for all other compilations.

Reviewed By: dtolnay

Differential Revision: D50303301

fbshipit-source-id: 1c3171e7eccc2d1a0461aa93b65ff82ac880c8c0
  • Loading branch information
zertosh authored and facebook-github-bot committed Oct 15, 2023
1 parent b6e1389 commit 98a6e7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
21 changes: 18 additions & 3 deletions prelude/rust/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def generate_rustdoc_test(
link_style: LinkStyle,
library: RustLinkStyleInfo,
params: BuildParams,
default_roots: list[str]) -> cmd_args:
default_roots: list[str]) -> (cmd_args, dict[str, cmd_args]):
exec_is_windows = ctx.attrs._exec_os_type[OsLookup].platform == "windows"

toolchain_info = compile_ctx.toolchain_info

resources = create_resource_db(
Expand Down Expand Up @@ -272,7 +274,7 @@ def generate_rustdoc_test(
allow_args = True,
)

if ctx.attrs._exec_os_type[OsLookup].platform == "windows":
if exec_is_windows:
runtool = ["--runtool=cmd.exe", "--runtool-arg=/V:OFF", "--runtool-arg=/C"]
else:
runtool = ["--runtool=/usr/bin/env"]
Expand All @@ -297,13 +299,26 @@ def generate_rustdoc_test(

rustdoc_cmd.hidden(compile_ctx.symlinked_srcs, link_args_output.hidden, runtime_files)

return _long_command(
rustdoc_cmd = _long_command(
ctx = ctx,
exe = toolchain_info.rustdoc,
args = rustdoc_cmd,
argfile_name = "{}.args".format(common_args.subdir),
)

plain_env, path_env = _process_env(compile_ctx, ctx.attrs.env, exec_is_windows)
rustdoc_env = plain_env | path_env

# Pass everything in env + doc_env, except ones with value None in doc_env.
for k, v in ctx.attrs.doc_env.items():
if v == None:
rustdoc_env.pop(k, None)
else:
rustdoc_env[k] = cmd_args(v)
rustdoc_env["RUSTC_BOOTSTRAP"] = cmd_args("1") # for `-Zunstable-options`

return (rustdoc_cmd, rustdoc_env)

# Generate multiple compile artifacts so that distinct sets of artifacts can be
# generated concurrently.
def rust_compile_multi(
Expand Down
18 changes: 4 additions & 14 deletions prelude/rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ def rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
providers = []

providers += _default_providers(
ctx = ctx,
lang_style_param = lang_style_param,
param_artifact = rust_param_artifact,
rustdoc = rustdoc,
Expand Down Expand Up @@ -463,11 +462,10 @@ def _handle_rust_artifact(
)

def _default_providers(
ctx: AnalysisContext,
lang_style_param: dict[(LinkageLang, LinkStyle), BuildParams],
param_artifact: dict[BuildParams, RustLinkStyleInfo],
rustdoc: Artifact,
rustdoc_test: [cmd_args, None],
rustdoc_test: [(cmd_args, dict[str, cmd_args]), None],
check_artifacts: dict[str, Artifact],
expand: Artifact,
sources: Artifact) -> list[Provider]:
Expand Down Expand Up @@ -495,20 +493,12 @@ def _default_providers(
providers = []

if rustdoc_test:
# Pass everything in env + doc_env, except ones with value None in doc_env.
doc_env = dict(ctx.attrs.env)
for k, v in ctx.attrs.doc_env.items():
if v == None:
doc_env.pop(k, None)
else:
doc_env[k] = v
doc_env["RUSTC_BOOTSTRAP"] = "1" # for `-Zunstable-options`

(rustdoc_cmd, rustdoc_env) = rustdoc_test
rustdoc_test_info = ExternalRunnerTestInfo(
type = "rustdoc",
command = [rustdoc_test],
command = [rustdoc_cmd],
run_from_project_root = True,
env = doc_env,
env = rustdoc_env,
)

# Run doc test as part of `buck2 test :crate`
Expand Down

0 comments on commit 98a6e7b

Please sign in to comment.