Skip to content

Commit

Permalink
Remove syn from baked_exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 5, 2023
1 parent c23d108 commit be89e2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions provider/datagen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ icu_provider_blob = { workspace = true, features = ["export"], optional = true }
icu_provider_fs = { workspace = true, features = ["export"], optional = true }
crlify = { workspace = true, optional = true }
databake = { workspace = true, optional = true}
syn = {version = "2", features = ["parsing"], optional = true }
proc-macro2 = {version = "1", optional = true }

# Other external dependencies
displaydoc = { version = "0.2.3", default-features = false }
Expand Down Expand Up @@ -103,7 +103,7 @@ simple_logger = { version = "4.1.0", default-features = false }

[features]
default = ["bin", "use_wasm", "networking", "legacy_api", "rayon", "fs_exporter", "blob_exporter", "baked_exporter"]
baked_exporter = ["dep:crlify", "dep:databake", "dep:syn"]
baked_exporter = ["dep:crlify", "dep:databake", "dep:proc-macro2"]
blob_exporter = ["dep:icu_provider_blob"]
fs_exporter = ["dep:icu_provider_fs"]
legacy_api = ["fs_exporter", "blob_exporter", "baked_exporter"]
Expand Down
27 changes: 13 additions & 14 deletions provider/datagen/src/baked_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ impl BakedExporter {
&self,
body: TokenStream,
key: DataKey,
marker: syn::Path,
marker: TokenStream,
) -> Result<(), DataError> {
let marker_string = marker.to_string();
let doc = format!(
" Implement `DataProvider<{}>` on the given struct using the data",
marker.segments.iter().next_back().unwrap().ident
marker.into_iter().last().unwrap()
);

let ident = Self::ident(key);
Expand Down Expand Up @@ -308,7 +309,7 @@ impl BakedExporter {
self.impl_data
.lock()
.expect("poison")
.insert(key, quote!(#marker).to_string());
.insert(key, marker_string);
Ok(())
}

Expand Down Expand Up @@ -346,9 +347,7 @@ impl DataExporter for BakedExporter {
key: DataKey,
payload: &DataPayload<ExportMarker>,
) -> Result<(), DataError> {
let marker =
syn::parse2::<syn::Path>(crate::registry::key_to_marker_bake(key, &self.dependencies))
.unwrap();
let marker = crate::registry::key_to_marker_bake(key, &self.dependencies);

let singleton_ident = format!("SINGLETON_{}", Self::ident(key).to_ascii_uppercase())
.parse::<TokenStream>()
Expand Down Expand Up @@ -410,12 +409,12 @@ impl BakedExporter {
key: DataKey,
fallback_mode: Option<BuiltInFallbackMode>,
) -> Result<(), DataError> {
let marker =
syn::parse2::<syn::Path>(crate::registry::key_to_marker_bake(key, &self.dependencies))
.unwrap();
let marker = crate::registry::key_to_marker_bake(key, &self.dependencies);

let (struct_type, into_data_payload) = if marker.segments.iter().next_back().unwrap().ident
== "DateSkeletonPatternsV1Marker"
let (struct_type, into_data_payload) = if marker
.to_string()
.trim()
.ends_with("DateSkeletonPatternsV1Marker")
{
(
quote! {
Expand Down Expand Up @@ -459,7 +458,7 @@ impl BakedExporter {

for (bake, locales) in values {
let first_locale = locales.iter().next().unwrap();
let anchor = syn::parse_str::<syn::Ident>(
let anchor = proc_macro2::Ident::new(
&first_locale
.chars()
.flat_map(|ch| {
Expand All @@ -473,8 +472,8 @@ impl BakedExporter {
}
})
.collect::<String>(),
)
.unwrap();
proc_macro2::Span::call_site(),
);
let bake = bake.parse::<TokenStream>().unwrap();
statics.push(quote! { static #anchor: #struct_type = #bake; });
map.extend(locales.into_iter().map(|l| (l, anchor.clone())));
Expand Down

0 comments on commit be89e2e

Please sign in to comment.