mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Add features for each script type
This commit is contained in:
21
.github/workflows/CI.yml
vendored
Normal file
21
.github/workflows/CI.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install toml
|
||||||
|
run: pip3 install toml
|
||||||
|
- name: Check
|
||||||
|
run: python check_features.py
|
||||||
@@ -13,5 +13,11 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
unicode-segmentation = "1.12"
|
unicode-segmentation = "1.12"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["bgi", "circus", "escude"]
|
||||||
|
bgi = []
|
||||||
|
circus = []
|
||||||
|
escude = []
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows-sys = { version = "0", features = ["Win32_Globalization", "Win32_System_Diagnostics_Debug"] }
|
windows-sys = { version = "0", features = ["Win32_Globalization", "Win32_System_Diagnostics_Debug"] }
|
||||||
|
|||||||
63
check_features.py
Normal file
63
check_features.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import toml
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# 检查cargo是否可用
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
["cargo", "--version"],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: 'cargo' not found. Install Rust and ensure it's in PATH.")
|
||||||
|
sys.exit(1)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error checking cargo: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# 读取Cargo.toml
|
||||||
|
try:
|
||||||
|
with open("Cargo.toml", "r") as f:
|
||||||
|
cargo_toml = toml.load(f)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: Cargo.toml not found in current directory.")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error parsing Cargo.toml: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
features = cargo_toml.get("features", {})
|
||||||
|
feature_names = list(features.keys())
|
||||||
|
|
||||||
|
if not feature_names:
|
||||||
|
print("No features defined in Cargo.toml.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
failed_features = []
|
||||||
|
|
||||||
|
print(f"Testing {len(feature_names)} features...")
|
||||||
|
for idx, feature in enumerate(feature_names, 1):
|
||||||
|
print(f"\nTesting feature {idx}/{len(feature_names)}: {feature}")
|
||||||
|
cmd = ["cargo", "check", "--no-default-features", "--features", feature, '--target-dir', 'target/features_check']
|
||||||
|
try:
|
||||||
|
subprocess.run(cmd, check=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
failed_features.append(feature)
|
||||||
|
print(f"❌ Feature '{feature}' failed to compile")
|
||||||
|
else:
|
||||||
|
print(f"✅ Feature '{feature}' compiled successfully")
|
||||||
|
|
||||||
|
if failed_features:
|
||||||
|
print("\nFailed features:")
|
||||||
|
for f in failed_features:
|
||||||
|
print(f" - {f}")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("\nAll features compiled successfully!")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -18,10 +18,16 @@ impl FixedFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "circus")]
|
||||||
fn is_circus(&self) -> bool {
|
fn is_circus(&self) -> bool {
|
||||||
matches!(self.typ, Some(ScriptType::Circus))
|
matches!(self.typ, Some(ScriptType::Circus))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "circus"))]
|
||||||
|
fn is_circus(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub fn format(&self, message: &str) -> String {
|
pub fn format(&self, message: &str) -> String {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
let vec: Vec<_> = UnicodeSegmentation::graphemes(message, true).collect();
|
let vec: Vec<_> = UnicodeSegmentation::graphemes(message, true).collect();
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
pub mod base;
|
pub mod base;
|
||||||
|
#[cfg(feature = "bgi")]
|
||||||
pub mod bgi;
|
pub mod bgi;
|
||||||
|
#[cfg(feature = "circus")]
|
||||||
pub mod circus;
|
pub mod circus;
|
||||||
|
#[cfg(feature = "escude")]
|
||||||
pub mod escude;
|
pub mod escude;
|
||||||
|
|
||||||
pub use base::{Script, ScriptBuilder};
|
pub use base::{Script, ScriptBuilder};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref BUILDER: Vec<Box<dyn ScriptBuilder + Sync + Send>> = vec![
|
pub static ref BUILDER: Vec<Box<dyn ScriptBuilder + Sync + Send>> = vec![
|
||||||
|
#[cfg(feature = "circus")]
|
||||||
Box::new(circus::script::CircusMesScriptBuilder::new()),
|
Box::new(circus::script::CircusMesScriptBuilder::new()),
|
||||||
|
#[cfg(feature = "bgi")]
|
||||||
Box::new(bgi::script::BGIScriptBuilder::new()),
|
Box::new(bgi::script::BGIScriptBuilder::new()),
|
||||||
|
#[cfg(feature = "escude")]
|
||||||
Box::new(escude::archive::EscudeBinArchiveBuilder::new()),
|
Box::new(escude::archive::EscudeBinArchiveBuilder::new()),
|
||||||
|
#[cfg(feature = "escude")]
|
||||||
Box::new(escude::script::EscudeBinScriptBuilder::new()),
|
Box::new(escude::script::EscudeBinScriptBuilder::new()),
|
||||||
];
|
];
|
||||||
pub static ref ALL_EXTS: Vec<String> =
|
pub static ref ALL_EXTS: Vec<String> =
|
||||||
|
|||||||
@@ -182,13 +182,17 @@ pub struct ExtraConfig {
|
|||||||
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
/// Script type
|
/// Script type
|
||||||
pub enum ScriptType {
|
pub enum ScriptType {
|
||||||
|
#[cfg(feature = "circus")]
|
||||||
/// Circus MES script
|
/// Circus MES script
|
||||||
Circus,
|
Circus,
|
||||||
|
#[cfg(feature = "bgi")]
|
||||||
#[value(alias("ethornell"))]
|
#[value(alias("ethornell"))]
|
||||||
/// Buriko General Interpreter/Ethornell Script
|
/// Buriko General Interpreter/Ethornell Script
|
||||||
BGI,
|
BGI,
|
||||||
|
#[cfg(feature = "escude")]
|
||||||
/// Escude bin archive
|
/// Escude bin archive
|
||||||
EscudeArc,
|
EscudeArc,
|
||||||
|
#[cfg(feature = "escude")]
|
||||||
/// Escude bin script
|
/// Escude bin script
|
||||||
Escude,
|
Escude,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user