2024-02-14 13:00:21 +08:00
|
|
|
mod codegen;
|
2022-09-19 21:38:20 +08:00
|
|
|
mod docgen;
|
|
|
|
mod helpers;
|
|
|
|
mod path;
|
|
|
|
mod querycheck;
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
use std::{env, error::Error};
|
|
|
|
|
|
|
|
type DynError = Box<dyn Error>;
|
|
|
|
|
2021-11-17 21:30:11 +08:00
|
|
|
pub mod tasks {
|
2024-02-14 13:00:21 +08:00
|
|
|
use crate::codegen::code_gen;
|
2022-09-19 21:38:20 +08:00
|
|
|
use crate::docgen::{lang_features, typable_commands, write};
|
|
|
|
use crate::docgen::{LANG_SUPPORT_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT};
|
|
|
|
use crate::querycheck::query_check;
|
2021-11-22 02:55:08 +08:00
|
|
|
use crate::DynError;
|
2021-11-17 21:30:11 +08:00
|
|
|
|
2024-07-06 04:11:02 +08:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
pub fn docgen() -> Result<(), DynError> {
|
|
|
|
write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?);
|
|
|
|
write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?);
|
|
|
|
Ok(())
|
2021-11-17 21:30:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-19 21:38:20 +08:00
|
|
|
pub fn querycheck() -> Result<(), DynError> {
|
|
|
|
query_check()
|
2022-08-26 06:24:09 +08:00
|
|
|
}
|
|
|
|
|
2024-02-14 13:00:21 +08:00
|
|
|
pub fn codegen() {
|
|
|
|
code_gen()
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
pub fn install_steel() {
|
2024-07-06 04:11:02 +08:00
|
|
|
fn workspace_dir() -> PathBuf {
|
|
|
|
let output = std::process::Command::new(env!("CARGO"))
|
|
|
|
.arg("locate-project")
|
|
|
|
.arg("--workspace")
|
|
|
|
.arg("--message-format=plain")
|
|
|
|
.output()
|
|
|
|
.unwrap()
|
|
|
|
.stdout;
|
|
|
|
let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
|
|
|
|
cargo_path.parent().unwrap().to_path_buf()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the steel submodule
|
|
|
|
std::process::Command::new("git")
|
|
|
|
.args(["submodule", "init"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
.args(["submodule", "foreach", "git", "pull", "origin", "master"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut workspace_dir = workspace_dir();
|
|
|
|
|
|
|
|
workspace_dir.push("steel");
|
|
|
|
|
|
|
|
std::process::Command::new("cargo")
|
|
|
|
.args(["xtask", "install"])
|
|
|
|
.current_dir(workspace_dir)
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("=> Finished installing steel");
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
code_gen();
|
2024-07-06 04:11:02 +08:00
|
|
|
|
|
|
|
let helix_scm_path = helix_term::commands::helix_module_file();
|
|
|
|
let steel_init_path = helix_term::commands::steel_init_file();
|
|
|
|
|
|
|
|
if !helix_scm_path.exists() {
|
|
|
|
std::fs::File::create(helix_scm_path).expect("Unable to create new helix.scm file!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !steel_init_path.exists() {
|
|
|
|
std::fs::File::create(steel_init_path).expect("Unable to create new init.scm file!");
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:17:41 +08:00
|
|
|
std::process::Command::new("cargo")
|
|
|
|
.args(["install", "--path", "helix-term", "--locked", "--force"])
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2021-11-17 21:30:11 +08:00
|
|
|
pub fn print_help() {
|
|
|
|
println!(
|
|
|
|
"
|
2021-11-22 02:55:08 +08:00
|
|
|
Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
|
2021-11-17 21:30:11 +08:00
|
|
|
|
|
|
|
Tasks:
|
2021-11-22 02:55:08 +08:00
|
|
|
docgen: Generate files to be included in the mdbook output.
|
2022-08-26 06:24:09 +08:00
|
|
|
query-check: Check that tree-sitter queries are valid.
|
2021-11-17 21:30:11 +08:00
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-22 02:55:08 +08:00
|
|
|
fn main() -> Result<(), DynError> {
|
2021-11-17 21:30:11 +08:00
|
|
|
let task = env::args().nth(1);
|
|
|
|
match task {
|
|
|
|
None => tasks::print_help(),
|
|
|
|
Some(t) => match t.as_str() {
|
2021-11-22 02:55:08 +08:00
|
|
|
"docgen" => tasks::docgen()?,
|
2022-09-19 21:38:20 +08:00
|
|
|
"query-check" => tasks::querycheck()?,
|
2024-02-14 13:00:21 +08:00
|
|
|
"code-gen" => tasks::codegen(),
|
2024-04-06 06:17:41 +08:00
|
|
|
"steel" => tasks::install_steel(),
|
2021-11-22 02:55:08 +08:00
|
|
|
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
|
2021-11-17 21:30:11 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
Ok(())
|
|
|
|
}
|