Skip to content

Commit

Permalink
Stub out calls to generate_webc_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Nov 14, 2022
1 parent 306cb85 commit 5ed1c99
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_json = "1.0.85"
webc = "3.0.1"
wasmer-pack = { version = "0.5.0", path = "../wasmer-pack" }
wapm-targz-to-pirita = { git = "ssh://[email protected]/wasmerio/pirita.git", version = "0.1.0" }
wapm-toml = "0.3.0"

[dev-dependencies]
insta = "1.18.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Codegen {
pub fn run(self, language: Language) -> Result<(), Error> {
let Codegen { out_dir, input } = self;

let pkg = crate::load_pirita_file(&input)?;
let pkg = crate::pirita::load(&input)?;

let files = match language {
Language::JavaScript => wasmer_pack::generate_javascript(&pkg)?,
Expand Down
2 changes: 0 additions & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ pub use crate::{
codegen::{Codegen, Language},
show::{Format, Show},
};

pub(crate) use crate::pirita::load_pirita_file;
53 changes: 47 additions & 6 deletions crates/cli/src/pirita.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use anyhow::{Context, Error};
use wapm_targz_to_pirita::TransformManifestFunctions;
use wasmer_pack::{Command, Interface, Library, Metadata, Module, Package};
use webc::{Manifest, ParseOptions, WebC, WebCOwned};

pub(crate) fn load_pirita_file(path: &Path) -> Result<Package, Error> {
let options = ParseOptions::default();
pub(crate) fn load(path: &Path) -> Result<Package, Error> {
let raw_webc: Vec<u8> = if path.is_dir() {
webc_from_dir(path)?
} else if path.extension() == Some("webc".as_ref()) {
std::fs::read(path).with_context(|| format!("Unable to read \"{}\"", path.display()))?
} else {
webc_from_tarball(path)?
};

let raw =
std::fs::read(path).with_context(|| format!("Unable to read \"{}\"", path.display()))?;
let webc = WebCOwned::parse(raw, &options)
let options = ParseOptions::default();
let webc = WebCOwned::parse(raw_webc, &options)
.with_context(|| format!("Unable to parse \"{}\" as a WEBC file", path.display()))?;

let fully_qualified_package_name = webc.get_package_name();
Expand All @@ -20,6 +26,41 @@ pub(crate) fn load_pirita_file(path: &Path) -> Result<Package, Error> {
Ok(Package::new(metadata, libraries, commands))
}

fn webc_from_dir(path: &Path) -> Result<Vec<u8>, Error> {
if !path.join("wapm.toml").exists() {
anyhow::bail!(
"The \"{}\" directory doesn't contain a \"wapm.tom\" file",
path.display()
);
}

todo!("Read all files into a FileMap and call generate_webc_file()");
}

fn webc_from_tarball(path: &Path) -> Result<Vec<u8>, Error> {
let tarball =
std::fs::read(path).with_context(|| format!("Unable to read \"{}\"", path.display()))?;
let files =
wapm_targz_to_pirita::unpack_tar_gz(tarball).context("Unable to unpack the tarball")?;

wapm_targz_to_pirita::generate_webc_file(
files,
&PathBuf::new(),
None,
&TransformManifestFunctions {
get_atoms_wapm_toml: wapm_toml::get_wapm_atom_file_paths,
get_dependencies: wapm_toml::get_dependencies,
get_package_annotations: wapm_toml::get_package_annotations,
get_modules: wapm_toml::get_modules,
get_commands: wapm_toml::get_commands,
get_manifest_file_names: wapm_toml::get_manifest_file_names,
get_metadata_paths: wapm_toml::get_metadata_paths,
get_bindings: wapm_toml::get_bindings,
get_wapm_manifest_file_name: wapm_toml::get_wapm_manifest_file_name,
},
)
}

fn commands(webc: &WebC<'_>, fully_qualified_package_name: &str) -> Result<Vec<Command>, Error> {
let mut commands = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Show {

impl Show {
pub fn run(self) -> Result<(), Error> {
let pkg = crate::load_pirita_file(&self.input).context("Unable to load the package")?;
let pkg = crate::pirita::load(&self.input).context("Unable to load the package")?;

let summary: Summary = summarize(&pkg);

Expand Down

0 comments on commit 5ed1c99

Please sign in to comment.