aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/builds
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-23 00:38:36 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-23 00:38:36 +0800
commit39721a88611f47a8e02a4daeafaa34d1a2c44b34 (patch)
treed4f5191556413e81300390a8dc0d54e0a0736e75 /mingling_core/src/builds
parente6c2545f89d2af8bac4e772d44655b97789ae60f (diff)
feat(core): rename `builds` feature to `build`
Replace the `builds` feature with `build` across the crate, keeping a backward-compatible alias for the old name. Update all internal visibility from `#[doc(hidden)] pub mod` to `pub(crate) mod` and reorganize the `__private` module into a dedicated `private.rs`.
Diffstat (limited to 'mingling_core/src/builds')
-rw-r--r--mingling_core/src/builds/comp.rs168
-rw-r--r--mingling_core/src/builds/pathf.rs43
2 files changed, 0 insertions, 211 deletions
diff --git a/mingling_core/src/builds/comp.rs b/mingling_core/src/builds/comp.rs
deleted file mode 100644
index 2abb1e1..0000000
--- a/mingling_core/src/builds/comp.rs
+++ /dev/null
@@ -1,168 +0,0 @@
-use std::path::PathBuf;
-
-use just_template::tmpl;
-
-use crate::ShellFlag;
-
-const TMPL_COMP_BASH: &str = include_str!("../../tmpls/comps/bash.sh");
-const TMPL_COMP_ZSH: &str = include_str!("../../tmpls/comps/zsh.zsh");
-const TMPL_COMP_FISH: &str = include_str!("../../tmpls/comps/fish.fish");
-const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1");
-
-/// Generate shell completion scripts for a given binary name.
-/// On Windows, generates `PowerShell` completion.
-/// On Linux, generates Zsh, Bash, and Fish completions.
-/// Scripts are written to the `OUT_DIR` (or `target/` if `OUT_DIR` is not set).
-///
-/// # Example
-/// ```rust,ignore
-/// # use mingling_core::comp::ShellFlag;
-/// # use mingling_core::build::build_comp_scripts;
-///
-/// // Generate completion scripts for "myapp"
-/// build_comp_scripts("myapp").unwrap();
-///
-/// // Generate completion scripts for current package
-/// build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap();
-/// ```
-pub fn build_comp_scripts(name: &str) -> Result<(), std::io::Error> {
- #[cfg(target_os = "windows")]
- {
- build_comp_script(&ShellFlag::Powershell, name)?;
- Ok(())
- }
-
- #[cfg(target_os = "linux")]
- {
- build_comp_script(&ShellFlag::Zsh, name)?;
- build_comp_script(&ShellFlag::Bash, name)?;
- build_comp_script(&ShellFlag::Fish, name)?;
- Ok(())
- }
-
- #[cfg(target_os = "macos")]
- {
- build_comp_script(&ShellFlag::Zsh, name)?;
- build_comp_script(&ShellFlag::Bash, name)?;
- build_comp_script(&ShellFlag::Fish, name)?;
- Ok(())
- }
-}
-
-/// Generate a shell completion script for a specific shell.
-///
-/// This function takes a shell flag and a binary name, selects the appropriate
-/// template, substitutes the binary name into the template, and writes the
-/// resulting completion script to the target directory (typically `target/`).
-///
-/// # Example
-/// ```rust,ignore
-/// # use mingling_core::comp::ShellFlag;
-/// # use mingling_core::build::build_comp_script;
-/// build_comp_script(&ShellFlag::Bash, "myapp").unwrap();
-/// ```
-pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> {
- let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
- let target_dir = out_dir.join("../../../").clone();
- build_comp_script_to(shell_flag, bin_name, &target_dir.to_string_lossy())
-}
-
-/// Generate a shell completion script to a specified directory.
-///
-/// This function takes a shell flag, a binary name, and a target directory path,
-/// selects the appropriate template, substitutes the binary name into the template,
-/// and writes the resulting completion script to the specified directory.
-///
-/// # Example
-/// ```rust,ignore
-/// # use mingling_core::comp::ShellFlag;
-/// # use mingling_core::build::build_comp_script_to;
-/// build_comp_script_to(&ShellFlag::Bash, "myapp", "target/completions").unwrap();
-/// ```
-pub fn build_comp_script_to(
- shell_flag: &ShellFlag,
- bin_name: &str,
- target_dir: &str,
-) -> Result<(), std::io::Error> {
- let (tmpl_str, ext) = get_tmpl(shell_flag);
- let mut tmpl = just_template::Template::from(tmpl_str);
- tmpl!(bin_name = bin_name);
- let target_path = std::path::PathBuf::from(target_dir);
- std::fs::create_dir_all(&target_path)?;
- let output_path = target_path.join(format!("{bin_name}_comp{ext}"));
- std::fs::write(&output_path, tmpl.to_string())
-}
-
-/// Generate a shell completion script and write it to a specified file path.
-///
-/// This function takes a shell flag, a binary name, and an output file path,
-/// selects the appropriate template, substitutes the binary name into the template,
-/// and writes the resulting completion script directly to the specified file path.
-///
-/// # Example
-/// ```rust,ignore
-/// # use mingling_core::comp::ShellFlag;
-/// # use mingling_core::build::build_comp_script_to_file;
-/// build_comp_script_to_file(&ShellFlag::Bash, "myapp", "target/completions/myapp_comp.sh").unwrap();
-/// ```
-pub fn build_comp_script_to_file(
- shell_flag: &ShellFlag,
- bin_name: &str,
- output_path: impl Into<PathBuf>,
-) -> Result<(), std::io::Error> {
- let (tmpl_str, _ext) = get_tmpl(shell_flag);
- let mut tmpl = just_template::Template::from(tmpl_str);
- tmpl!(bin_name = bin_name);
- std::fs::write(output_path.into(), tmpl.to_string())
-}
-
-fn get_tmpl(shell_flag: &ShellFlag) -> (&'static str, &'static str) {
- match shell_flag {
- ShellFlag::Bash => (TMPL_COMP_BASH, ".sh"),
- ShellFlag::Zsh => (TMPL_COMP_ZSH, ".zsh"),
- ShellFlag::Fish => (TMPL_COMP_FISH, ".fish"),
- ShellFlag::Powershell => (TMPL_COMP_PWSH, ".ps1"),
- ShellFlag::Other(_) => (TMPL_COMP_BASH, ".sh"),
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::ShellFlag;
-
- #[test]
- fn get_tmpl_bash() {
- let (tmpl, ext) = get_tmpl(&ShellFlag::Bash);
- assert_eq!(ext, ".sh");
- assert!(!tmpl.is_empty(), "bash template should not be empty");
- }
-
- #[test]
- fn get_tmpl_zsh() {
- let (tmpl, ext) = get_tmpl(&ShellFlag::Zsh);
- assert_eq!(ext, ".zsh");
- assert!(!tmpl.is_empty(), "zsh template should not be empty");
- }
-
- #[test]
- fn get_tmpl_fish() {
- let (tmpl, ext) = get_tmpl(&ShellFlag::Fish);
- assert_eq!(ext, ".fish");
- assert!(!tmpl.is_empty(), "fish template should not be empty");
- }
-
- #[test]
- fn get_tmpl_powershell() {
- let (tmpl, ext) = get_tmpl(&ShellFlag::Powershell);
- assert_eq!(ext, ".ps1");
- assert!(!tmpl.is_empty(), "powershell template should not be empty");
- }
-
- #[test]
- fn get_tmpl_other() {
- let (tmpl, ext) = get_tmpl(&ShellFlag::Other("custom".to_string()));
- assert_eq!(ext, ".sh");
- assert!(!tmpl.is_empty(), "fallback template should not be empty");
- }
-}
diff --git a/mingling_core/src/builds/pathf.rs b/mingling_core/src/builds/pathf.rs
deleted file mode 100644
index d8d4698..0000000
--- a/mingling_core/src/builds/pathf.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-pub use mingling_pathf::config::*;
-pub use mingling_pathf::module_pathf::*;
-pub use mingling_pathf::pattern_analyzer::*;
-pub use mingling_pathf::patterns::*;
-
-use std::path::Path;
-
-/// Wraps `analyze_and_build_type_mapping_for` with config derived from
-/// the crate's feature flags (e.g., `dispatch_tree`).
-pub fn analyze_and_build_type_mapping_for(
- crate_dir: &Path,
- output_dir: &Path,
-) -> Result<(), crate::error::MinglingPathfinderError> {
- let config = mingling_pathf::config::PathfinderConfig {
- use_dispatch_tree: cfg!(feature = "dispatch_tree"),
- };
- mingling_pathf::analyze_and_build_type_mapping_for(crate_dir, output_dir, &config)
-}
-
-/// Wraps `analyze_and_build_type_mapping` (build.rs convenience) with config.
-pub fn analyze_and_build_type_mapping() -> Result<(), crate::error::MinglingPathfinderError> {
- let config = mingling_pathf::config::PathfinderConfig {
- use_dispatch_tree: cfg!(feature = "dispatch_tree"),
- };
- let crate_dir =
- std::env::current_dir().map_err(crate::error::MinglingPathfinderError::IoError)?;
- let crate_name = std::env::var("CARGO_PKG_NAME").map_err(|_| {
- crate::error::MinglingPathfinderError::IoError(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "CARGO_PKG_NAME not set",
- ))
- })?;
- let out_dir = std::env::var("OUT_DIR").map_err(|_| {
- crate::error::MinglingPathfinderError::IoError(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "OUT_DIR not set",
- ))
- })?;
- let output_dir = Path::new(&out_dir).join(&crate_name);
- mingling_pathf::analyze_and_build_type_mapping_for(&crate_dir, &output_dir, &config)?;
- println!("cargo:rerun-if-changed=src/");
- Ok(())
-}