MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / parse_component

Method parse_component

crates/test/src/lib.rs:438–475  ·  view source on GitHub ↗

Parsers the component located at `path` and creates all information necessary for a `Component` return value.

(&self, path: &Path, kind: Kind, mut bindgen: Bindgen)

Source from the content-addressed store, hash-verified

436 /// Parsers the component located at `path` and creates all information
437 /// necessary for a `Component` return value.
438 fn parse_component(&self, path: &Path, kind: Kind, mut bindgen: Bindgen) -> Result<Component> {
439 let extension = path
440 .extension()
441 .and_then(|s| s.to_str())
442 .context("non-utf-8 path extension")?;
443
444 let language = match extension {
445 "rs" => Language::Rust,
446 "c" => Language::C,
447 "cpp" => Language::Cpp,
448 "wat" => Language::Wat,
449 "cs" => Language::Csharp,
450 "mbt" => Language::MoonBit,
451 "go" => Language::Go,
452 other => Language::Custom(custom::Language::lookup(self, other)?),
453 };
454
455 let contents = fs::read_to_string(&path)?;
456 let config = match language.obj().comment_prefix_for_test_config() {
457 Some(comment) => {
458 config::parse_test_config::<config::RuntimeTestConfig>(&contents, comment)?
459 }
460 None => Default::default(),
461 };
462 assert!(bindgen.args.is_empty());
463 bindgen.args = config.args.into();
464
465 Ok(Component {
466 name: path.file_stem().unwrap().to_str().unwrap().to_string(),
467 path: path.to_path_buf(),
468 language,
469 bindgen,
470 kind,
471 contents,
472 lang_config: config.lang,
473 wasmtime_flags: config.wasmtime_flags,
474 })
475 }
476
477 /// Prepares all languages in use in `test` as part of a one-time
478 /// initialization step.

Callers 1

load_runtime_testMethod · 0.80

Calls 4

and_thenMethod · 0.80
objMethod · 0.80
to_stringMethod · 0.45

Tested by

no test coverage detected