Skip to content

Commit

Permalink
allow passing compiler version via cmdline arg, to try using a really…
Browse files Browse the repository at this point in the history
… old compiler that still supports save-analysis
  • Loading branch information
wfraser committed Aug 24, 2023
1 parent a72332c commit 4da3053
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Analysis {
}

impl Analysis {
pub fn generate(workspace_path: impl AsRef<Path>) -> Result<(), String> {
pub fn generate(workspace_path: impl AsRef<Path>, compiler: &str) -> Result<(), String> {
let config_json = serde_json::to_string(
&rls_data::config::Config {
output_file: None, // use default paths
Expand All @@ -28,7 +28,7 @@ impl Analysis {
.expect("failed to json-serialize rust analysis configuration");

let cargo_status = Command::new("cargo")
.arg("+nightly")
.arg(format!("+{compiler}"))
.arg("check")
.arg("--target-dir")
.arg(Path::new("target").join(SUBDIR))
Expand Down
29 changes: 24 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,37 @@ use rsbrowse::ui;

struct Arguments {
workspace_path: PathBuf,
compiler: String,
}

fn usage() {
eprintln!("usage: {} <cargo workspace path>", std::env::args().next().unwrap());
}

fn parse_args() -> Option<Arguments> {
let workspace_path: PathBuf = std::env::args_os()
.nth(1)?
.into();
let mut args = std::env::args_os().skip(1);
let mut path = None;
let mut compiler = "nightly".to_owned();
loop {
let arg = match args.next() {
Some(a) => a,
None => break,
};
match arg.to_str() {
Some("--compiler") => {
compiler = args.next()?.to_string_lossy().into_owned();
}
_ => {
if path.is_some() {
return None;
}
path = Some(arg);
}
}
}
Some(Arguments {
workspace_path,
workspace_path: path?.into(),
compiler,
})
}

Expand All @@ -29,7 +48,7 @@ fn main() {
});

eprintln!("Running Cargo to generate analysis data...");
Analysis::generate(&args.workspace_path).unwrap();
Analysis::generate(&args.workspace_path, &args.compiler).unwrap();

eprintln!("Reading analysis data...");
let analysis = Analysis::load(&args.workspace_path);
Expand Down

0 comments on commit 4da3053

Please sign in to comment.