#![allow(dead_code)]
use assert_cmd::Command;
use cabin_build::Dialect;
mod fake_ports;
mod foundation_port_smoke;
mod port_schema;
#[allow(unused_imports)]
pub use fake_ports::{FakeArchiveServer, FakePortRepo};
#[allow(unused_imports)]
pub use foundation_port_smoke::{
PortBuildRun, PortCacheLifecycle, run_port_build_then_run, run_port_cache_lifecycle,
};
#[allow(unused_imports)]
pub use port_schema::{
assert_builtin_port_bundled_and_parses, assert_tar_gz_source, builtin_overlay,
load_real_port_and_assert_schema,
};
pub fn host_exe(stem: &str) -> String {
Dialect::host_default().executable_name(stem)
}
pub fn host_static_lib(stem: &str) -> String {
Dialect::host_default().static_library_name(stem)
}
pub fn host_obj_ext() -> &'static str {
Dialect::host_default().object_extension()
}
pub fn host_path(unix_relpath: &str) -> String {
unix_relpath.replace('/', std::path::MAIN_SEPARATOR_STR)
}
pub fn program_from_command(cmd: &str) -> String {
let cmd = cmd.trim_start();
if let Some(rest) = cmd.strip_prefix('"')
&& let Some(end) = rest.find('"')
{
return rest[..end].to_owned();
}
cmd.split_whitespace().next().unwrap_or("").to_owned()
}
pub fn host_std_cxx_flag() -> &'static str {
match Dialect::host_default() {
Dialect::GnuLike => "-std=c++17",
Dialect::Msvc => "/std:c++17",
}
}
pub fn host_release_opt_flag() -> &'static str {
match Dialect::host_default() {
Dialect::GnuLike => "-O3",
Dialect::Msvc => "/O2",
}
}
pub fn host_no_opt_flag() -> &'static str {
match Dialect::host_default() {
Dialect::GnuLike => "-O0",
Dialect::Msvc => "/Od",
}
}
pub fn host_define_ndebug_flag() -> &'static str {
match Dialect::host_default() {
Dialect::GnuLike => "-DNDEBUG",
Dialect::Msvc => "/DNDEBUG",
}
}
pub fn host_debug_info_flag() -> &'static str {
match Dialect::host_default() {
Dialect::GnuLike => "-g",
Dialect::Msvc => "/Z7",
}
}
pub fn manifest_dir_read_error() -> &'static str {
if cfg!(windows) {
"Access is denied"
} else {
"Is a directory"
}
}
pub fn cabin() -> Command {
let mut cmd = Command::cargo_bin("cabin").expect("the `cabin` binary should be built by cargo");
cmd.env("CABIN_NO_CONFIG", "1")
.env_remove("CABIN_CONFIG")
.env_remove("CABIN_CONFIG_HOME");
for key in [
"CC",
"CXX",
"AR",
"NINJA",
"CFLAGS",
"CXXFLAGS",
"CPPFLAGS",
"LDFLAGS",
"CABIN_NET_OFFLINE",
"CABIN_RESOLVER_INCOMPATIBLE_STANDARDS",
"CABIN_COMPILER_WRAPPER",
"CABIN_CACHE_DIR",
"CABIN_CACHE_HOME",
"CABIN_FMT",
"CABIN_TIDY",
"CABIN_PKG_CONFIG",
"PKG_CONFIG_PATH",
"PKG_CONFIG_LIBDIR",
"PKG_CONFIG_SYSROOT_DIR",
"NO_COLOR",
"CLICOLOR",
"CLICOLOR_FORCE",
] {
cmd.env_remove(key);
}
cmd.env("CABIN_TERM_COLOR", "never");
pin_test_cache_home(&mut cmd);
cmd
}
pub fn pin_test_cache_home(cmd: &mut Command) {
cmd.env(
"CABIN_CACHE_HOME",
std::env::temp_dir().join("cabin-tests-cache-home"),
);
}
pub fn command_exists(name: &str) -> bool {
which::which(name).is_ok()
}
pub fn ninja_available() -> bool {
command_exists("ninja")
}
pub fn c_compiler_available() -> bool {
["cc", "clang", "gcc"]
.iter()
.any(|name| command_exists(name))
|| msvc_cl_available()
}
pub fn cxx_compiler_available() -> bool {
["c++", "clang++", "g++"]
.iter()
.any(|name| command_exists(name))
|| msvc_cl_available()
}
fn msvc_cl_available() -> bool {
cfg!(windows) && (command_exists("cl") || cabin_toolchain::msvc::msvc_tool_path("cl").is_some())
}
pub fn cxx_build_tools_available() -> bool {
ninja_available() && cxx_compiler_available()
}
pub fn c_and_cxx_build_tools_available() -> bool {
ninja_available() && c_compiler_available() && cxx_compiler_available()
}
pub fn require_c_and_cxx_build_tools() {
let mut missing = Vec::new();
if !ninja_available() {
missing.push("ninja");
}
if !c_compiler_available() {
missing.push("a C compiler (cc/clang/gcc)");
}
if !cxx_compiler_available() {
missing.push("a C++ compiler (c++/clang++/g++)");
}
assert!(
c_and_cxx_build_tools_available(),
"C/C++ build tools required for this test are missing on PATH: {}; install them",
missing.join(", "),
);
}
pub fn require_cxx_build_tools() {
let mut missing = Vec::new();
if !ninja_available() {
missing.push("ninja");
}
if !cxx_compiler_available() {
missing.push("a C++ compiler (c++/clang++/g++)");
}
assert!(
cxx_build_tools_available(),
"C++ build tools required for this test are missing on PATH: {}; install them",
missing.join(", "),
);
}