Skip to content

Commit

Permalink
Merge pull request #9 from djmarcin/rust_analyzer_2
Browse files Browse the repository at this point in the history
Use bazel-like space separated target specification
  • Loading branch information
UebelAndre committed Nov 16, 2021
2 parents 6cbd381 + 0d71669 commit 508d85b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
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('@') {
"" => "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>,
}

0 comments on commit 508d85b

Please sign in to comment.