2020-05-04 00:54:16 +00:00
|
|
|
use proc_macro::TokenStream;
|
2020-05-24 19:39:23 +00:00
|
|
|
use proc_macro_crate::crate_name;
|
2020-07-14 23:16:01 +00:00
|
|
|
use syn::{Attribute, Path};
|
2020-05-04 00:54:16 +00:00
|
|
|
|
2020-05-24 19:39:23 +00:00
|
|
|
#[derive(Debug)]
|
2020-05-04 00:54:16 +00:00
|
|
|
pub struct Modules {
|
|
|
|
pub bevy_render: String,
|
|
|
|
pub bevy_asset: String,
|
|
|
|
pub bevy_core: String,
|
|
|
|
pub bevy_app: String,
|
2020-10-18 20:48:15 +00:00
|
|
|
pub bevy_type_registry: String,
|
2020-05-04 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Modules {
|
|
|
|
pub fn meta() -> Modules {
|
|
|
|
Modules {
|
|
|
|
bevy_asset: "bevy::asset".to_string(),
|
|
|
|
bevy_render: "bevy::render".to_string(),
|
|
|
|
bevy_core: "bevy::core".to_string(),
|
|
|
|
bevy_app: "bevy::app".to_string(),
|
2020-10-18 20:48:15 +00:00
|
|
|
bevy_type_registry: "bevy::type_registry".to_string(),
|
2020-05-04 00:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn external() -> Modules {
|
|
|
|
Modules {
|
|
|
|
bevy_asset: "bevy_asset".to_string(),
|
|
|
|
bevy_render: "bevy_render".to_string(),
|
|
|
|
bevy_core: "bevy_core".to_string(),
|
|
|
|
bevy_app: "bevy_app".to_string(),
|
2020-10-18 20:48:15 +00:00
|
|
|
bevy_type_registry: "bevy_type_registry".to_string(),
|
2020-05-04 00:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 19:39:23 +00:00
|
|
|
fn use_meta() -> bool {
|
|
|
|
crate_name("bevy").is_ok()
|
2020-05-04 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 23:16:01 +00:00
|
|
|
const AS_CRATE_ATTRIBUTE_NAME: &str = "as_crate";
|
|
|
|
|
|
|
|
pub fn get_modules(attributes: &[Attribute]) -> Modules {
|
|
|
|
let mut modules = if use_meta() {
|
2020-05-24 19:39:23 +00:00
|
|
|
Modules::meta()
|
|
|
|
} else {
|
|
|
|
Modules::external()
|
2020-07-14 23:16:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for attribute in attributes.iter() {
|
2020-08-16 07:30:04 +00:00
|
|
|
if *attribute.path.get_ident().as_ref().unwrap() == AS_CRATE_ATTRIBUTE_NAME {
|
2020-07-14 23:16:01 +00:00
|
|
|
let value = attribute.tokens.to_string();
|
2020-08-16 07:30:04 +00:00
|
|
|
if value[1..value.len() - 1] == modules.bevy_render {
|
2020-07-17 00:23:50 +00:00
|
|
|
modules.bevy_render = "crate".to_string();
|
2020-07-14 23:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 19:39:23 +00:00
|
|
|
}
|
2020-07-14 23:16:01 +00:00
|
|
|
|
|
|
|
modules
|
2020-05-04 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_path(path_str: &str) -> Path {
|
|
|
|
syn::parse(path_str.parse::<TokenStream>().unwrap()).unwrap()
|
|
|
|
}
|