From 0f9f2658dc91132a5fd885a75f04286f1e498514 Mon Sep 17 00:00:00 2001 From: Tom Gowan Date: Thu, 9 May 2019 17:46:00 +1000 Subject: [PATCH] relative include --- src/compiler.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 9ab07fc..8b97095 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -3,7 +3,7 @@ use shaderc::{IncludeType, ResolvedInclude}; use shaderc::{ShaderKind, CompileOptions}; use std::fs::File; use std::io::Read; -use std::path::Path; +use std::path::{Path, PathBuf}; pub fn compile(path: T, shader_kind: ShaderKind) -> Result, CompileError> where @@ -34,15 +34,20 @@ where fn get_include( path: &str, include_type: IncludeType, - _folder_path: &str, - _depth: usize, + folder_path: &str, + depth: usize, ) -> Result { match include_type { IncludeType::Relative => { let p = Path::new(path); + let mut folder = PathBuf::from(folder_path); + folder.pop(); + folder.push(p); + let p = folder; if !p.is_file() { return Err("Include doesn't point to file".to_string()); } + let resolved_name = p .to_str() .ok_or("Path has invalid characters".to_string())?