Skip to main content

OFile

Struct OFile 

Source
pub struct OFile {
    pub name: String,
    pub include_paths: Vec<PathBuf>,
    pub compile_flags: Vec<String>,
}

Fields§

§name: String§include_paths: Vec<PathBuf>§compile_flags: Vec<String>

Implementations§

Source§

impl OFile

Source

pub fn new( name: &str, include_paths: Vec<PathBuf>, compile_flags: Vec<String>, ) -> Self

Examples found in repository?
examples/project_expand/main.rs (line 86)
72fn main() {
73    env_logger::init();
74
75    let args: Args = argh::from_env();
76
77    let srcdir = args.src;
78    let sandbox = args.sandbox;
79
80    let mut g = G::new(srcdir.clone(), sandbox);
81
82    let main_c = g
83        .add_root_node(CFile::new("project_expand/main.c"))
84        .unwrap();
85    let main_o = g
86        .add_node(OFile::new("project_expand/main.o", vec![], vec![]))
87        .unwrap();
88    let _wrapper_h = g
89        .add_root_node(HFile::new("project_expand/wrapper.h"))
90        .unwrap();
91    let app = g.add_node(XFile::new("project_expand/app")).unwrap();
92
93    let languages_yml = g
94        .add_root_node(YmlDesc::new("project_expand/languages.yml"))
95        .unwrap();
96    let languages_json = g
97        .add_node(JsonDesc::new("project_expand/languages.json"))
98        .unwrap();
99    let liblangs = g
100        .add_node(AFile::new("project_expand/generated/liblangs.a"))
101        .unwrap();
102
103    g.add_edge(main_c, main_o);
104    g.add_edge(main_o, app);
105    g.add_edge(languages_yml, languages_json);
106    g.add_edge(languages_json, liblangs);
107    g.add_edge(liblangs, app);
108
109    info!(
110        "Created graph with {} nodes and {} edges",
111        g.g.node_count(),
112        g.g.edge_count()
113    );
114
115    let success = g.make();
116    info!("Build {}", if success { "succeeded" } else { "failed" });
117
118    // Write mermaid graph to file
119    let mermaid_path = srcdir.join("project_expand/graph.mermaid");
120    let mermaid = g.to_mermaid();
121    fs::write(&mermaid_path, &mermaid).expect("Failed to write graph.mermaid");
122    info!("Wrote mermaid graph to {}", mermaid_path.display());
123}
More examples
Hide additional examples
examples/project_C/main.rs (line 84)
69fn main() {
70    env_logger::init();
71
72    let args: Args = argh::from_env();
73
74    let srcdir = args.src;
75    let sandbox = args.sandbox;
76
77    // ANCHOR: instanciate
78    let mut g = G::new(srcdir, sandbox);
79    // ANCHOR_END: instanciate
80
81    // ANCHOR: add_nodes
82    let main_c = g.add_root_node(CFile::new("project_C/main.c")).unwrap();
83    let main_o = g
84        .add_node(OFile::new("project_C/main.o", vec![], vec![]))
85        .unwrap();
86    let add_c = g.add_root_node(CFile::new("project_C/add.c")).unwrap();
87    let add_o = g
88        .add_node(OFile::new(
89            "project_C/add.o",
90            vec![],
91            vec!["-DYYY_defined".to_string()],
92        ))
93        .unwrap();
94    let _add_h = g.add_root_node(HFile::new("project_C/add.h")).unwrap();
95    let _wrapper_h = g.add_root_node(HFile::new("project_C/wrapper.h")).unwrap();
96    let project_a = g.add_node(AFile::new("project_C/libproject.a")).unwrap();
97    let app = g.add_node(XFile::new("project_C/app")).unwrap();
98    // ANCHOR_END: add_nodes
99
100    // ANCHOR: add_edges
101    g.add_edge(main_c, main_o);
102    g.add_edge(main_o, app);
103    g.add_edge(add_c, add_o);
104    g.add_edge(add_o, project_a);
105    g.add_edge(project_a, app);
106    // ANCHOR_END: add_edges
107
108    info!(
109        "Created graph with {} nodes and {} edges",
110        g.g.node_count(),
111        g.g.edge_count()
112    );
113
114    // ANCHOR: make
115    // make() will:
116    // 1. Mount root nodes (copy source files to sandbox)
117    // 2. Scan for dependencies (adds edges for #include directives)
118    // 3. Build all nodes in dependency order (parallel where possible)
119    let success = g.make();
120    info!("Build {}", if success { "succeeded" } else { "failed" });
121    // ANCHOR_END: make
122}
examples/project_expand/../../tests/common/json_desc.rs (line 122)
79    fn expand(&self, sandbox: &Path, _predecessors: &[&(dyn GNode + Send + Sync)]) -> ExpandResult {
80        let input_path = sandbox.join(&self.name);
81        let json_content = fs::read_to_string(&input_path)
82            .map_err(|e| ExpandError::ReadError(input_path.clone(), e))?;
83
84        let languages: Vec<Language> = serde_json::from_str(&json_content).map_err(|e| {
85            ExpandError::ParseError(format!(
86                "Failed to parse JSON {}: {}",
87                input_path.display(),
88                e
89            ))
90        })?;
91
92        let generated_dir = sandbox.join("project_expand/generated");
93        fs::create_dir_all(&generated_dir).ok();
94
95        let mut nodes: Vec<Box<dyn GNode + Send + Sync>> = Vec::new();
96        let mut edges: Vec<Edge> = Vec::new();
97
98        let lib_path = "project_expand/generated/liblangs.a";
99
100        for lang in &languages {
101            // Generate C file
102            let c_path = format!("project_expand/generated/{}.c", lang.language);
103            let c_content = format!(
104                "const char* helloworld_{}=\"{}\" ;\nconst char* get_{}() {{ return helloworld_{} ; }}\n",
105                lang.language, lang.helloworld, lang.language, lang.language
106            );
107            let c_full_path = sandbox.join(&c_path);
108            fs::write(&c_full_path, &c_content)
109                .map_err(|e| ExpandError::WriteError(c_full_path, e))?;
110            nodes.push(Box::new(CFile::new(&c_path)));
111
112            // Generate H file
113            let h_path = format!("project_expand/generated/{}.h", lang.language);
114            let h_content = format!("const char* get_{}() ;\n", lang.language);
115            let h_full_path = sandbox.join(&h_path);
116            fs::write(&h_full_path, &h_content)
117                .map_err(|e| ExpandError::WriteError(h_full_path, e))?;
118            nodes.push(Box::new(HFile::new(&h_path)));
119
120            // Create OFile for this language
121            let o_path = format!("project_expand/generated/{}.o", lang.language);
122            nodes.push(Box::new(OFile::new(&o_path, vec![], vec![])));
123
124            // Add edges from JsonDesc to CFile and HFile (so they are not treated as root nodes)
125            edges.push(Edge {
126                nfrom: Box::new(JsonDesc::new(&self.name)),
127                nto: Box::new(CFile::new(&c_path)),
128            });
129            edges.push(Edge {
130                nfrom: Box::new(JsonDesc::new(&self.name)),
131                nto: Box::new(HFile::new(&h_path)),
132            });
133
134            // Add edges: CFile -> OFile -> AFile
135            edges.push(Edge {
136                nfrom: Box::new(CFile::new(&c_path)),
137                nto: Box::new(OFile::new(&o_path, vec![], vec![])),
138            });
139            edges.push(Edge {
140                nfrom: Box::new(OFile::new(&o_path, vec![], vec![])),
141                nto: Box::new(AFile::new(lib_path)),
142            });
143        }
144
145        // Generate languages.h with array of function pointers
146        let languages_h_path = PathBuf::from("project_expand/generated/languages.h");
147        let mut h_content = String::new();
148        h_content.push_str("#ifndef LANGUAGES_H\n");
149        h_content.push_str("#define LANGUAGES_H\n\n");
150
151        for lang in &languages {
152            h_content.push_str(&format!(
153                "#include \"project_expand/generated/{}.h\"\n",
154                lang.language
155            ));
156        }
157        h_content.push_str("\n");
158
159        h_content.push_str(&format!("#define N_languages {}\n\n", languages.len()));
160
161        h_content.push_str("typedef const char* (*get_language_fn)() ;\n\n");
162        h_content.push_str("get_language_fn languages[] = {\n");
163        for lang in &languages {
164            h_content.push_str(&format!("    get_{},\n", lang.language));
165        }
166        h_content.push_str("} ;\n\n");
167
168        h_content.push_str("#endif\n");
169
170        let languages_h_full_path = sandbox.join(&languages_h_path);
171        fs::write(&languages_h_full_path, &h_content)
172            .map_err(|e| ExpandError::WriteError(languages_h_full_path, e))?;
173        nodes.push(Box::new(HFile::new(&languages_h_path.to_string_lossy())));
174
175        // Add edge from JsonDesc to languages.h
176        edges.push(Edge {
177            nfrom: Box::new(JsonDesc::new(&self.name)),
178            nto: Box::new(HFile::new(&languages_h_path.to_string_lossy())),
179        });
180
181        Ok((nodes, edges))
182    }

Trait Implementations§

Source§

impl GNode for OFile

Source§

fn build( &self, sandbox: &Path, predecessors: &[&(dyn GNode + Send + Sync)], ) -> bool

Source§

fn scan( &self, sandbox: &Path, predecessors: &[&(dyn GNode + Send + Sync)], ) -> (bool, Vec<PathBuf>)

Source§

fn tag(&self) -> String

Source§

fn pathbuf(&self) -> PathBuf

Source§

fn expand( &self, _sandbox: &Path, _predecessors: &[&(dyn GNode + Send + Sync)], ) -> ExpandResult

Auto Trait Implementations§

§

impl Freeze for OFile

§

impl RefUnwindSafe for OFile

§

impl Send for OFile

§

impl Sync for OFile

§

impl Unpin for OFile

§

impl UnsafeUnpin for OFile

§

impl UnwindSafe for OFile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.