Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] preprocessor PoC #198

Closed
wants to merge 10 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up
klkvr committed Sep 13, 2024
commit 15ce120c2e17aa384a43af79a202a36ac78a0c6f
13 changes: 3 additions & 10 deletions crates/compilers/src/preprocessor.rs
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ impl ItemLocation {
}
}

/// Checks if the given path is a test/script file.
fn is_test_or_script<L>(path: &Path, paths: &ProjectPathsConfig<L>) -> bool {
let test_dir = paths.tests.strip_prefix(&paths.root).unwrap_or(&paths.root);
let script_dir = paths.scripts.strip_prefix(&paths.root).unwrap_or(&paths.root);
@@ -318,14 +319,6 @@ impl BytecodeDependencyOptimizer<'_> {
BytecodeDependencyOptimizer { asts, paths, sources }
}

/// Returns true if the file is not a test or script file.
fn is_src_file(&self, file: &Path) -> bool {
let tests = self.paths.tests.strip_prefix(&self.paths.root).unwrap_or(&self.paths.root);
let scripts = self.paths.scripts.strip_prefix(&self.paths.root).unwrap_or(&self.paths.root);

!file.starts_with(tests) && !file.starts_with(scripts)
}

fn process(self) -> Result<()> {
let mut updates = Updates::default();

@@ -348,7 +341,7 @@ impl BytecodeDependencyOptimizer<'_> {
for (path, ast) in &self.asts {
let src = self.sources.get(path).unwrap().content.as_str();

if !self.is_src_file(path) {
if is_test_or_script(path, &self.paths) {
continue;
}

@@ -412,7 +405,7 @@ impl BytecodeDependencyOptimizer<'_> {
updates: &mut Updates,
) -> Result<()> {
for (path, ast) in &self.asts {
if self.is_src_file(path) {
if !is_test_or_script(path, &self.paths) {
continue;
}
let src = self.sources.get(path).unwrap().content.as_str();