From 57edf7051f03dbc07a7f15e32d101989847d6175 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 14:48:54 +0800 Subject: [PATCH 1/3] chore: const --- frb_codegen/src/library/codegen/misc.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frb_codegen/src/library/codegen/misc.rs b/frb_codegen/src/library/codegen/misc.rs index daede6a235..9df5aada35 100644 --- a/frb_codegen/src/library/codegen/misc.rs +++ b/frb_codegen/src/library/codegen/misc.rs @@ -33,3 +33,5 @@ impl GeneratorProgressBarPack { } } } + +pub(crate) const THIRD_PARTY_DIR_NAME: &'static str = "third_party"; From 45343f267467f285511c30d4f05a80dc42393493 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 14:50:59 +0800 Subject: [PATCH 2/3] feat: more --- .../codegen/generator/api_dart/text_generator.rs | 11 +++++++++-- frb_codegen/src/library/utils/namespace.rs | 14 +++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs b/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs index 39ae0064f6..1047bec2f9 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs @@ -5,11 +5,13 @@ use crate::codegen::generator::api_dart::spec_generator::{ }; use crate::codegen::generator::misc::target::TargetOrCommonMap; use crate::codegen::generator::misc::{generate_code_header, PathText, PathTexts}; +use crate::codegen::misc::THIRD_PARTY_DIR_NAME; use crate::utils::basic_code::DartBasicHeaderCode; +use crate::utils::crate_name::CrateName; use crate::utils::namespace::Namespace; use crate::utils::path_utils::path_to_string; use anyhow::Context; -use itertools::Itertools; +use itertools::{concat, Itertools}; use pathdiff::diff_paths; use std::path::{Path, PathBuf}; @@ -146,7 +148,12 @@ fn compute_path_from_namespace( dart_decl_base_output_path: &Path, namespace: &Namespace, ) -> PathBuf { - let chunks = namespace.path_exclude_self_crate(); + let raw_path = namespace.path(); + let chunks = match raw_path[0] { + CrateName::SELF_CRATE => raw_path[1..].to_owned(), + _ => concat([vec![THIRD_PARTY_DIR_NAME], raw_path.clone()]), + }; + let ans_without_extension = (chunks.iter()).fold(dart_decl_base_output_path.to_owned(), |a, b| a.join(b)); ans_without_extension.with_extension("dart") diff --git a/frb_codegen/src/library/utils/namespace.rs b/frb_codegen/src/library/utils/namespace.rs index 9c7b24f77f..9bf2248453 100644 --- a/frb_codegen/src/library/utils/namespace.rs +++ b/frb_codegen/src/library/utils/namespace.rs @@ -54,13 +54,13 @@ impl Namespace { self.joined_path.split(Self::SEP).collect() } - pub fn path_exclude_self_crate(&self) -> Vec<&str> { - let mut path = self.path(); - if path.first() == Some(&CrateName::SELF_CRATE) { - path.remove(0); - } - path - } + // pub fn path_exclude_self_crate(&self) -> Vec<&str> { + // let mut path = self.path(); + // if path.first() == Some(&CrateName::SELF_CRATE) { + // path.remove(0); + // } + // path + // } pub fn to_pseudo_io_path(&self, extension: &str) -> PathBuf { PathBuf::from(&format!("/{}.{extension}", self.path().join("/"))) From 24d245a820793cabf22e611c2a27eb981c349a10 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 15:00:20 +0800 Subject: [PATCH 3/3] chore: lint --- frb_codegen/src/library/codegen/misc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/misc.rs b/frb_codegen/src/library/codegen/misc.rs index 9df5aada35..315fcb6d5f 100644 --- a/frb_codegen/src/library/codegen/misc.rs +++ b/frb_codegen/src/library/codegen/misc.rs @@ -34,4 +34,4 @@ impl GeneratorProgressBarPack { } } -pub(crate) const THIRD_PARTY_DIR_NAME: &'static str = "third_party"; +pub(crate) const THIRD_PARTY_DIR_NAME: &str = "third_party";