leo_package/lib.rs
1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17#![forbid(unsafe_code)]
18#![doc = include_str!("../README.md")]
19
20pub mod build;
21pub mod imports;
22pub mod inputs;
23pub mod outputs;
24pub mod package;
25pub mod root;
26pub mod source;
27
28use leo_errors::{PackageError, Result};
29
30use std::{fs, fs::ReadDir, path::PathBuf};
31
32pub static LEO_FILE_EXTENSION: &str = ".leo";
33
34pub static TEST_PRIVATE_KEY: &str = "APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH";
35
36pub(crate) fn parse_file_paths(directory: ReadDir, file_paths: &mut Vec<PathBuf>) -> Result<()> {
37 for file_entry in directory {
38 let file_entry = file_entry.map_err(PackageError::failed_to_get_leo_file_entry)?;
39 let file_path = file_entry.path();
40
41 // Verify that the entry is structured as a valid file or directory
42 if file_path.is_dir() {
43 let directory =
44 fs::read_dir(&file_path).map_err(|err| PackageError::failed_to_read_file(file_path.display(), err))?;
45
46 parse_file_paths(directory, file_paths)?;
47 continue;
48 } else {
49 // If the extension doesn't match, we simply skip this file
50 // If there's no extension, we also skip this file
51 if let Some(file_extension) = file_path.extension() {
52 if file_extension == LEO_FILE_EXTENSION.trim_start_matches('.') {
53 file_paths.push(file_path);
54 }
55 }
56 }
57 }
58
59 Ok(())
60}