MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_source

Function parse_source

crates/component-macro/src/bindgen.rs:193–244  ·  view source on GitHub ↗
(
    paths: &Vec<String>,
    inline: &Option<String>,
)

Source from the content-addressed store, hash-verified

191}
192
193fn parse_source(
194 paths: &Vec<String>,
195 inline: &Option<String>,
196) -> anyhow::Result<(Resolve, Vec<PackageId>, Vec<PathBuf>)> {
197 let mut resolve = Resolve::default();
198 resolve.all_features = true;
199 let mut files = Vec::new();
200 let mut pkgs = Vec::new();
201 let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
202 let default = root.join("wit");
203
204 let parse = |resolve: &mut Resolve,
205 files: &mut Vec<PathBuf>,
206 pkgs: &mut Vec<PackageId>,
207 paths: &[PathBuf]|
208 -> anyhow::Result<_> {
209 for path in paths {
210 let p = root.join(path);
211 // Try to normalize the path to make the error message more understandable when
212 // the path is not correct. Fallback to the original path if normalization fails
213 // (probably return an error somewhere else).
214 let normalized_path = match std::fs::canonicalize(&p) {
215 Ok(p) => p,
216 Err(_) => p.to_path_buf(),
217 };
218 let (pkg, sources) = resolve.push_path(normalized_path)?;
219 pkgs.push(pkg);
220 files.extend(sources.paths().map(|p| p.to_owned()));
221 }
222 Ok(())
223 };
224
225 if paths.is_empty() {
226 if default.exists() {
227 parse(&mut resolve, &mut files, &mut pkgs, &[default])?;
228 }
229 } else {
230 parse(
231 &mut resolve,
232 &mut files,
233 &mut pkgs,
234 &paths.iter().map(|s| s.into()).collect::<Vec<_>>(),
235 )?;
236 }
237
238 if let Some(inline) = inline {
239 pkgs.truncate(0);
240 pkgs.push(resolve.push_group(UnresolvedPackageGroup::parse("macro-input", inline)?)?);
241 }
242
243 Ok((resolve, pkgs, files))
244}
245
246mod kw {
247 syn::custom_keyword!(inline);

Callers 1

parseMethod · 0.85

Calls 13

fromFunction · 0.85
OkFunction · 0.85
existsMethod · 0.80
newFunction · 0.50
parseFunction · 0.50
unwrapMethod · 0.45
joinMethod · 0.45
pushMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected