Merge pull request #4508 from roc-lang/windows-final-cli-tests

Windows final cli tests
This commit is contained in:
Folkert de Vries 2022-11-16 18:21:49 +01:00 committed by GitHub
commit 0920fb4227
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 243 additions and 128 deletions

View file

@ -186,11 +186,15 @@ pub fn build_zig_host_native(
opt_level: OptLevel,
shared_lib_path: Option<&Path>,
) -> Command {
// to prevent `clang failed with stderr: zig: error: unable to make temporary file: No such file or directory`
let env_userprofile = env::var("USERPROFILE").unwrap_or_else(|_| "".to_string());
let mut zig_cmd = zig();
zig_cmd
.env_clear()
.env("PATH", env_path)
.env("HOME", env_home);
.env("HOME", env_home)
.env("USERPROFILE", env_userprofile);
if let Some(shared_lib_path) = shared_lib_path {
zig_cmd.args(&[
@ -419,7 +423,7 @@ pub fn build_c_host_native(
dest,
sources[0],
find_zig_str_path().to_str().unwrap(),
"x86_64-windows-gnu",
get_target_str(target),
opt_level,
Some(shared_lib_path),
);
@ -578,23 +582,16 @@ pub fn rebuild_host(
shared_lib_path,
)
}
Architecture::X86_64 => {
let target = match target.operating_system {
OperatingSystem::Windows => "x86_64-windows-gnu",
_ => "native",
};
build_zig_host_native(
&env_path,
&env_home,
host_dest.to_str().unwrap(),
zig_host_src.to_str().unwrap(),
zig_str_path.to_str().unwrap(),
target,
opt_level,
shared_lib_path,
)
}
Architecture::X86_64 => build_zig_host_native(
&env_path,
&env_home,
host_dest.to_str().unwrap(),
zig_host_src.to_str().unwrap(),
zig_str_path.to_str().unwrap(),
get_target_str(target),
opt_level,
shared_lib_path,
),
Architecture::X86_32(_) => build_zig_host_native(
&env_path,
&env_home,
@ -636,7 +633,7 @@ pub fn rebuild_host(
// on windows, we need the nightly toolchain so we can use `-Z export-executable-symbols`
// using `+nightly` only works when running cargo through rustup
let mut cmd = rustup();
cmd.args(["run", "nightly", "cargo"]);
cmd.args(["run", "nightly-2022-08-06", "cargo"]);
cmd
} else {
@ -807,6 +804,16 @@ pub fn rebuild_host(
host_dest
}
fn get_target_str(target: &Triple) -> &str {
if target.operating_system == OperatingSystem::Windows
&& target.environment == target_lexicon::Environment::Gnu
{
"x86_64-windows-gnu"
} else {
"native"
}
}
fn nix_path_opt() -> Option<String> {
env::var_os("NIX_GLIBC_PATH").map(|path| path.into_string().unwrap())
}
@ -1227,7 +1234,7 @@ fn link_wasm32(
}
fn link_windows(
_target: &Triple,
target: &Triple,
output_path: PathBuf,
input_paths: &[&str],
link_type: LinkType,
@ -1263,7 +1270,7 @@ fn link_windows(
.args(input_paths)
.args([
"-target",
"x86_64-windows-gnu",
get_target_str(target),
"--subsystem",
"console",
"-lc",
@ -1370,7 +1377,15 @@ pub fn preprocess_host_wasm32(host_input_path: &Path, preprocessed_host_path: &P
}
fn run_build_command(mut command: Command, file_to_build: &str, flaky_fail_counter: usize) {
let cmd_str = format!("{:?}", &command);
let mut command_string = std::ffi::OsString::new();
command_string.push(command.get_program());
for arg in command.get_args() {
command_string.push(" ");
command_string.push(arg);
}
let cmd_str = command_string.to_str().unwrap();
let cmd_output = command.output().unwrap();
let max_flaky_fail_count = 10;
@ -1378,24 +1393,26 @@ fn run_build_command(mut command: Command, file_to_build: &str, flaky_fail_count
match std::str::from_utf8(&cmd_output.stderr) {
Ok(stderr) => {
// flaky error seen on macos 12 apple silicon, related to https://github.com/ziglang/zig/issues/9711
if stderr.contains("unable to save cached ZIR code") && flaky_fail_counter < max_flaky_fail_count {
run_build_command(command, file_to_build, flaky_fail_counter + 1)
if stderr.contains("unable to save cached ZIR code") {
if flaky_fail_counter < max_flaky_fail_count {
run_build_command(command, file_to_build, flaky_fail_counter + 1)
} else {
internal_error!(
"Error:\n Failed to rebuild {} {} times, this is not a flaky failure:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
max_flaky_fail_count,
cmd_str,
stderr
)
}
} else {
internal_error!(
"Error:\n Failed to rebuild {} {} times, this is not a flaky failure:\n The executed command was:\n {}\n stderr of that command:\n {}",
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
max_flaky_fail_count,
cmd_str,
stderr
)
}
internal_error!(
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
cmd_str,
stderr
)
},
Err(utf8_err) => internal_error!(
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command could not be parsed as valid utf8:\n {}",

View file

@ -222,8 +222,12 @@ fn run_command(mut command: Command, flaky_fail_counter: usize) {
} else {
run_command(command, flaky_fail_counter + 1)
}
} else if error_str
.contains("lld-link: error: failed to write the output file: Permission denied")
{
panic!("{} failed with:\n\n {}\n\nWorkaround:\n\n Re-run the cargo command that triggered this build.\n\n", command_str, error_str);
} else {
panic!("{} failed: {}", command_str, error_str);
panic!("{} failed with:\n\n {}\n", command_str, error_str);
}
}
},

View file

@ -13,6 +13,11 @@ pub mod spaces;
use bumpalo::{collections::String, Bump};
use roc_parse::ast::Module;
#[cfg(windows)]
const NEWLINE: &str = "\r\n";
#[cfg(not(windows))]
const NEWLINE: &str = "\n";
#[derive(Debug)]
pub struct Ast<'a> {
pub module: Module<'a>,
@ -99,7 +104,9 @@ impl<'a> Buf<'a> {
pub fn newline(&mut self) {
self.spaces_to_flush = 0;
self.text.push('\n');
self.text.push_str(NEWLINE);
self.beginning_of_line = true;
}
@ -183,14 +190,14 @@ fn fmt_text_eof(text: &mut bumpalo::collections::String<'_>) {
// There's some whitespace at the end of this file, but the first
// whitespace char after the last non-whitespace char isn't a newline.
// So replace that whitespace char (and everything after it) with a newline.
text.replace_range(last_whitespace_index.., "\n");
text.replace_range(last_whitespace_index.., NEWLINE);
}
None => {
debug_assert!(last_whitespace_index == text.len());
debug_assert!(!text.ends_with(char::is_whitespace));
// This doesn't end in whitespace at all, so add a newline.
text.push('\n');
text.push_str(NEWLINE);
}
}
}

View file

@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use bumpalo::Bump;
use roc_module::symbol::ModuleId;
#[cfg(not(windows))]
const ROC_SKIP_SUBS_CACHE: &str = "ROC_SKIP_SUBS_CACHE";
const SKIP_SUBS_CACHE: bool = {