mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
ensure we always build roc when running via the helper for tests
This commit is contained in:
parent
f431a2c576
commit
b896f70ddc
1 changed files with 58 additions and 61 deletions
|
@ -11,7 +11,6 @@ use std::env;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, ExitStatus, Stdio};
|
use std::process::{Command, ExitStatus, Stdio};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
@ -30,62 +29,7 @@ where
|
||||||
I: IntoIterator<Item = S>,
|
I: IntoIterator<Item = S>,
|
||||||
S: AsRef<OsStr>,
|
S: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
let roc_binary_path = build_roc_bin_cached();
|
run_roc_with_stdin_and_env(args, stdin_vals, extra_env)
|
||||||
|
|
||||||
run_roc_with_stdin_and_env(&roc_binary_path, args, stdin_vals, extra_env)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we don't already have a /target/release/roc, build it!
|
|
||||||
pub fn build_roc_bin_cached() -> PathBuf {
|
|
||||||
let roc_binary_path = path_to_roc_binary();
|
|
||||||
|
|
||||||
if !roc_binary_path.exists() {
|
|
||||||
build_roc_bin(&[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
roc_binary_path
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_roc_bin(extra_args: &[&str]) -> PathBuf {
|
|
||||||
let roc_binary_path = path_to_roc_binary();
|
|
||||||
|
|
||||||
// Remove the /target/release/roc part
|
|
||||||
let root_project_dir = roc_binary_path
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.parent()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// cargo build --bin roc
|
|
||||||
// (with --release iff the test is being built with --release)
|
|
||||||
let mut args = if cfg!(debug_assertions) {
|
|
||||||
vec!["build", "--bin", "roc"]
|
|
||||||
} else {
|
|
||||||
vec!["build", "--release", "--bin", "roc"]
|
|
||||||
};
|
|
||||||
|
|
||||||
args.extend(extra_args);
|
|
||||||
|
|
||||||
let mut cargo_cmd = cargo();
|
|
||||||
|
|
||||||
cargo_cmd.current_dir(root_project_dir).args(&args);
|
|
||||||
|
|
||||||
let cargo_cmd_str = format!("{:?}", cargo_cmd);
|
|
||||||
|
|
||||||
let cargo_output = cargo_cmd.output().unwrap();
|
|
||||||
|
|
||||||
if !cargo_output.status.success() {
|
|
||||||
panic!(
|
|
||||||
"The following cargo command failed:\n\n {}\n\n stdout was:\n\n {}\n\n stderr was:\n\n {}\n",
|
|
||||||
cargo_cmd_str,
|
|
||||||
String::from_utf8(cargo_output.stdout).unwrap(),
|
|
||||||
String::from_utf8(cargo_output.stderr).unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
roc_binary_path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since glue is always compiling the same plugin, it can not be run in parallel.
|
// Since glue is always compiling the same plugin, it can not be run in parallel.
|
||||||
|
@ -101,7 +45,7 @@ where
|
||||||
{
|
{
|
||||||
let _guard = GLUE_LOCK.lock().unwrap();
|
let _guard = GLUE_LOCK.lock().unwrap();
|
||||||
|
|
||||||
run_roc_with_stdin(&path_to_roc_binary(), args, &[])
|
run_roc_with_stdin(args, &[])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_error(stderr: &str) -> bool {
|
pub fn has_error(stderr: &str) -> bool {
|
||||||
|
@ -170,16 +114,15 @@ pub fn strip_colors(str: &str) -> String {
|
||||||
.replace(ANSI_STYLE_CODES.color_reset, "")
|
.replace(ANSI_STYLE_CODES.color_reset, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_roc_with_stdin<I, S>(path: &Path, args: I, stdin_vals: &[&str]) -> Out
|
pub fn run_roc_with_stdin<I, S>(args: I, stdin_vals: &[&str]) -> Out
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = S>,
|
I: IntoIterator<Item = S>,
|
||||||
S: AsRef<OsStr>,
|
S: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
run_roc_with_stdin_and_env(path, args, stdin_vals, &[])
|
run_roc_with_stdin_and_env(args, stdin_vals, &[])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_roc_with_stdin_and_env<I, S>(
|
pub fn run_roc_with_stdin_and_env<I, S>(
|
||||||
roc_path: &Path,
|
|
||||||
args: I,
|
args: I,
|
||||||
stdin_vals: &[&str],
|
stdin_vals: &[&str],
|
||||||
extra_env: &[(&str, &str)],
|
extra_env: &[(&str, &str)],
|
||||||
|
@ -188,6 +131,7 @@ where
|
||||||
I: IntoIterator<Item = S>,
|
I: IntoIterator<Item = S>,
|
||||||
S: AsRef<OsStr>,
|
S: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
|
let roc_path = build_roc_bin_cached();
|
||||||
let mut roc_cmd = Command::new(roc_path);
|
let mut roc_cmd = Command::new(roc_path);
|
||||||
|
|
||||||
for arg in args {
|
for arg in args {
|
||||||
|
@ -235,6 +179,59 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we don't already have a /target/release/roc, build it!
|
||||||
|
pub fn build_roc_bin_cached() -> PathBuf {
|
||||||
|
let roc_binary_path = path_to_roc_binary();
|
||||||
|
|
||||||
|
if !roc_binary_path.exists() {
|
||||||
|
build_roc_bin(&[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
roc_binary_path
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build_roc_bin(extra_args: &[&str]) -> PathBuf {
|
||||||
|
let roc_binary_path = path_to_roc_binary();
|
||||||
|
|
||||||
|
// Remove the /target/release/roc part
|
||||||
|
let root_project_dir = roc_binary_path
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.parent()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// cargo build --bin roc
|
||||||
|
// (with --release iff the test is being built with --release)
|
||||||
|
let mut args = if cfg!(debug_assertions) {
|
||||||
|
vec!["build", "--bin", "roc"]
|
||||||
|
} else {
|
||||||
|
vec!["build", "--release", "--bin", "roc"]
|
||||||
|
};
|
||||||
|
|
||||||
|
args.extend(extra_args);
|
||||||
|
|
||||||
|
let mut cargo_cmd = cargo();
|
||||||
|
|
||||||
|
cargo_cmd.current_dir(root_project_dir).args(&args);
|
||||||
|
|
||||||
|
let cargo_cmd_str = format!("{:?}", cargo_cmd);
|
||||||
|
|
||||||
|
let cargo_output = cargo_cmd.output().unwrap();
|
||||||
|
|
||||||
|
if !cargo_output.status.success() {
|
||||||
|
panic!(
|
||||||
|
"The following cargo command failed:\n\n {}\n\n stdout was:\n\n {}\n\n stderr was:\n\n {}\n",
|
||||||
|
cargo_cmd_str,
|
||||||
|
String::from_utf8(cargo_output.stdout).unwrap(),
|
||||||
|
String::from_utf8(cargo_output.stderr).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
roc_binary_path
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run_cmd<'a, I: IntoIterator<Item = &'a str>, E: IntoIterator<Item = (&'a str, &'a str)>>(
|
pub fn run_cmd<'a, I: IntoIterator<Item = &'a str>, E: IntoIterator<Item = (&'a str, &'a str)>>(
|
||||||
cmd_name: &str,
|
cmd_name: &str,
|
||||||
stdin_vals: I,
|
stdin_vals: I,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue