Skip to content

compatibility check caching #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added .tkcache
Empty file.
50 changes: 50 additions & 0 deletions src/compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::process::Command;
use std::{fs::File, path::Path};

pub fn check_compatibility(linker: String) {
let result = check_compatibility_impl(linker);
if result.is_err() {
println!("Error: {}", result.unwrap_err());
// maybe exit here?
}
}

fn check_compatibility_impl(linker: String) -> std::io::Result<()> {
if !Path::new(".tkcache").exists() {
initial_compat_check(linker);
let _ = File::create(".tkcache")?;
}
Ok(())
}

fn initial_compat_check(linker: String) {
if cfg!(windows) {
if Command::new("bash").arg("--version").output().is_err() {
println!("Error: WSL installation not found. Please install WSL and try again.");
std::process::exit(1)
}
}

if get_os_command().arg("-c").arg("nasm").output().is_err() {
println!("Error: NASM installation not found.");
std::process::exit(1)
}

if get_os_command()
.arg("-c")
.arg(format!("{linker}"))
.output()
.is_err()
{
println!("Error: {linker} installation not found.");
std::process::exit(1)
}
}

fn get_os_command() -> Command {
return if cfg!(windows) {
Command::new("bash")
} else {
Command::new("sh")
};
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod checker;
pub mod compatibility;
pub mod compiler;
pub mod graph;
pub mod lexer;
Expand Down
12 changes: 3 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use path_slash::PathBufExt;
use std::{path::PathBuf, process::Command};
use std::path::PathBuf;

use tack::compatibility::check_compatibility;
use tack::run::{invoke_command, run};

fn print_help_and_exit() -> ! {
Expand All @@ -20,15 +21,8 @@ Options:
std::process::exit(1);
}

fn check_compatibility() {
if cfg!(windows) && Command::new("bash").arg("--version").output().is_err() {
println!("Error: WSL installation not found. Please install WSL and try again.");
std::process::exit(1)
}
}

fn main() {
check_compatibility();
check_compatibility("ld".to_string());

let input = match std::env::args().nth(1) {
Some(value) => {
Expand Down