From 98188391a20b6472d9008485461b6429c8e37bd9 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 4 May 2022 12:06:04 +0200 Subject: [PATCH] rusticl/program: parse quoted paths in args Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- src/gallium/frontends/rusticl/core/program.rs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index d687dc2a8f7..46f7e3158fe 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -80,9 +80,34 @@ fn prepare_options(options: &str, dev: &Device) -> Vec { } options.push_str(" -D__OPENCL_VERSION__="); options.push_str(dev.cl_version.clc_str()); - options - .split_whitespace() - .map(|a| match a { + + let mut res = Vec::new(); + + // we seperate on a ' ' unless we hit a " + let mut sep = ' '; + let mut old = 0; + for (i, c) in options.char_indices() { + if c == '"' { + if sep == ' ' { + sep = '"'; + } else { + sep = ' '; + } + } + + if c == '"' || c == sep { + // beware of double seps + if old != i { + res.push(&options[old..i]); + } + old = i + c.len_utf8(); + } + } + // add end of the string + res.push(&options[old..]); + + res.iter() + .map(|&a| match a { "-cl-denorms-are-zero" => "-fdenormal-fp-math=positive-zero", _ => a, })