diff --git a/tools/copy_bom/src/bom.rs b/tools/copy_bom/src/bom.rs new file mode 100644 index 00000000..3bc1958f --- /dev/null +++ b/tools/copy_bom/src/bom.rs @@ -0,0 +1,98 @@ +//! This file defines data structures to store contents in bom file +//! as well as all management on these strcutures. +//! Structures `Bom`, `Target`, `SymLink`, `Source`, `NormalFile`, `FileWithOption` +//! are used to parse the bom file. +//! Structures ending with `management` are used to define managements on different levels. +//! We will construct a BomManagement for each bom file (the top bom file and all included bom files). +//! Then do real file operations on each BomManagement +use crate::error::{FILE_NOT_EXISTS_ERROR, INVALID_BOM_FILE_ERROR}; +use crate::util::{ + check_file_hash, copy_dir, copy_file, copy_shared_object, create_link, dest_in_root, + find_dependent_shared_objects, find_included_bom_file, mkdir, resolve_envs, +}; +use serde::{Deserialize, Serialize}; +use serde_yaml; +use std::collections::{HashSet, VecDeque}; +use std::hash::Hash; +use std::path::PathBuf; +use std::slice::Iter; + +// The whole bom file +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Bom { + pub includes: Option>, + pub excludes: Option>, + targets: Option>, +} + +// target in a bom file. +// Each target represents the same destination. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Target { + target: String, + mkdirs: Option>, + createlinks: Option>, + copy: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SymLink { + src: String, + linkname: String, +} + +// source in a target. +// each Source has the same `from` directory. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Source { + from: Option, + dirs: Option>, + files: Option>, +} + +// A file need to be copied +// It can be only a filename; or file with multiple options to enable checking hash, renaming file, etc. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(untagged)] +pub enum NormalFile { + FileName(String), + FileWithOption(FileWithOption), +} + +// A file with multiple optional options +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct FileWithOption { + name: String, + hash: Option, + autodep: Option, + rename: Option, +} + +/// all operations defined for one bom file +#[derive(Default)] +pub struct BomManagement { + dirs_to_make: Vec, + links_to_create: Vec<(String, String)>, + dirs_to_copy: Vec<(String, String)>, + files_to_copy: Vec<(String, String)>, + shared_objects_to_copy: Vec<(String, String)>, +} + +/// all operations defined for one target +#[derive(Default)] +pub struct TargetManagement { + dirs_to_make: Vec, + links_to_create: Vec<(String, String)>, + dirs_to_copy: Vec<(String, String)>, + files_to_copy: Vec<(String, String)>, + files_autodep: Vec, +} + +/// all operations defined for one source +#[derive(Default)] +pub struct SourceManagement { + dirs_to_copy: Vec<(String, String)>, + files_to_copy: Vec<(String, String)>, + files_autodep: Vec, +} +