Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bazel-like space separated target specification #9

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/rust_analyzer/aquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn get_crate_specs(
bazel: &Path,
workspace: &Path,
execution_root: &Path,
targets: &[&str],
targets: &[String],
rules_rust_name: &str,
) -> anyhow::Result<Vec<CrateSpec>> {
log::debug!("Get crate specs with targets: {:?}", targets);
Expand Down
6 changes: 3 additions & 3 deletions tools/rust_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn generate_crate_info(
bazel: impl AsRef<Path>,
workspace: impl AsRef<Path>,
rules_rust: impl AsRef<str>,
targets: &[&str],
targets: &[String],
) -> anyhow::Result<()> {
log::debug!("Building rust_analyzer_crate_spec files for {:?}", targets);

Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn write_rust_project(
bazel: impl AsRef<Path>,
workspace: impl AsRef<Path>,
rules_rust_name: &impl AsRef<str>,
targets: &[&str],
targets: &[String],
execution_root: impl AsRef<Path>,
rust_project_path: impl AsRef<Path>,
) -> anyhow::Result<()> {
Expand All @@ -53,7 +53,7 @@ pub fn write_rust_project(
rules_rust_name.as_ref(),
)?;

let workspace_name = match rules_rust_name.as_ref().trim_start_matches("@") {
let workspace_name = match rules_rust_name.as_ref().trim_start_matches('@') {
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
"" => "rules_rust",
s => s,
};
Expand Down
17 changes: 10 additions & 7 deletions tools/rust_analyzer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ fn main() -> anyhow::Result<()> {
.as_ref()
.expect("failed to find execution root, is --execution-root set correctly?");

let targets: Vec<&str> = config.targets.split(',').collect();

let rules_rust_name = env!("ASPECT_REPOSITORY");

// Generate the crate specs.
generate_crate_info(&config.bazel, &workspace_root, &rules_rust_name, &targets)?;
generate_crate_info(
&config.bazel,
&workspace_root,
&rules_rust_name,
&config.targets,
)?;

// Use the generated files to write rust-project.json.
write_rust_project(
&config.bazel,
&workspace_root,
&rules_rust_name,
&targets,
&config.targets,
&execution_root,
&workspace_root.join("rust-project.json"),
)?;
Expand Down Expand Up @@ -111,7 +114,7 @@ struct Config {
#[structopt(long, default_value = "bazel")]
bazel: PathBuf,

/// Comma-separated list of target patterns
#[structopt(long, default_value = "@//...")]
targets: String,
// Space separated list of target patterns that comes after all other args.
#[structopt(default_value = "@//...")]
targets: Vec<String>,
}