use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::submodules::build::Step;
use super::Plugin;
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct PluginToml {
pub name: String,
pub version: String,
pub stage: Stage,
#[serde(skip)]
pub path: PathBuf,
}
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct Stage {
pub pre: Option<PluginStage>,
pub aapt: Option<PluginStage>,
pub compile: Option<PluginStage>,
pub dex: Option<PluginStage>,
pub bundle: Option<PluginStage>,
pub post: Option<PluginStage>,
}
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct PluginStage {
pub file: PathBuf,
pub priority: i32,
}
impl PluginToml {
pub fn get_steps(&self) -> Vec<Plugin> {
let mut steps = vec![];
macro_rules! map_plugin {
[$($i:ident = $j:expr),*] => {
$(
// check if $i is set, if set then create a sub plugin
if let Some(s) = &self.stage.$i {
let mut path = self.path.clone();
path.push(s.file.clone());
let mut plugin = Plugin::new(self.name.clone(), self.version.clone(), path, $j);
plugin.priority = s.priority;
steps.push(plugin);
}
)*
};
}
map_plugin![
pre = Step::PRE,
aapt = Step::AAPT,
compile = Step::COMPILE,
dex = Step::DEX,
bundle = Step::BUNDLE,
post = Step::POST
];
steps
}
}