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

Validate if paths in include_path exist #1215

Open
volsa opened this issue Apr 26, 2024 · 0 comments
Open

Validate if paths in include_path exist #1215

volsa opened this issue Apr 26, 2024 · 0 comments
Labels
good first issue Good for newcomers validation candidate for syntactic or semantic validation

Comments

@volsa
Copy link
Member

volsa commented Apr 26, 2024

Describe the bug
Given the following configuration file

{
	"name" : "MyProject",
	   "files" : ["../src/**/*.st"],
	   "compile_type" : "Shared",
	   "output" : "prog.so",
	   "libraries" : [
	       {
	           "name" : "iec61131std",
	           "path" : "<path to iec61131std/lib>",
	           "package" : "Copy",
	           "include_path" : [
	             "<path to iec61131std/include/*.st>"
	           ]
	       }
	   ]
}

If the entries in include_path are invalid (i.e. the path doesn't exist), plc build config/plc.json will fail building if functions are used from the library. While this is expected, an additional error message telling the user "path xyz is invalid" would be great and reduce the time investigating the issue for them.

Additional context
Something along if !input.exists() { /* error */ } in resolve_file_paths should fix it, though I'm not sure if the exists() call will fail for relative paths.

fn resolve_file_paths(location: Option<&Path>, inputs: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
let mut sources = Vec::new();
//Ensure we are working with a directory
let location = location.and_then(|it| if it.is_file() { it.parent() } else { Some(it) });
for input in &inputs {
let input = location.map(|it| it.join(input)).unwrap_or(input.to_path_buf());
let path = &input.to_string_lossy();
let paths = glob(path).context(format!("Failed to read glob pattern {path}"))?;
for p in paths {
let path = p.context("Illegal Path")?;
sources.push(path);
}
}
Ok(sources)
}

@volsa volsa added validation candidate for syntactic or semantic validation good first issue Good for newcomers labels Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers validation candidate for syntactic or semantic validation
Projects
None yet
Development

No branches or pull requests

1 participant