Skip to main content

knave_expand/project/
mod.rs

1mod dependency_reader;
2mod fields;
3mod name;
4mod problems;
5mod reader;
6
7use std::path::PathBuf;
8
9pub use dependency_reader::Section;
10pub use name::ProjectName;
11pub use problems::ProjectProblems;
12pub use reader::ProjectReader;
13
14use crate::diagnostic::Diagnostics;
15use crate::source::Span;
16
17#[derive(Debug)]
18pub struct Project {
19    pub name: String,
20    pub version: String,
21    pub entry: PathBuf,
22    pub library_root: PathBuf,
23    pub edition: i128,
24    pub libraries: Vec<LibraryDependency>,
25    pub dependencies: Vec<CrateDependency>,
26    pub dev_dependencies: Vec<CrateDependency>,
27    pub sections: Vec<SectionHead>,
28}
29
30#[derive(Debug)]
31pub struct SectionHead {
32    pub section: Section,
33    pub span: Span,
34    pub has_entries: bool,
35}
36
37#[derive(Debug)]
38pub struct LibraryDependency {
39    pub name: String,
40    pub name_span: Span,
41    pub source: LibrarySource,
42}
43
44#[derive(Debug)]
45pub enum LibrarySource {
46    Path(PathBuf),
47    Git { url: String, commit: String },
48}
49
50impl LibrarySource {
51    pub const FULL_COMMIT_LENGTH: usize = 40;
52}
53
54#[derive(Debug)]
55pub struct CrateDependency {
56    pub name: String,
57    pub version: Option<String>,
58    pub features: Vec<String>,
59    pub path: Option<PathBuf>,
60}
61
62impl Project {
63    pub fn unbuilt_sections(&self) -> Diagnostics {
64        let mut problems = Diagnostics::default();
65        self.sections
66            .iter()
67            .filter(|head| head.has_entries && !head.section.is_built())
68            .for_each(|head| {
69                problems.push(ProjectProblems::unbuilt_section(
70                    head.section.name(),
71                    head.span,
72                ))
73            });
74        problems
75    }
76}