flowey/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![expect(missing_docs)]
5#![forbid(unsafe_code)]
6
7//! The user-facing flowey API.
8//!
9//! Relying on `flowey_core` directly is not advised, as many APIs exposed at
10//! that level are only supposed to be used by flowey _infrastructure_ (e.g: in
11//! `flowey_cli`).
12
13pub use flowey_core::shell_cmd;
14
15/// Shell abstractions for flowey command execution.
16pub mod shell {
17 pub use flowey_core::shell::*;
18}
19
20/// Types and traits for implementing flowey nodes.
21pub mod node {
22 pub mod prelude {
23 // include all user-facing types in the prelude
24 pub use flowey_core::match_arch;
25 pub use flowey_core::node::user_facing::*;
26
27 // ...in addition, export various types/traits that node impls are
28 // almost certainly going to require
29 pub use anyhow;
30 pub use anyhow::Context;
31 pub use fs_err;
32 pub use log;
33 pub use serde::Deserialize;
34 pub use serde::Serialize;
35 pub use std::path::Path;
36 pub use std::path::PathBuf;
37
38 /// Extension trait to streamline working with [`Path`] in flowey.
39 pub trait FloweyPathExt {
40 /// Alias for [`std::path::absolute`]
41 fn absolute(&self) -> std::io::Result<PathBuf>;
42
43 /// Helper to make files executable on unix-like platforms
44 fn make_executable(&self) -> std::io::Result<()>;
45
46 /// Helper to check if a file is executable on unix-like platforms
47 fn is_executable(&self) -> std::io::Result<bool>;
48 }
49
50 impl<T> FloweyPathExt for T
51 where
52 T: AsRef<Path>,
53 {
54 fn absolute(&self) -> std::io::Result<PathBuf> {
55 std::path::absolute(self)
56 }
57
58 fn make_executable(&self) -> std::io::Result<()> {
59 #[cfg(unix)]
60 {
61 use std::os::unix::fs::PermissionsExt;
62 let path = self.as_ref();
63 let old_mode = path.metadata()?.permissions().mode();
64 fs_err::set_permissions(
65 path,
66 std::fs::Permissions::from_mode(old_mode | 0o111),
67 )?;
68 }
69 Ok(())
70 }
71
72 fn is_executable(&self) -> std::io::Result<bool> {
73 #[cfg(unix)]
74 {
75 use std::os::unix::fs::PermissionsExt;
76 let path = self.as_ref();
77 let mode = path.metadata()?.permissions().mode();
78 Ok(mode & 0o111 != 0)
79 }
80
81 // TODO: Implement for windows. Tracked by https://github.com/microsoft/openvmm/issues/2622
82 #[cfg(not(unix))]
83 {
84 Ok(true)
85 }
86 }
87 }
88 }
89}
90
91/// Types and traits for implementing flowey pipelines.
92pub mod pipeline {
93 pub mod prelude {
94 pub use flowey_core::pipeline::user_facing::*;
95 }
96}
97
98/// Types and traits for implementing flowey patch functions.
99pub mod patch {
100 pub use flowey_core::patch::*;
101 pub use flowey_core::register_patch;
102}
103
104/// Utility functions.
105pub mod util {
106 pub use flowey_core::util::*;
107}