1use serde::{Deserialize, Serialize};
2
3use crate::{configuration_file::ConfigurationFileFormat, target::Target};
4
5use std::{
6 collections::BTreeMap,
7 hash::Hash,
8 path::{Path, PathBuf},
9};
10
11#[derive(Debug, Serialize, Deserialize, Hash)]
13#[serde(rename_all = "camelCase")]
14pub struct Project {
15 name: String,
16 root: PathBuf,
17 configuration_file_path: PathBuf,
18 configuration_file_format: ConfigurationFileFormat,
19 #[serde(flatten)]
20 configuration: ProjectConfiguration,
21}
22
23impl Project {
24 pub fn from_configuration_and_metadata<P: AsRef<Path>>(
25 name: &str,
26 source: (P, ConfigurationFileFormat),
27 configuration: ProjectConfiguration,
28 ) -> Self {
29 let mut root = source.0.as_ref().to_owned();
30 let _ = root.pop();
31
32 Project {
33 name: name.to_owned(),
34 root,
35 configuration_file_path: source.0.as_ref().to_owned(),
36 configuration_file_format: source.1,
37 configuration,
38 }
39 }
40
41 pub fn name(&self) -> &str {
42 &self.name
43 }
44
45 pub fn root(&self) -> &Path {
46 &self.root
47 }
48
49 pub fn configuration_file_path(&self) -> &Path {
50 &self.configuration_file_path
51 }
52
53 pub fn configuration_file_format(&self) -> ConfigurationFileFormat {
54 self.configuration_file_format
55 }
56
57 pub fn targets(&self) -> &BTreeMap<String, Target> {
58 &self.configuration.targets
59 }
60}
61
62#[derive(Debug, Serialize, Hash, Deserialize)]
63pub struct ProjectConfiguration {
64 #[serde(default)]
65 targets: BTreeMap<String, Target>,
66}