-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
602a26d
commit 2f45838
Showing
25 changed files
with
254 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ | |
|
||
# BazelCI | ||
bazelci.py | ||
|
||
# rust-analyzer | ||
rust-project.json |
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
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,5 @@ | ||
sh_binary( | ||
name = "rust_analyzer_test", | ||
srcs = ["rust_analyzer_test_runner.sh"], | ||
args = [package_name()], | ||
) |
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
7 changes: 3 additions & 4 deletions
7
test/rust_analyzer/aspect_traversal_test/rust_project_json_test.rs
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
9 changes: 4 additions & 5 deletions
9
test/rust_analyzer/merging_crates_test/rust_project_json_test.rs
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use runfiles::Runfiles; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
#[test] | ||
fn test_deps_of_crate_and_its_test_are_merged() { | ||
let r = Runfiles::create().unwrap(); | ||
let rust_project_path = | ||
r.rlocation("rules_rust/test/rust_analyzer/merging_crates_test/rust-project.json"); | ||
let rust_project_path = PathBuf::from(env::var("RUST_PROJECT_JSON").unwrap()); | ||
|
||
let content = std::fs::read_to_string(&rust_project_path) | ||
.unwrap_or_else(|_| panic!("couldn't open {:?}", &rust_project_path)); | ||
|
||
assert!( | ||
content.contains(r#""root_module":"test/rust_analyzer/merging_crates_test/mylib.rs","deps":[{"crate":0,"name":"lib_dep"},{"crate":2,"name":"extra_test_dep"}]"#), | ||
content.contains(r#""root_module":"mylib.rs","edition":"2018","deps":[{"crate":0,"name":"extra_test_dep"},{"crate":1,"name":"lib_dep"}]"#), | ||
"expected rust-project.json to contain both lib_dep and extra_test_dep in deps of mylib.rs."); | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
test/rust_analyzer/merging_crates_test_reversed/BUILD.bazel
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
test/rust_analyzer/merging_crates_test_reversed/extra_test_dep.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
test/rust_analyzer/merging_crates_test_reversed/rust_project_json_test.rs
This file was deleted.
Oops, something went wrong.
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,94 @@ | ||
#!/bin/bash | ||
|
||
# Runs Bazel build commands over rustfmt rules, where some are expected | ||
# to fail. | ||
# | ||
# Can be run from anywhere within the rules_rust workspace. | ||
|
||
set -euo pipefail | ||
|
||
if [[ -z "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then | ||
echo "This script should be run under Bazel" | ||
exit 1 | ||
fi | ||
|
||
PACKAGE_NAME="$1" | ||
if [[ -z "${PACKAGE_NAME:-}" ]]; then | ||
echo "The first argument should be the package name of the test target" | ||
exit 1 | ||
fi | ||
|
||
function generate_workspace() { | ||
local temp_dir="$(mktemp -d -t rules_rust_test_rust_analyzer-XXXXXXXXXX)" | ||
local new_workspace="${temp_dir}/rules_rust_test_rust_analyzer" | ||
|
||
mkdir -p "${new_workspace}" | ||
cat << EOF > "${new_workspace}/WORKSPACE.bazel" | ||
workspace(name = "rules_rust_test_rust_analyzer") | ||
local_repository( | ||
name = "rules_rust", | ||
path = "${BUILD_WORKSPACE_DIRECTORY}", | ||
) | ||
load("@rules_rust//rust:repositories.bzl", "rust_repositories") | ||
rust_repositories(include_rustc_srcs = True) | ||
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_deps") | ||
rust_analyzer_deps() | ||
EOF | ||
|
||
cat << EOF > "${new_workspace}/.bazelrc" | ||
build --keep_going | ||
test --test_output=errors | ||
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect | ||
build:strict --output_groups=+rustfmt_checks | ||
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect | ||
build:strict --output_groups=+clippy_checks | ||
EOF | ||
|
||
echo "${new_workspace}" | ||
} | ||
|
||
function rust_analyzer_test() { | ||
local source_dir="$1" | ||
local workspace="$2" | ||
|
||
echo "Testing '$(basename "${source_dir}")'" | ||
rm -f "${workspace}"/*.rs "${workspace}"/*.json "${workspace}/BUILD.bazel" | ||
cp -r "${source_dir}"/* "${workspace}" | ||
|
||
# Drop the 'manual' tags | ||
if [ "$(uname)" == "Darwin" ]; then | ||
SEDOPTS=(-i '' -e) | ||
else | ||
SEDOPTS=(-i) | ||
fi | ||
sed ${SEDOPTS[@]} 's/"manual"//' "${workspace}/BUILD.bazel" | ||
|
||
pushd "${workspace}" &> /dev/null | ||
echo "Generating rust-project.json..." | ||
bazel run "@rules_rust//tools/rust_analyzer:gen_rust_project" | ||
echo "Building..." | ||
bazel build //... | ||
echo "Testing..." | ||
bazel test //... | ||
echo "Building with Aspects..." | ||
bazel build //... --config=strict | ||
popd &> /dev/null | ||
} | ||
|
||
function run_test_suite() { | ||
local temp_workspace="$(generate_workspace)" | ||
echo "Generated workspace: ${temp_workspace}" | ||
|
||
for test_dir in "${BUILD_WORKSPACE_DIRECTORY}/${PACKAGE_NAME}"/*; do | ||
# Skip everything but directories | ||
if [[ ! -d "${test_dir}" ]]; then | ||
continue | ||
fi | ||
|
||
rust_analyzer_test "${test_dir}" "${temp_workspace}" | ||
done | ||
|
||
rm -rf "${temp_workspace}" | ||
} | ||
|
||
run_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
Oops, something went wrong.