Skip to content

Commit

Permalink
Merge pull request #2010 from fzyzcjy/feat/12120
Browse files Browse the repository at this point in the history
Improve Dart output directory of third party crates
  • Loading branch information
fzyzcjy authored Jun 2, 2024
2 parents 2a676f9 + 8e11bda commit 2645f09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions frb_codegen/src/library/codegen/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ impl GeneratorProgressBarPack {
}
}
}

pub(crate) const THIRD_PARTY_DIR_NAME: &str = "third_party";
14 changes: 7 additions & 7 deletions frb_codegen/src/library/utils/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")))
Expand Down

0 comments on commit 2645f09

Please sign in to comment.