Skip to content

Commit 343cc0c

Browse files
author
Roland Peelen
committed
♻️ - Move fn to clean / remove trim()
1 parent 6fd39ad commit 343cc0c

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

src/build.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,6 @@ use std::path::{Path, PathBuf};
1616
use std::process::Command;
1717
use std::time::Instant;
1818

19-
pub fn get_res_path_from_ast(ast_file: &str) -> Option<String> {
20-
if let Ok(lines) = helpers::read_lines(ast_file.to_string()) {
21-
// we skip the first line with is some null characters
22-
// the following lines in the AST are the dependency modules
23-
// we stop when we hit a line that starts with a "/", this is the path of the file.
24-
// this is the point where the dependencies end and the actual AST starts
25-
for line in lines.skip(1) {
26-
match line {
27-
Ok(line) => {
28-
let line = line.trim().to_string();
29-
if line.starts_with('/') {
30-
return Some(line);
31-
}
32-
}
33-
Err(_) => (),
34-
}
35-
}
36-
}
37-
return None;
38-
}
39-
4019
pub fn get_interface<'a>(module: &'a Module) -> &'a Option<Interface> {
4120
match &module.source_type {
4221
SourceType::SourceFile(source_file) => &source_file.interface,
@@ -514,12 +493,7 @@ pub fn parse_packages(
514493
.map(|path| helpers::file_path_to_module_name(&path, &None))
515494
.collect::<AHashSet<String>>();
516495

517-
let mlmap = gen_mlmap(
518-
&package,
519-
namespace,
520-
depending_modules,
521-
project_root,
522-
);
496+
let mlmap = gen_mlmap(&package, namespace, depending_modules, project_root);
523497

524498
// mlmap will be compiled in the AST generation step
525499
// compile_mlmap(&package, namespace, &project_root);

src/clean.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ use rayon::prelude::*;
77
use std::fs;
88
use std::time::SystemTime;
99

10+
pub fn get_res_path_from_ast(ast_file: &str) -> Option<String> {
11+
if let Ok(lines) = helpers::read_lines(ast_file.to_string()) {
12+
// we skip the first line with is some null characters
13+
// the following lines in the AST are the dependency modules
14+
// we stop when we hit a line that starts with a "/", this is the path of the file.
15+
// this is the point where the dependencies end and the actual AST starts
16+
for line in lines.skip(1) {
17+
match line {
18+
Ok(line) if line.trim_start().starts_with('/') => return Some(line),
19+
_ => (),
20+
}
21+
}
22+
}
23+
return None;
24+
}
25+
26+
1027
fn remove_asts(source_file: &str, package_name: &str, namespace: &Option<String>, root_path: &str) {
1128
let _ = std::fs::remove_file(helpers::get_compiler_asset(
1229
source_file,
@@ -104,7 +121,7 @@ pub fn cleanup_previous_build(
104121
);
105122

106123
let ast_file_path = path.to_str().unwrap().to_owned();
107-
let res_file_path = build::get_res_path_from_ast(&ast_file_path);
124+
let res_file_path = get_res_path_from_ast(&ast_file_path);
108125
match res_file_path {
109126
Some(res_file_path) => {
110127
let _ = ast_modules.insert(

0 commit comments

Comments
 (0)