foundry_compilers/compilers/vyper/
input.rs

1use super::VyperLanguage;
2use crate::{
3    artifacts::vyper::{VyperInput, VyperSettings},
4    compilers::CompilerInput,
5};
6use foundry_compilers_artifacts::sources::{Source, Sources};
7use semver::Version;
8use serde::Serialize;
9use std::{borrow::Cow, path::Path};
10
11#[derive(Clone, Debug, Serialize)]
12pub struct VyperVersionedInput {
13    #[serde(flatten)]
14    pub input: VyperInput,
15    #[serde(skip)]
16    pub version: Version,
17}
18
19impl CompilerInput for VyperVersionedInput {
20    type Settings = VyperSettings;
21    type Language = VyperLanguage;
22
23    fn build(
24        sources: Sources,
25        settings: Self::Settings,
26        _language: Self::Language,
27        version: Version,
28    ) -> Self {
29        Self { input: VyperInput::new(sources, settings, &version), version }
30    }
31
32    fn compiler_name(&self) -> Cow<'static, str> {
33        "Vyper".into()
34    }
35
36    fn strip_prefix(&mut self, base: &Path) {
37        self.input.strip_prefix(base);
38    }
39
40    fn language(&self) -> Self::Language {
41        VyperLanguage
42    }
43
44    fn version(&self) -> &Version {
45        &self.version
46    }
47
48    fn sources(&self) -> impl Iterator<Item = (&Path, &Source)> {
49        self.input
50            .sources
51            .iter()
52            .chain(self.input.interfaces.iter())
53            .map(|(path, source)| (path.as_path(), source))
54    }
55}