idea: serialize package into rust code
Pkg configure/build/install generate a proc-macro2 TokenStream that we will serialize into file and recompile Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
c83cf30a24
commit
a7ce242f09
|
@ -15,6 +15,8 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"bok-macro",
|
"bok-macro",
|
||||||
"paste",
|
"paste",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -271,7 +271,20 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
||||||
let non_opt_types2 = non_opt_types.clone();
|
let non_opt_types2 = non_opt_types.clone();
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
impl ::bok::Pkg for #name {}
|
impl ::bok::Pkg for #name {
|
||||||
|
fn base(&self) -> Option<&impl ::bok::Pkg> {
|
||||||
|
Some(&self.base)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ::core::fmt::Display for #name {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>)
|
||||||
|
->::core::fmt::Result
|
||||||
|
{
|
||||||
|
use ::bok::Pkg;
|
||||||
|
let pkg = self.package();
|
||||||
|
pkg.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl #name {
|
impl #name {
|
||||||
pub fn builder() -> #name_builder {
|
pub fn builder() -> #name_builder {
|
||||||
#name_builder {
|
#name_builder {
|
||||||
|
|
|
@ -16,6 +16,8 @@ publish = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
bitflags = "2.4"
|
bitflags = "2.4"
|
||||||
|
proc-macro2 = "1.0"
|
||||||
|
quote = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bok-macro = { path="../bok-macro" }
|
bok-macro = { path="../bok-macro" }
|
||||||
|
|
|
@ -82,42 +82,63 @@ pub struct RepositoryEmpty {}
|
||||||
impl Repository for RepositoryEmpty {}
|
impl Repository for RepositoryEmpty {}
|
||||||
|
|
||||||
/// Implement common package operations
|
/// Implement common package operations
|
||||||
pub trait Pkg: ::std::default::Default {
|
pub trait Pkg: ::std::default::Default + ::core::fmt::Display {
|
||||||
/*
|
fn base(&self) -> Option<&impl Pkg>;
|
||||||
fn prepare_pre();
|
fn prepare(&self) -> ::proc_macro2::TokenStream {
|
||||||
fn prepare();
|
self.base().unwrap().prepare()
|
||||||
fn prepare_post();
|
|
||||||
fn configure_pre();
|
|
||||||
fn configure();
|
|
||||||
fn configure_post();
|
|
||||||
fn build_pre();
|
|
||||||
fn build();
|
|
||||||
fn build_post();
|
|
||||||
fn check_pre();
|
|
||||||
fn check();
|
|
||||||
fn check_post();
|
|
||||||
fn install_pre();
|
|
||||||
fn install();
|
|
||||||
fn install_post();
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
fn build_base(&mut self) {
|
|
||||||
Self::base::default()
|
|
||||||
}
|
}
|
||||||
*/
|
fn configure(&self) -> ::proc_macro2::TokenStream {
|
||||||
/*
|
self.base().unwrap().configure()
|
||||||
fn as_any(&self) -> &dyn Any
|
}
|
||||||
where
|
fn build(&self) -> ::proc_macro2::TokenStream {
|
||||||
Self: Sized,
|
self.base().unwrap().build()
|
||||||
{
|
}
|
||||||
self
|
fn check(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
self.base().unwrap().check()
|
||||||
|
}
|
||||||
|
fn install(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
self.base().unwrap().install()
|
||||||
|
}
|
||||||
|
fn package(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
let mut all = self.prepare();
|
||||||
|
all.extend(self.configure());
|
||||||
|
all.extend(self.build());
|
||||||
|
all.extend(self.check());
|
||||||
|
all.extend(self.install());
|
||||||
|
all
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PkgEmpty {}
|
pub struct PkgEmpty {}
|
||||||
|
|
||||||
|
impl ::core::fmt::Display for PkgEmpty {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pkg for PkgEmpty {
|
||||||
|
fn base(&self) -> Option<&impl Pkg> {
|
||||||
|
None::<Self>.as_ref()
|
||||||
|
}
|
||||||
|
fn prepare(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
::quote::quote! {}
|
||||||
|
}
|
||||||
|
fn configure(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
::quote::quote! {}
|
||||||
|
}
|
||||||
|
fn build(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
::quote::quote! {}
|
||||||
|
}
|
||||||
|
fn check(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
::quote::quote! {}
|
||||||
|
}
|
||||||
|
fn install(&self) -> ::proc_macro2::TokenStream {
|
||||||
|
::quote::quote! {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
::bitflags::bitflags! {
|
::bitflags::bitflags! {
|
||||||
/// In each package, what we can build and how
|
/// In each package, what we can build and how
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
|
Loading…
Reference in New Issue