Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support automatic scanning of third party crates (part 1) #2007

Merged
merged 157 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
9f2a257
feat: field
fzyzcjy Jun 1, 2024
5e74f0a
chore: simp
fzyzcjy Jun 1, 2024
fb488ff
fix: err
fzyzcjy Jun 1, 2024
835c312
feat: more
fzyzcjy Jun 1, 2024
1bd9ea2
fix: err
fzyzcjy Jun 1, 2024
75d4ad5
feat: more
fzyzcjy Jun 1, 2024
5112feb
chore: rename
fzyzcjy Jun 1, 2024
a053ce6
feat: more
fzyzcjy Jun 1, 2024
6089ae8
fix: err
fzyzcjy Jun 1, 2024
42b35ab
chore: lint
fzyzcjy Jun 1, 2024
63bf504
refcactor: mv
fzyzcjy Jun 1, 2024
832244d
refactor: more
fzyzcjy Jun 1, 2024
4b72571
feat: more
fzyzcjy Jun 1, 2024
aa3dfdb
feat: more
fzyzcjy Jun 1, 2024
c81a1fa
fix: err
fzyzcjy Jun 1, 2024
4a4ac40
feat: more
fzyzcjy Jun 1, 2024
bfae07a
chore: more
fzyzcjy Jun 1, 2024
266cdeb
feat: more
fzyzcjy Jun 1, 2024
3a0c0d0
fix: err
fzyzcjy Jun 1, 2024
8afd72c
fix: err
fzyzcjy Jun 1, 2024
99fd3c7
feat: more
fzyzcjy Jun 1, 2024
e6e33a4
feat: more
fzyzcjy Jun 1, 2024
d50108a
chore: cp back
fzyzcjy Jun 1, 2024
2c60b5d
feat: more
fzyzcjy Jun 1, 2024
464da31
feat: simp
fzyzcjy Jun 1, 2024
dbf0d00
feat: more
fzyzcjy Jun 1, 2024
48cc317
chore: arg
fzyzcjy Jun 1, 2024
ba72c80
feat: arg
fzyzcjy Jun 1, 2024
b0b1920
feat: more
fzyzcjy Jun 1, 2024
483570c
feat: more
fzyzcjy Jun 1, 2024
c25c486
fix: err
fzyzcjy Jun 1, 2024
5885a3b
chore: lint
fzyzcjy Jun 1, 2024
2fb4a95
feat: more
fzyzcjy Jun 1, 2024
48a7ec3
chore: simp
fzyzcjy Jun 1, 2024
1483f3c
feat: more
fzyzcjy Jun 1, 2024
471b996
chore: name
fzyzcjy Jun 1, 2024
7475b5e
chore: more rename
fzyzcjy Jun 1, 2024
1c99001
feat: more
fzyzcjy Jun 1, 2024
9e29b77
feat: more
fzyzcjy Jun 1, 2024
71c8be8
fix: err
fzyzcjy Jun 1, 2024
5a8a14d
feat: more
fzyzcjy Jun 1, 2024
68defe2
chore: lint
fzyzcjy Jun 1, 2024
29f8a77
chore: more
fzyzcjy Jun 1, 2024
82cf9c2
Merge branch 'master' into feat/12109
fzyzcjy Jun 1, 2024
8c7441c
fix: err
fzyzcjy Jun 1, 2024
0aaf846
fix: compile
fzyzcjy Jun 1, 2024
7678a7d
chore: empty
fzyzcjy Jun 1, 2024
c4ee906
refactor: mv
fzyzcjy Jun 1, 2024
1e44fc6
feat: more
fzyzcjy Jun 1, 2024
adacea6
feat: ty
fzyzcjy Jun 1, 2024
934232d
fix: err
fzyzcjy Jun 1, 2024
df7c316
feat: more
fzyzcjy Jun 1, 2024
7dcbe03
feaT: more
fzyzcjy Jun 1, 2024
1815812
feat: more
fzyzcjy Jun 1, 2024
64f0118
feat: replace
fzyzcjy Jun 1, 2024
ac8b20c
chore: more
fzyzcjy Jun 1, 2024
e63bbd9
feat: more
fzyzcjy Jun 1, 2024
37a45d0
feat: more
fzyzcjy Jun 1, 2024
3faeaec
feat: mv
fzyzcjy Jun 1, 2024
7321b67
feat: more
fzyzcjy Jun 1, 2024
add99fe
feat: more
fzyzcjy Jun 1, 2024
be7ab1d
chore: rename
fzyzcjy Jun 1, 2024
e15d359
feat: more
fzyzcjy Jun 1, 2024
529ac84
feat: more
fzyzcjy Jun 1, 2024
52c941b
feat: more
fzyzcjy Jun 1, 2024
445e80c
fix: err
fzyzcjy Jun 1, 2024
83370df
chore: fmt
fzyzcjy Jun 1, 2024
6fff883
feat: more
fzyzcjy Jun 1, 2024
c72dd6d
feat: more
fzyzcjy Jun 1, 2024
4a2eaae
fix: err
fzyzcjy Jun 1, 2024
20708e4
feat: more
fzyzcjy Jun 1, 2024
206251a
chore: rename
fzyzcjy Jun 1, 2024
673f32e
fix: err
fzyzcjy Jun 1, 2024
23777b8
feat: more
fzyzcjy Jun 1, 2024
67bf9c9
feat: more
fzyzcjy Jun 1, 2024
b9f7911
feat: more
fzyzcjy Jun 1, 2024
6c27be5
feat: more
fzyzcjy Jun 1, 2024
77b9dc0
feat: more
fzyzcjy Jun 1, 2024
3c2eec6
refactor: rename
fzyzcjy Jun 1, 2024
0ed19bb
feat: more
fzyzcjy Jun 1, 2024
98d1897
fix: err
fzyzcjy Jun 1, 2024
313372c
feat: more
fzyzcjy Jun 1, 2024
f5bd141
feat: more
fzyzcjy Jun 1, 2024
08eea97
fix: err
fzyzcjy Jun 1, 2024
dc309d6
feat: more
fzyzcjy Jun 1, 2024
ed080da
chore: codegen
fzyzcjy Jun 1, 2024
c31fd40
feat: more
fzyzcjy Jun 1, 2024
d45777a
chore: codegen
fzyzcjy Jun 1, 2024
dd627da
Merge branch 'feat/12112' into feat/12109
fzyzcjy Jun 2, 2024
fd613f3
feat: skipper
fzyzcjy Jun 2, 2024
4bc9e96
fix: err
fzyzcjy Jun 2, 2024
7d9efec
chore: rm
fzyzcjy Jun 2, 2024
43c5eb2
feat: more
fzyzcjy Jun 2, 2024
0a3a5f3
fix: err
fzyzcjy Jun 2, 2024
7411848
chore: rm unused
fzyzcjy Jun 2, 2024
04c8c58
fix: err
fzyzcjy Jun 2, 2024
e022f69
feat: more
fzyzcjy Jun 2, 2024
d2a8f22
feat: more
fzyzcjy Jun 2, 2024
7d724eb
chore: rm
fzyzcjy Jun 2, 2024
627e44e
chore: rename
fzyzcjy Jun 2, 2024
0532126
feat: more
fzyzcjy Jun 2, 2024
789e01b
feat: more
fzyzcjy Jun 2, 2024
dfc677b
feat: more
fzyzcjy Jun 2, 2024
28d4e73
feat: more
fzyzcjy Jun 2, 2024
ef6bdf1
feat: more
fzyzcjy Jun 2, 2024
3822cd5
fix: err
fzyzcjy Jun 2, 2024
22b68da
chore: lint
fzyzcjy Jun 2, 2024
3d68f39
chore: codegen
fzyzcjy Jun 2, 2024
78efbe9
feat: hint
fzyzcjy Jun 2, 2024
0c6bb18
feat: demo
fzyzcjy Jun 2, 2024
f24a916
feat: config
fzyzcjy Jun 2, 2024
e8fe417
chore: more
fzyzcjy Jun 2, 2024
f673e9f
feat: ty
fzyzcjy Jun 2, 2024
229ad06
feat: parse config
fzyzcjy Jun 2, 2024
434ed77
feat: more
fzyzcjy Jun 2, 2024
1593725
feat: more
fzyzcjy Jun 2, 2024
fc57394
feat: more
fzyzcjy Jun 2, 2024
7e50edd
feat: more
fzyzcjy Jun 2, 2024
f9782e5
feat: more
fzyzcjy Jun 2, 2024
c975aa3
fix: err
fzyzcjy Jun 2, 2024
9c8dac1
fix: more
fzyzcjy Jun 2, 2024
e97832e
fix: err
fzyzcjy Jun 2, 2024
84fa06f
feat: more
fzyzcjy Jun 2, 2024
441cd41
chore: mv
fzyzcjy Jun 2, 2024
2bc874d
feat: more
fzyzcjy Jun 2, 2024
bb6b833
fix: err
fzyzcjy Jun 2, 2024
a1488d8
refactor: mv
fzyzcjy Jun 2, 2024
dde8153
fix: err
fzyzcjy Jun 2, 2024
45b5b4c
fix: err
fzyzcjy Jun 2, 2024
be0348a
chore: codegen
fzyzcjy Jun 2, 2024
3ab5db4
chore: codegen
fzyzcjy Jun 2, 2024
2f395a7
chore: fmt
fzyzcjy Jun 2, 2024
f654b07
chore: goldens
fzyzcjy Jun 2, 2024
7b586ad
fix: err
fzyzcjy Jun 2, 2024
e50d79a
chore: more
fzyzcjy Jun 2, 2024
2b5f3d9
chore: codegen
fzyzcjy Jun 2, 2024
275f8c5
chore: more
fzyzcjy Jun 2, 2024
f26868d
chore: codegen
fzyzcjy Jun 2, 2024
c154c62
chore: fmt
fzyzcjy Jun 2, 2024
ffd1a22
chore: more
fzyzcjy Jun 2, 2024
6c7d5ca
chore: codegen
fzyzcjy Jun 2, 2024
5e36c54
chore: more
fzyzcjy Jun 2, 2024
0c0e219
chore: codegen
fzyzcjy Jun 2, 2024
f09ca9e
feat: more
fzyzcjy Jun 2, 2024
9bc10ea
chore: rm
fzyzcjy Jun 2, 2024
1ec080a
feat: more
fzyzcjy Jun 2, 2024
4c2015b
chore: lint
fzyzcjy Jun 2, 2024
303553f
feat: rm
fzyzcjy Jun 2, 2024
3205b2b
feat: sort
fzyzcjy Jun 2, 2024
0e6fb1c
Revert "Merge branch 'feat/12112' into feat/12109"
fzyzcjy Jun 2, 2024
395e75e
chore: fmt
fzyzcjy Jun 2, 2024
2e0d693
chore: codegen
fzyzcjy Jun 2, 2024
6bf1700
chore: doc
fzyzcjy Jun 2, 2024
32ea25c
fix: windows
fzyzcjy Jun 2, 2024
c0d2813
chore: goldens
fzyzcjy Jun 2, 2024
3ad5fe2
Merge branch 'feat/12113' into feat/12109
fzyzcjy Jun 2, 2024
b7b139d
chore: goldens
fzyzcjy Jun 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frb_codegen/src/binary/commands_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn compute_codegen_config_from_naive_command_args(
full_dep: Some(args.full_dep),
local: Some(args.local),
default_external_library_loader_web_prefix: args.default_external_library_loader_web_prefix,
dart_type_rename: None, // complex type, not supported on command line yet
dump: args.dump,
dump_all: Some(args.dump_all),
})
Expand Down
2 changes: 2 additions & 0 deletions frb_codegen/src/library/codegen/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::codegen::dumper::internal_config::ConfigDumpContent;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Configuration for code generation
/// Refer to `GenerateCommandArgs` for documentations
Expand Down Expand Up @@ -29,6 +30,7 @@ pub struct Config {
pub full_dep: Option<bool>,
pub local: Option<bool>,
pub default_external_library_loader_web_prefix: Option<String>,
pub dart_type_rename: Option<HashMap<String, String>>,
pub dump: Option<Vec<ConfigDumpContent>>,
pub dump_all: Option<bool>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use crate::codegen::Config;
use crate::library::commands::cargo_metadata::execute_cargo_metadata;
use crate::utils::dart_repository::get_dart_package_name;
use crate::utils::path_utils::path_to_string;
use crate::utils::syn_utils::canonicalize_rust_type;
use anyhow::Context;
use itertools::Itertools;
use pathdiff::diff_paths;
use std::collections::HashMap;
use std::path::{Path, PathBuf};

pub(super) struct Args<'a> {
Expand Down Expand Up @@ -61,8 +63,10 @@ pub(super) fn parse(args: Args) -> anyhow::Result<GeneratorInternalConfig> {
dart_enums_style,
dart3,
dart_decl_base_output_path: dart_output_path_pack.dart_decl_base_output_path.clone(),
dart_impl_output_path: dart_output_path_pack.dart_impl_output_path.clone(),
dart_entrypoint_class_name: dart_output_class_name_pack.entrypoint_class_name.clone(),
dart_preamble: config.dart_preamble.clone().unwrap_or_default(),
dart_type_rename: compute_dart_type_rename(config)?,
},
wire: GeneratorWireInternalConfig {
dart: GeneratorWireDartInternalConfig {
Expand Down Expand Up @@ -168,3 +172,31 @@ fn compute_default_external_library_relative_directory(
let diff = diff_paths(rust_crate_dir, dart_root).context("cannot diff path")?;
Ok(path_to_string(&diff.join("target").join("release/"))?.replace('\\', "/"))
}

fn compute_dart_type_rename(config: &Config) -> anyhow::Result<HashMap<String, String>> {
fn convert_rust_type(raw: &str) -> anyhow::Result<Vec<String>> {
Ok(vec![
canonicalize_rust_type(raw)?,
canonicalize_rust_type(&format!(
"flutter_rust_bridge::for_generated::RustAutoOpaqueInner<{}>",
raw
))?,
])
}

Ok(config
.dart_type_rename
.clone()
.unwrap_or_default()
.iter()
.map(|(k, v)| {
Ok(convert_rust_type(k)?
.into_iter()
.map(|parsed_k| (parsed_k, v.to_owned()))
.collect_vec())
})
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter()
.flatten()
.collect())
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl InternalConfig {
rust_path_migrator::migrate_rust_input_config(&config.rust_root, &config.rust_input)?;
let RustInputInfo {
rust_crate_dir,
third_party_crate_names,
rust_input_namespace_pack,
} = rust_path_parser::compute_rust_input_info(&migrated_rust_input, &base_dir)?;

Expand Down Expand Up @@ -96,15 +97,16 @@ impl InternalConfig {
},
parser: ParserInternalConfig {
hir: ParserHirInternalConfig {
rust_crate_dir: rust_crate_dir.clone(),
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
third_party_crate_names,
},
mir: ParserMirInternalConfig {
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
force_codec_mode_pack: compute_force_codec_mode_pack(full_dep),
default_stream_sink_codec,
default_rust_opaque_codec,
},
rust_crate_dir: rust_crate_dir.clone(),
},
generator,
polisher: PolisherInternalConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,52 @@
use crate::codegen::config::internal_config_parser::dart_path_parser::compute_path_map;
use crate::codegen::config::internal_config_parser::rust_path_migrator::ConfigRustRootAndRustInput;
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use crate::codegen::ir::mir::namespace::Namespace;
use crate::codegen::parser::mir::internal_config::RustInputNamespacePack;
use crate::codegen::Config;
use crate::utils::crate_name::CrateName;
use crate::utils::namespace::Namespace;
use crate::utils::path_utils::canonicalize_with_error_message;
use anyhow::Context;
use itertools::Itertools;
use std::path::{Path, PathBuf};

pub(super) struct RustInputInfo {
pub rust_crate_dir: PathBuf,
pub third_party_crate_names: Vec<CrateName>,
pub rust_input_namespace_pack: RustInputNamespacePack,
}

pub(super) fn compute_rust_input_info(
migrated_rust_input: &ConfigRustRootAndRustInput,
base_dir: &Path,
) -> anyhow::Result<RustInputInfo> {
let rust_input_namespace_prefixes_raw =
compute_rust_input_namespace_prefixes_raw(&migrated_rust_input.rust_input);

Ok(RustInputInfo {
rust_crate_dir: compute_rust_crate_dir(base_dir, &migrated_rust_input.rust_root)?,
rust_input_namespace_pack: compute_rust_input_namespace_pack(
&migrated_rust_input.rust_input,
)?,
third_party_crate_names: compute_third_party_crate_names(
&rust_input_namespace_prefixes_raw,
),
rust_input_namespace_pack: RustInputNamespacePack {
rust_input_namespace_prefixes: tidy_rust_input_namespace_prefixes(
&rust_input_namespace_prefixes_raw,
),
},
})
}

fn compute_rust_input_namespace_pack(
raw_rust_input: &str,
) -> anyhow::Result<RustInputNamespacePack> {
Ok(RustInputNamespacePack::new(
raw_rust_input
.split(',')
.map(|s| Namespace::new_raw(s.to_owned()))
.collect_vec(),
))
fn compute_rust_input_namespace_prefixes_raw(raw_rust_input: &str) -> Vec<Namespace> {
raw_rust_input
.split(',')
.map(|s| Namespace::new_raw(s.to_owned()))
.collect_vec()
}

// const BLACKLIST_FILE_NAMES: [&str; 1] = ["mod.rs"];
//
// let glob_pattern = base_dir.join(raw_rust_input);
//
// let mut pack = RustInputNamespacePack {
// rust_input_namespaces: vec![],
// };
// for path in glob_path(&glob_pattern)?.into_iter() {
// if BLACKLIST_FILE_NAMES.contains(&path.file_name().unwrap().to_str().unwrap()) {
// pack.rust_suppressed_input_namespaces.push(path);
// } else {
// pack.rust_input_namespaces.push(path);
// }
// }
//
// // This will stop the whole generator and tell the users, so we do not care about testing it
// // frb-coverage:ignore-start
// ensure!(
// !pack.rust_input_namespaces.is_empty(),
// "Find zero rust input paths. (glob_pattern={glob_pattern:?})"
// );
// // ensure!(
// // !pack.rust_input_namespaces.iter().any(|p| path_to_string(p).unwrap().contains("lib.rs")),
// // "Do not use `lib.rs` as a Rust input. Please put code to be generated in something like `api.rs`.",
// // );
// // frb-coverage:ignore-end
//
// Ok(pack)
fn tidy_rust_input_namespace_prefixes(raw: &[Namespace]) -> Vec<Namespace> {
raw.iter()
.map(|x| Namespace::new_raw(x.joined_path.replace('-', "_")))
.collect_vec()
}

fn compute_rust_crate_dir(base_dir: &Path, rust_root: &str) -> anyhow::Result<PathBuf> {
Expand All @@ -85,3 +68,16 @@ pub(super) fn compute_rust_output_path(
fn fallback_rust_output_path(rust_crate_dir: &Path) -> PathBuf {
rust_crate_dir.join("src").join("frb_generated.rs")
}

fn compute_third_party_crate_names(
rust_input_namespace_prefixes_raw: &[Namespace],
) -> Vec<CrateName> {
rust_input_namespace_prefixes_raw
.iter()
.map(|x| x.path()[0])
.filter(|x| *x != CrateName::SELF_CRATE)
.dedup()
.sorted()
.map(|x| CrateName::new(x.to_owned()))
.collect_vec()
}
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/dumper/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) struct DumperInternalConfig {
pub enum ConfigDumpContent {
Config,
Source,
Hir,
Mir,
GeneratorInfo,
GeneratorSpec,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct GeneratorApiDartInternalConfig {
pub dart_enums_style: bool,
pub dart3: bool,
pub dart_decl_base_output_path: PathBuf,
pub dart_impl_output_path: TargetOrCommonMap<PathBuf>,
pub dart_entrypoint_class_name: String,
pub dart_preamble: String,
pub dart_type_rename: HashMap<String, String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::codegen::ir::mir::func::{
MirFunc, MirFuncAccessorMode, MirFuncArgMode, MirFuncDefaultConstructorMode, MirFuncOwnerInfo,
MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode,
};
use crate::codegen::ir::mir::namespace::NamespacedName;
use crate::if_then_some;
use crate::library::codegen::generator::api_dart::spec_generator::base::*;
use crate::utils::namespace::NamespacedName;
use convert_case::{Case, Casing};
use itertools::Itertools;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::codegen::ir::mir::namespace::Namespace;
use crate::utils::basic_code::DartBasicHeaderCode;
use crate::utils::namespace::Namespace;
use serde::Serialize;

pub(crate) mod field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::codegen::generator::api_dart::spec_generator::class::method::generate
use crate::codegen::generator::api_dart::spec_generator::class::misc::generate_class_extra_body;
use crate::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait;
use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass;
use crate::codegen::ir::mir::namespace::NamespacedName;
use crate::codegen::ir::mir::ty::rust_opaque::MirTypeRustOpaque;
use crate::library::codegen::generator::api_dart::spec_generator::base::*;
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use crate::library::codegen::ir::mir::ty::MirTypeTrait;
use crate::utils::namespace::NamespacedName;
use lazy_static::lazy_static;
use regex::Regex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::codegen::generator::api_dart::spec_generator::misc::{
};
use crate::codegen::ir::mir::field::MirField;
use crate::codegen::ir::mir::func::{MirFunc, MirFuncArgMode, MirFuncMode};
use crate::codegen::ir::mir::namespace::Namespace;
use crate::codegen::ir::mir::ty::delegate::{MirTypeDelegate, MirTypeDelegateStreamSink};
use crate::codegen::ir::mir::ty::MirType;
use crate::if_then_some;
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use crate::utils::basic_code::DartBasicHeaderCode;
use crate::utils::namespace::Namespace;
use itertools::Itertools;
use serde::Serialize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::codegen::ir::mir::ty::delegate::{
use crate::codegen::ir::mir::ty::general_list::MirTypeGeneralList;
use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive;
use crate::codegen::ir::mir::ty::{MirType, MirTypeTrait};
use crate::utils::syn_utils::canonicalize_rust_type;
use convert_case::{Case, Casing};
use enum_dispatch::enum_dispatch;
use itertools::Itertools;
Expand Down Expand Up @@ -217,7 +218,12 @@ impl<'a> ApiDartGeneratorInfoTrait for RustAutoOpaqueImplicitApiDartGenerator<'a

impl<'a> ApiDartGeneratorInfoTrait for RustOpaqueApiDartGenerator<'a> {
fn dart_api_type(&self) -> String {
self.mir.sanitized_type()
self.context
.config
.dart_type_rename
.get(&canonicalize_rust_type(&self.mir.inner.0).unwrap())
.cloned()
.unwrap_or_else(|| self.mir.sanitized_type())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use crate::codegen::ir::mir::annotation::MirDartAnnotation;
use crate::codegen::ir::mir::comment::MirComment;
use crate::codegen::ir::mir::func::MirFunc;
use crate::codegen::ir::mir::import::MirDartImport;
use crate::codegen::ir::mir::namespace::Namespace;
use crate::codegen::ir::mir::pack::DistinctTypeGatherer;
use crate::codegen::ir::mir::ty::MirType;
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use crate::library::codegen::ir::mir::ty::MirTypeTrait;
use crate::utils::namespace::Namespace;
use crate::utils::path_utils::path_to_string;
use anyhow::Context;
use itertools::Itertools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ use crate::codegen::generator::api_dart::spec_generator::function::ApiDartGenera
use crate::codegen::generator::api_dart::spec_generator::misc::generate_imports_which_types_and_funcs_use;
use crate::codegen::generator::api_dart::spec_generator::sanity_checker::sanity_check_class_name_duplicates;
use crate::codegen::ir::mir::func::{MirFunc, MirFuncOwnerInfo};
use crate::codegen::ir::mir::namespace::Namespace;
use crate::codegen::ir::mir::pack::{MirPack, MirPackComputedCache};
use crate::codegen::ir::mir::skip::{MirSkip, MirSkipReason};
use crate::codegen::ir::mir::ty::MirType;
use crate::codegen::ConfigDumpContent;
use crate::library::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait;
use crate::library::codegen::ir::mir::ty::MirTypeTrait;
use crate::utils::basic_code::DartBasicHeaderCode;
use crate::utils::namespace::Namespace;
use anyhow::Result;
use itertools::Itertools;
use itertools::{concat, Itertools};
use serde::Serialize;
use std::collections::{HashMap, HashSet};
use ConfigDumpContent::GeneratorInfo;
Expand All @@ -41,8 +42,7 @@ pub(crate) struct ApiDartOutputSpecItem {
pub classes: Vec<ApiDartGeneratedClass>,
pub imports: DartBasicHeaderCode,
pub preamble: String,
pub unused_types: Vec<String>,
pub skipped_functions: Vec<String>,
pub skips: Vec<MirSkip>,
pub needs_freezed: bool,
}

Expand Down Expand Up @@ -125,25 +125,31 @@ fn generate_item(

sanity_check_class_name_duplicates(&classes)?;

let unused_types = (context.mir_pack.unused_types.iter())
.filter(|t| &t.namespace == namespace)
.map(|t| t.name.to_owned())
.collect_vec();

let skipped_functions = (context.mir_pack.skipped_functions.iter())
.filter(|t| &t.namespace == namespace)
.map(|t| t.name.to_owned())
.collect_vec();

let needs_freezed = classes.iter().any(|class| class.needs_freezed);

Ok(ApiDartOutputSpecItem {
funcs,
classes,
imports,
preamble: context.config.dart_preamble.clone(),
unused_types,
skipped_functions,
skips: compute_skips(context.mir_pack, namespace),
needs_freezed,
})
}

fn compute_skips(mir_pack: &MirPack, namespace: &Namespace) -> Vec<MirSkip> {
let unused_types = (mir_pack.unused_types.iter())
.filter(|t| &t.namespace == namespace)
.map(|name| MirSkip {
name: name.clone(),
reason: MirSkipReason::IgnoredTypeNotUsedByPub,
})
.collect_vec();

let skipped_functions = (mir_pack.skipped_functions.iter())
.filter(|t| &t.name.namespace == namespace)
.cloned()
.collect_vec();

concat([unused_types, skipped_functions])
}
Loading
Loading