-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use crate_info.deps and others instead of ctx.rule.attr.deps in rust …
…analyzer aspect
- Loading branch information
Showing
12 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
load("//rust:defs.bzl", "rust_analyzer", "rust_library", "rust_proc_macro", "rust_test") | ||
|
||
rust_library( | ||
name = "mylib", | ||
srcs = ["mylib.rs"], | ||
proc_macro_deps = [":proc_macro_dep"], | ||
deps = [":lib_dep"], | ||
) | ||
|
||
rust_library( | ||
name = "lib_dep", | ||
srcs = ["lib_dep.rs"], | ||
) | ||
|
||
rust_proc_macro( | ||
name = "proc_macro_dep", | ||
srcs = ["proc_macro_dep.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "mylib_test", | ||
crate = ":mylib", | ||
proc_macro_deps = [":extra_proc_macro_dep"], | ||
deps = [":extra_test_dep"], | ||
) | ||
|
||
rust_library( | ||
name = "extra_test_dep", | ||
srcs = ["extra_test_dep.rs"], | ||
) | ||
|
||
rust_proc_macro( | ||
name = "extra_proc_macro_dep", | ||
srcs = ["extra_proc_macro_dep.rs"], | ||
) | ||
|
||
rust_analyzer( | ||
name = "rust_analyzer", | ||
testonly = True, | ||
targets = [":mylib_test"], | ||
) | ||
|
||
rust_test( | ||
name = "rust_project_json_test", | ||
srcs = ["rust_project_json_test.rs"], | ||
args = ["$(location :rust-project.json)"], | ||
data = [":rust-project.json"], | ||
harness = False, | ||
) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::env; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
let rust_project_path = args.get(1).expect("expected rust-project.json path as first argument."); | ||
let content = std::fs::read_to_string(rust_project_path).expect(&format!("couldn't open {}", rust_project_path)); | ||
|
||
for dep in &["lib_dep", "extra_test_dep", "proc_macro_dep", "extra_proc_macro_dep"] { | ||
if !content.contains(dep) { | ||
panic!("expected rust-project.json to contain {}.", dep); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load(":rust_analyzer_test.bzl", "rust_analyzer_test_suite") | ||
|
||
############################ UNIT TESTS ############################# | ||
rust_analyzer_test_suite(name = "rust_analyzer_test_suite") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Unittests for rust rules.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
|
||
# This is an unittest for rust_analyzer.bzl, violating private visibility is necessary. | ||
# buildifier: disable=bzl-visibility | ||
load("//rust:defs.bzl", "rust_analyzer", "rust_library") | ||
|
||
def _rust_analyzer_hello_world_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
tut = analysistest.target_under_test(env) | ||
asserts.true(env, len(tut.actions) == 1, "expected one action, got %s" % len(tut.actions)) | ||
action = tut.actions[0] | ||
outputs = action.outputs.to_list() | ||
asserts.true(env, len(outputs) == 1, "expected one output, got %s" % len(outputs)) | ||
output = outputs[0] | ||
asserts.true(env, output.path.endswith("rust-project.json")) | ||
return analysistest.end(env) | ||
|
||
rust_analyzer_hello_world_test = analysistest.make(_rust_analyzer_hello_world_test_impl) | ||
|
||
def _rust_analyzer_test(): | ||
rust_library( | ||
name = "mylib", | ||
srcs = ["mylib.rs"], | ||
) | ||
|
||
rust_analyzer( | ||
name = "rust_analyzer", | ||
testonly = True, | ||
targets = [":mylib"], | ||
) | ||
|
||
rust_analyzer_hello_world_test( | ||
name = "rust_analyzer_hello_world_test", | ||
target_under_test = ":rust_analyzer", | ||
) | ||
|
||
def rust_analyzer_test_suite(name): | ||
"""Entry-point macro called from the BUILD file. | ||
Args: | ||
name: Name of the macro. | ||
""" | ||
_rust_analyzer_test() | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":rust_analyzer_hello_world_test", | ||
], | ||
) |