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

refactor: move compiler args from runner to compiler #121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AndreCostaaa
Copy link
Contributor

@AndreCostaaa AndreCostaaa commented Sep 26, 2024

This PR refactors existing compiler code so we can easily add new compiler types

Comment on lines +93 to +98
String::from(
get_absolute_path(&PathBuf::from("main.c"))
.unwrap()
.to_str()
.unwrap(),
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to refactor these pattern here and below (9 times) to a single line ? Maybe by creating a function get_absolute_path_string("main.c") or another name, just for testing.

output_path: &std::path::PathBuf,
extensions: &[&str],
) -> Vec<String> {
let path = output_path.to_str().unwrap_or("");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe unwrap_or_default would be nicer IMO ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid creating yet another path variable that is not clear which kind of path, I would prefer to inline this in the String::from(). What do you think ?

@@ -34,7 +52,7 @@ impl Compiler {
.iter()
.filter_map(|file| {
if Compiler::has_valid_extension(file, allowed_extensions) {
return get_full_path(file).ok();
return get_absolute_path(file).ok();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to see why we need to check the path furthermore ? Why does returning Compiler::has_valid_extension(...) is not enough ?

dunce::canonicalize(path)
}
/// Gets the absolute path of path without checking if the path actually exists
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to avoid useless syscalls

pub fn args(&self, files: &Vec<std::path::PathBuf>) -> Vec<String> {
pub fn args(
&self,
files: &Vec<std::path::PathBuf>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we agree that these paths must be like introduction/hello-world/main.c (relative to course folder), because taking the absolute path based on current folder (project folder) would not point to real files otherwise (if we took just main.c, the path would be invalid) ?

Maybe adding a note about this would help future dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: Move compiler specific code out of the compile_runner and to the compiler
2 participants