Skip to content

Commit

Permalink
more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
noise64 committed Oct 15, 2024
1 parent dc2fe4a commit 9b20561
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion wasm-rpc-stubgen/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn generate_cargo_toml(def: &StubDefinition) -> anyhow::Result<()> {
);

let stub_package_name = def.stub_package_name();
for (dep_package, dep_package_sources) in def.source_packages_with_wit_sources() {
for (dep_package, dep_package_sources) in def.packages_with_wit_sources() {
let dep_package_name = &dep_package.name;

if *dep_package_name == stub_package_name {
Expand Down
4 changes: 2 additions & 2 deletions wasm-rpc-stubgen/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::fs::copy;
use crate::naming;
use crate::rust::generate_stub_source;
use crate::stub::StubDefinition;
use crate::wit::{copy_wit_files, generate_stub_wit_to_target};
use crate::wit::{copy_wit_dependencies, generate_stub_wit_to_target};
use crate::wit_resolve::ResolvedWitDir;
use anyhow::Context;
use fs_extra::dir::CopyOptions;
Expand Down Expand Up @@ -56,7 +56,7 @@ pub async fn build(

pub fn generate_stub_wit_dir(stub_def: &StubDefinition) -> anyhow::Result<ResolvedWitDir> {
generate_stub_wit_to_target(stub_def).context("Failed to generate the stub wit file")?;
copy_wit_files(stub_def).context("Failed to copy the dependent wit files")?;
copy_wit_dependencies(stub_def).context("Failed to copy the dependent wit files")?;
stub_def
.resolve_target_wit()
.context("Failed to resolve the result WIT root")
Expand Down
2 changes: 1 addition & 1 deletion wasm-rpc-stubgen/src/commands/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fs::{OverwriteSafeAction, OverwriteSafeActionPlan};
use crate::model::validation::ValidatedResult;
use colored::Colorize;
use crate::fs::{OverwriteSafeAction, OverwriteSafeActionPlan};

pub fn log_action<T: AsRef<str>>(action: &str, subject: T) {
println!("{} {}", action.green(), subject.as_ref())
Expand Down
4 changes: 1 addition & 3 deletions wasm-rpc-stubgen/src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ impl StubDefinition {
// and similar reasoning is used when in one function we get and resolve an ID, since
// these would be internal arena errors.

pub fn source_packages_with_wit_sources(
&self,
) -> impl Iterator<Item = (&Package, &Vec<PathBuf>)> {
pub fn packages_with_wit_sources(&self) -> impl Iterator<Item = (&Package, &Vec<PathBuf>)> {
self.resolve
.topological_packages()
.into_iter()
Expand Down
19 changes: 6 additions & 13 deletions wasm-rpc-stubgen/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use crate::commands::log::{log_action, log_warn_action};
use crate::fs::{copy, copy_transformed};
use crate::fs::{copy, copy_transformed, must_get_file_name};
use crate::stub::{
FunctionParamStub, FunctionResultStub, FunctionStub, InterfaceStub, InterfaceStubImport,
InterfaceStubTypeDef, StubDefinition,
Expand Down Expand Up @@ -495,14 +495,14 @@ fn write_param_list(
Ok(())
}

pub fn copy_wit_files(def: &StubDefinition) -> anyhow::Result<()> {
pub fn copy_wit_dependencies(def: &StubDefinition) -> anyhow::Result<()> {
let stub_package_name = def.stub_package_name();
let remove_stub_imports = import_remover(&stub_package_name);

let target_wit_root = def.target_wit_root();
let target_deps = target_wit_root.join(naming::wit::DEPS_DIR);

for (package, sources) in def.source_packages_with_wit_sources() {
for (package, sources) in def.packages_with_wit_sources() {
if package.name == stub_package_name {
log_warn_action("Skipping", format!("package {}", package.name));
continue;
Expand All @@ -513,18 +513,11 @@ pub fn copy_wit_files(def: &StubDefinition) -> anyhow::Result<()> {
log_action("Copying", format!("source package {}", package.name));
for source in sources {
if is_source_package {
// TODO: naming to def and review this naming
let dest = target_deps
.join(format!(
"{}_{}",
def.source_package_name.namespace, def.source_package_name.name
.join(naming::wit::package_dep_folder_name(
&def.source_package_name,
))
.join(source.file_name().ok_or_else(|| {
anyhow!(
"Failed to get file name for source: {}",
source.to_string_lossy()
)
})?);
.join(must_get_file_name(source)?);
log_action(
" Copying",
format!(
Expand Down

0 comments on commit 9b20561

Please sign in to comment.