Skip to content

Commit

Permalink
specify escript path from cli
Browse files Browse the repository at this point in the history
Summary: the same as previous diff but for `escript`

Reviewed By: alanz

Differential Revision: D56197690

fbshipit-source-id: d40eaf1b3be15331373ed5db9000ff4b62ecaf89
  • Loading branch information
perehonchuk authored and facebook-github-bot committed Apr 17, 2024
1 parent 0d5865c commit b92293b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/elp/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ pub struct Args {
pub log_file: Option<PathBuf>,
#[bpaf(argument("ERL"))]
pub erl: Option<PathBuf>,
#[bpaf(argument("ESCRIPT"))]
pub escript: Option<PathBuf>,
pub no_log_buffering: bool,
#[bpaf(external(command))]
pub command: Command,
Expand Down
7 changes: 7 additions & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use bpaf::batteries;
use elp::cli;
use elp::cli::Cli;
use elp::ServerSetup;
use elp_ide::erlang_service::ESCRIPT;
use elp_log::timeit;
use elp_log::FileLogger;
use elp_log::Logger;
Expand Down Expand Up @@ -85,6 +86,12 @@ fn setup_static(args: &Args) {
let mut erl = ERL.write().unwrap();
*erl = path.to_string_lossy().to_string();
}

if let Some(escript) = &args.escript {
let path = fs::canonicalize(escript).expect("escript path should be valid");
let mut escript = ESCRIPT.write().unwrap();
*escript = path.to_string_lossy().to_string();
}
}

fn try_main(cli: &mut dyn Cli, args: Args) -> Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion crates/elp/src/resources/test/help.stdout
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Usage: [--log-file LOG_FILE] [--erl ERL] [--no-log-buffering] [COMMAND ...]
Usage: [--log-file LOG_FILE] [--erl ERL] [--escript ESCRIPT] [--no-log-buffering] [COMMAND ...]

Available options:
--log-file <LOG_FILE>
--erl <ERL>
--escript <ESCRIPT>
--no-log-buffering
-h, --help Prints help information

Expand Down
9 changes: 8 additions & 1 deletion crates/erlang_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::process::ChildStdout;
use std::process::Command;
use std::process::Stdio;
use std::sync::Arc;
use std::sync::RwLock;
use std::time::Duration;

use anyhow::anyhow;
Expand Down Expand Up @@ -46,6 +47,10 @@ use text_size::TextRange;

pub mod common_test;

lazy_static! {
pub static ref ESCRIPT: RwLock<String> = RwLock::new("escript".to_string());
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum DiagnosticLocation {
Normal(TextRange),
Expand Down Expand Up @@ -324,7 +329,9 @@ impl Connection {
let mut escript = Builder::new().prefix("erlang_service").tempfile()?;
escript.write_all(escript_src)?;

let mut cmd = Command::new("escript");
let escript_bin = ESCRIPT.read().unwrap();

let mut cmd = Command::new(&*escript_bin);
cmd.arg(escript.path());

cmd.stdin(Stdio::piped())
Expand Down

0 comments on commit b92293b

Please sign in to comment.