From 94ef369960a8e1868616d331c00deb8af12f713f Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 21:33:22 +0100 Subject: [PATCH 01/29] entry point detection --- CHANGELOG.md | 3 +++ src/interpreter.rs | 12 ++++++++++++ src/interpreters/C_original.rs | 4 +++- src/interpreters/Cpp_original.rs | 5 ++++- src/interpreters/Go_original.rs | 14 +++++++++++++- src/interpreters/Java_original.rs | 17 ++++++++++------- src/interpreters/Rust_original.rs | 5 ++++- src/interpreters/Scala_original.rs | 7 +++++-- 8 files changed, 54 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d45e0e3..3f50c1bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.1.2 +- auto dectection of entry point for many languages + ## v1.1.1 - Fix terminal display issues - Configurable display options diff --git a/src/interpreter.rs b/src/interpreter.rs index 01a68468..d007521e 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -178,6 +178,7 @@ pub trait InterpreterUtils { fn set_pid(&self, pid: u32); fn get_pid(&self) -> Option; fn get_interpreter_option(data: &DataHolder, option: &str) -> Option; + fn contains_main(entry: &str, snippet: &str, comment: &str) -> bool; } impl InterpreterUtils for T { @@ -291,6 +292,17 @@ impl InterpreterUtils for T { None } + + fn contains_main(entry: &str, snippet: &str, comment: &str) -> bool { + let compact_main: String = entry.split_whitespace().collect(); + let compact_snippet: String = snippet + .lines() + .filter(|l| !l.trim().starts_with(comment)) + .collect::() + .split_whitespace() + .collect(); + return compact_snippet.contains(&compact_main); + } } pub trait ReplLikeInterpreter { diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 5d0d5783..09a545db 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -134,7 +134,9 @@ impl Interpreter for C_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { self.fetch_imports()?; - self.code = String::from("int main() {\n") + &self.code + "\nreturn 0;}"; + if !C_original::contains_main(&"int main (", &self.code, &"//") { + self.code = String::from("int main() {\n") + &self.code + "\nreturn 0;}"; + } if !self.imports.iter().any(|s| s.contains("")) { self.code = String::from("#include \n") + &self.code; } diff --git a/src/interpreters/Cpp_original.rs b/src/interpreters/Cpp_original.rs index f312b03b..7abc6c50 100644 --- a/src/interpreters/Cpp_original.rs +++ b/src/interpreters/Cpp_original.rs @@ -138,7 +138,10 @@ impl Interpreter for Cpp_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { self.fetch_imports()?; - self.code = String::from("int main() {\n") + &self.code + "\nreturn 0;}"; + + if !Cpp_original::contains_main(&"int main (", &self.code, &"//") { + self.code = String::from("int main() {\n") + &self.code + "\nreturn 0;}"; + } if !self.imports.iter().any(|s| s.contains("")) { self.code = String::from("#include \n") + &self.code; } diff --git a/src/interpreters/Go_original.rs b/src/interpreters/Go_original.rs index f190d600..d7444242 100644 --- a/src/interpreters/Go_original.rs +++ b/src/interpreters/Go_original.rs @@ -110,7 +110,19 @@ impl Interpreter for Go_original { } fn add_boilerplate(&mut self) -> Result<(), SniprunError> { - self.code = String::from("package main \nimport \"fmt\"\nfunc main() {") + &self.code + "}"; + + if !Go_original::contains_main(&"func main (", &self.code, &"//") { + self.code = String::from("func main() {") + &self.code + "}"; + } + + if !Go_original::contains_main(&"import \"fmt\"", &self.code, &"//") { + self.code = String::from("package \"fmt\"\n") + &self.code; + } + + if !Go_original::contains_main(&"package main", &self.code, &"//") { + self.code = String::from("package main\n") + &self.code; + } + Ok(()) } diff --git a/src/interpreters/Java_original.rs b/src/interpreters/Java_original.rs index 92c0877a..060ed6f8 100644 --- a/src/interpreters/Java_original.rs +++ b/src/interpreters/Java_original.rs @@ -82,13 +82,16 @@ impl Interpreter for Java_original { } fn add_boilerplate(&mut self) -> Result<(), SniprunError> { - self.code = String::from( - "public class Main { - public static void main(String[] args) { - ", - ) + &self.code - + "} - }"; + + if !Java_original::contains_main(&"public static void main(", &self.code, &"//") { + self.code = String::from( + "public class Main { + public static void main(String[] args) { + ", + ) + &self.code + + "} + }"; + } Ok(()) } diff --git a/src/interpreters/Rust_original.rs b/src/interpreters/Rust_original.rs index b32f7643..65411bea 100644 --- a/src/interpreters/Rust_original.rs +++ b/src/interpreters/Rust_original.rs @@ -109,7 +109,10 @@ impl Interpreter for Rust_original { } fn add_boilerplate(&mut self) -> Result<(), SniprunError> { - self.code = String::from("fn main() {") + &self.code + "}"; + + if !Rust_original::contains_main(&"fn main(", &self.code, &"//") { + self.code = String::from("fn main() {") + &self.code + "}"; + } Ok(()) } diff --git a/src/interpreters/Scala_original.rs b/src/interpreters/Scala_original.rs index 9de2721e..3ba91fcf 100644 --- a/src/interpreters/Scala_original.rs +++ b/src/interpreters/Scala_original.rs @@ -96,8 +96,11 @@ impl Interpreter for Scala_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { // an example following Rust's syntax - self.code = - String::from("object Main {\ndef main(arg: Array[String]) = {") + &self.code + "}\n}"; + + if !Scala_original::contains_main(&"int main (", &self.code, &"//") { + self.code = + String::from("object Main {\ndef main(arg: Array[String]) = {") + &self.code + "}\n}"; + } Ok(()) } From 8992da09d30bac6de85e0ce8ddc19f6567487dc0 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:08:44 +0100 Subject: [PATCH 02/29] remove tree-sitter in health check --- lua/sniprun.lua | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lua/sniprun.lua b/lua/sniprun.lua index b663ce41..aa39e0b7 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -312,16 +312,6 @@ function M.health() local health_error = vim.fn['health#report_error'] local health_warn = vim.fn['health#report_warn'] health_start('Installation') - if vim.fn.executable('tree-sitter') == 0 then - health_warn('`tree-sitter` executable not found (): File support and higher may not work properly') - else - local handle = io.popen('tree-sitter -V') - local result = handle:read("*a") - handle:close() - local version = vim.split(result,'\n')[1]:match('[^tree%psitter].*') - health_ok('`tree-sitter` found '..version..' , sniprun will try to make good use of that') - end - if vim.fn.executable('cargo') == 0 then health_warn("Rust toolchain not available", {"[optionnal] Install the rust toolchain https://www.rust-lang.org/tools/install"}) else health_ok("Rust toolchain found") end From 1582c483cd3e29d780d76484e4ae83bfe932ec3b Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:22:28 +0100 Subject: [PATCH 03/29] unblock plot in python3_fifo --- src/interpreters/Python3_fifo.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 04ba4251..4ccd1bf1 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -171,6 +171,17 @@ impl Python3_fifo { false } + /// needs imports to have been fetched already + fn unblock_plot(&mut self) { + + //it's not really pretty but should work most of the time + if self.imports.split_whitespace().collect::().contains("pyplotasplt") { + self.code = self.code.replace("plt.show()", "plt.show(block=False)") + } + self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False)") + } + + fn fetch_config(&mut self) { let default_interpreter = String::from("python3"); self.interpreter = default_interpreter; @@ -305,6 +316,8 @@ impl Interpreter for Python3_fifo { self.imports = String::from("\ntry:\n") + &indented_imports + "\nexcept:\n\tpass\n"; } + self.unblock_plot(); + let mut source_venv = String::new(); if let Some(venv_path) = &self.venv { info!("loading venv: {}", venv_path); From b7964d788fb6c3a9db13963b100592df6149b74e Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:34:04 +0100 Subject: [PATCH 04/29] pause after nonblocking plot --- src/interpreters/Python3_fifo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 4ccd1bf1..f4923199 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -176,9 +176,9 @@ impl Python3_fifo { //it's not really pretty but should work most of the time if self.imports.split_whitespace().collect::().contains("pyplotasplt") { - self.code = self.code.replace("plt.show()", "plt.show(block=False)") + self.code = self.code.replace("plt.show()", "plt.show(block=False);plt.pause(0.001)") } - self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False)") + self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False);plt.plause(0.001)") } From 2dcf2278705e17516df58f46f22a0fd2cd65a4cb Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:37:10 +0100 Subject: [PATCH 05/29] fix missing import in plot detection --- src/interpreters/Python3_fifo.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index f4923199..c4362202 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -173,9 +173,10 @@ impl Python3_fifo { /// needs imports to have been fetched already fn unblock_plot(&mut self) { + let all_imports = self.imports.clone() + &self.read_previous_code(); //it's not really pretty but should work most of the time - if self.imports.split_whitespace().collect::().contains("pyplotasplt") { + if all_imports.split_whitespace().collect::().contains("pyplotasplt") { self.code = self.code.replace("plt.show()", "plt.show(block=False);plt.pause(0.001)") } self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False);plt.plause(0.001)") From d00ca9eeaea0366071b5022b7a25caa116edbe05 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:42:31 +0100 Subject: [PATCH 06/29] pause instead of show --- src/interpreters/Python3_fifo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index c4362202..62282d68 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -177,9 +177,9 @@ impl Python3_fifo { //it's not really pretty but should work most of the time if all_imports.split_whitespace().collect::().contains("pyplotasplt") { - self.code = self.code.replace("plt.show()", "plt.show(block=False);plt.pause(0.001)") + self.code = self.code.replace("plt.show()", "plt.pause(0.001)") } - self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False);plt.plause(0.001)") + self.code = self.code.replace("pyplot.show()", "plt.plause(0.001)") } From ab0b873b71e4172ed79ae5c41af2c85d06784834 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 4 Jan 2022 23:47:22 +0100 Subject: [PATCH 07/29] more syntax possiblilites for pyton3fifo plot --- src/interpreters/Python3_fifo.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 62282d68..e51b9e40 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -177,9 +177,10 @@ impl Python3_fifo { //it's not really pretty but should work most of the time if all_imports.split_whitespace().collect::().contains("pyplotasplt") { - self.code = self.code.replace("plt.show()", "plt.pause(0.001)") + self.code = self.code.replace("plt.show()", "plt.pause(0.001);plt.pause(0.001)") } - self.code = self.code.replace("pyplot.show()", "plt.plause(0.001)") + self.code = self.code.replace("matplotlib.pyplot.show()", "matplotlib.pyplot.plause(0.001);matplotlib.pyplot.pause"); + self.code = self.code.replace("pyplot.show()", "pyplot.plause(0.001);pyplot.pause(0.001)"); } From 5c7b618d76bc6658c270534631e34c8e4ed9a6a1 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:02:50 +0100 Subject: [PATCH 08/29] pyplot with ion() --- src/interpreters/Python3_fifo.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index e51b9e40..52f3c29c 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -175,12 +175,16 @@ impl Python3_fifo { fn unblock_plot(&mut self) { let all_imports = self.imports.clone() + &self.read_previous_code(); + if self.imports.contains("pyplot") { + self.imports = self.imports.clone() + "\nion()\n"; + } + //it's not really pretty but should work most of the time if all_imports.split_whitespace().collect::().contains("pyplotasplt") { - self.code = self.code.replace("plt.show()", "plt.pause(0.001);plt.pause(0.001)") + self.code = self.code.replace("plt.show()", "plt.show(block=False)") } - self.code = self.code.replace("matplotlib.pyplot.show()", "matplotlib.pyplot.plause(0.001);matplotlib.pyplot.pause"); - self.code = self.code.replace("pyplot.show()", "pyplot.plause(0.001);pyplot.pause(0.001)"); + // self.code = self.code.replace("matplotlib.pyplot.show()", "matplotlib.pyplot.plause(0.001);matplotlib.pyplot.pause"); + self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False)"); } From 770debccfb1361560a8a8ed24b4687fcb08f6ebc Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:05:12 +0100 Subject: [PATCH 09/29] add missing import for ion --- src/interpreters/Python3_fifo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 52f3c29c..92998d76 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -176,7 +176,7 @@ impl Python3_fifo { let all_imports = self.imports.clone() + &self.read_previous_code(); if self.imports.contains("pyplot") { - self.imports = self.imports.clone() + "\nion()\n"; + self.imports = self.imports.clone() + "\nimport matplotlib.pyplot ; matplotlib.pyplot.ion()\n"; } //it's not really pretty but should work most of the time From 36b43e53fc7e4206543823353d787fc5a5890e75 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:11:01 +0100 Subject: [PATCH 10/29] unblock_plot before imports formatting --- src/interpreters/Python3_fifo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 92998d76..a689156c 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -313,6 +313,8 @@ impl Interpreter for Python3_fifo { Ok(()) } fn add_boilerplate(&mut self) -> Result<(), SniprunError> { + self.unblock_plot(); + if !self.imports.is_empty() { let mut indented_imports = String::new(); for import in self.imports.lines() { @@ -322,8 +324,6 @@ impl Interpreter for Python3_fifo { self.imports = String::from("\ntry:\n") + &indented_imports + "\nexcept:\n\tpass\n"; } - self.unblock_plot(); - let mut source_venv = String::new(); if let Some(venv_path) = &self.venv { info!("loading venv: {}", venv_path); From 3c5825b0d90ef98f2eb049a91467578a7589fcd9 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:20:11 +0100 Subject: [PATCH 11/29] run ion each time --- src/interpreters/Python3_fifo.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index a689156c..e62f5874 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -175,18 +175,19 @@ impl Python3_fifo { fn unblock_plot(&mut self) { let all_imports = self.imports.clone() + &self.read_previous_code(); - if self.imports.contains("pyplot") { - self.imports = self.imports.clone() + "\nimport matplotlib.pyplot ; matplotlib.pyplot.ion()\n"; - } - //it's not really pretty but should work most of the time - if all_imports.split_whitespace().collect::().contains("pyplotasplt") { + if all_imports + .split_whitespace() + .collect::() + .contains("pyplotasplt") + { self.code = self.code.replace("plt.show()", "plt.show(block=False)") } // self.code = self.code.replace("matplotlib.pyplot.show()", "matplotlib.pyplot.plause(0.001);matplotlib.pyplot.pause"); - self.code = self.code.replace("pyplot.show()", "pyplot.show(block=False)"); + self.code = self + .code + .replace("pyplot.show()", "pyplot.show(block=False)"); } - fn fetch_config(&mut self) { let default_interpreter = String::from("python3"); @@ -437,7 +438,14 @@ impl ReplLikeInterpreter for Python3_fifo { .filter(|l| !l.trim().is_empty()) .collect::>() .join("\n") - .replace("#\n#","\n"); + .replace("#\n#", "\n"); + + let mut run_ion = String::new(); + if self.read_previous_code().contains("pyplot") { + run_ion.push_str( + &"try:\n\timport matplotlib.pyplot ; matplotlib.pyplot.ion()\nexcept:\n\tpass\n\n", + ); + } let all_code = String::from("\n") + &self.code + "\n\n"; self.code = String::from("\nimport sys\n\n") From a91627b13236e9532e23c93667e886559134a54a Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:21:05 +0100 Subject: [PATCH 12/29] typo --- src/interpreters/Python3_fifo.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index e62f5874..4f8f5f23 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -449,6 +449,7 @@ impl ReplLikeInterpreter for Python3_fifo { let all_code = String::from("\n") + &self.code + "\n\n"; self.code = String::from("\nimport sys\n\n") + + &run_ion + &start_mark + &start_mark_err + &all_code From b4731b78f97477be3f3b3cf644d6f07cd3f0067d Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:41:34 +0100 Subject: [PATCH 13/29] run ioff each time too --- src/interpreters/Python3_fifo.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 4f8f5f23..d8b72e0f 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -441,10 +441,12 @@ impl ReplLikeInterpreter for Python3_fifo { .replace("#\n#", "\n"); let mut run_ion = String::new(); - if self.read_previous_code().contains("pyplot") { + let mut run_ioff = String::new(); + if self.imports.contains("pyplot") { run_ion.push_str( &"try:\n\timport matplotlib.pyplot ; matplotlib.pyplot.ion()\nexcept:\n\tpass\n\n", ); + run_ioff.push_str(&"\nmatplotlib.pyplot.ioff()\n"); } let all_code = String::from("\n") + &self.code + "\n\n"; @@ -454,7 +456,8 @@ impl ReplLikeInterpreter for Python3_fifo { + &start_mark_err + &all_code + &end_mark - + &end_mark_err; + + &end_mark_err + + &run_ioff; Ok(()) } From 77b187d750b738f214d814113d7cfe2f5ae40a9a Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 00:48:07 +0100 Subject: [PATCH 14/29] timeout in python3_fifo --- src/interpreters/Python3_fifo.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index d8b72e0f..88253323 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -32,10 +32,15 @@ impl Python3_fifo { let mut out_contents = String::new(); let mut err_contents = String::new(); + let start = std::time::Instant::now(); loop { let pause = std::time::Duration::from_millis(50); std::thread::sleep(pause); + if start.elapsed().as_secs() > 10 { + return Err(SniprunError::CustomError(String::from("python3_fifo: Timeout waiting on result"))); + } + //check for stderr first if let Ok(mut file) = std::fs::File::open(&err_path) { info!("errfile exists"); From b58dfc4e5842a7b6d3a304998aa05b8d63424e06 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 01:23:37 +0100 Subject: [PATCH 15/29] append end mark after a few seconds --- src/interpreters/Python3_fifo.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 88253323..8442193d 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -38,7 +38,13 @@ impl Python3_fifo { std::thread::sleep(pause); if start.elapsed().as_secs() > 10 { - return Err(SniprunError::CustomError(String::from("python3_fifo: Timeout waiting on result"))); + if let Ok(mut file) = std::fs::OpenOptions::new().write(true).append(true).open(&out_path) { + let _ = file.write_all(end_mark.as_bytes()); + } + + if let Ok(mut file) = std::fs::OpenOptions::new().write(true).append(true).open(&err_path) { + let _ =file.write_all(end_mark.as_bytes()); + } } //check for stderr first From 1b7a03464f769bccddec40de80750163a196a5a6 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 01:29:42 +0100 Subject: [PATCH 16/29] remove this awful idea --- src/interpreters/Python3_fifo.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 8442193d..3495da83 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -37,16 +37,6 @@ impl Python3_fifo { let pause = std::time::Duration::from_millis(50); std::thread::sleep(pause); - if start.elapsed().as_secs() > 10 { - if let Ok(mut file) = std::fs::OpenOptions::new().write(true).append(true).open(&out_path) { - let _ = file.write_all(end_mark.as_bytes()); - } - - if let Ok(mut file) = std::fs::OpenOptions::new().write(true).append(true).open(&err_path) { - let _ =file.write_all(end_mark.as_bytes()); - } - } - //check for stderr first if let Ok(mut file) = std::fs::File::open(&err_path) { info!("errfile exists"); From 720255ff7f01d9d1c11ee94e508760a2dbc9dcc0 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 10:44:45 +0100 Subject: [PATCH 17/29] 'sync' repl --- ressources/init_repl.sh | 0 ressources/sync_repl.sh | 11 +++++++++++ src/interpreters/Python3_fifo.rs | 11 +++++++++++ 3 files changed, 22 insertions(+) mode change 100755 => 100644 ressources/init_repl.sh create mode 100755 ressources/sync_repl.sh diff --git a/ressources/init_repl.sh b/ressources/init_repl.sh old mode 100755 new mode 100644 diff --git a/ressources/sync_repl.sh b/ressources/sync_repl.sh new file mode 100755 index 00000000..59f3b7d2 --- /dev/null +++ b/ressources/sync_repl.sh @@ -0,0 +1,11 @@ +#!/bin/bash +working_dir="$1/fifo_repl" +echo "sync requested" >> $working_dir/log + +pipe=pipe_in +out=out_file +err=err_file + +echo "" > $working_dir/$pipe + +echo "sync done" >> $working_dir/log diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 3495da83..6470469f 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -37,6 +37,17 @@ impl Python3_fifo { let pause = std::time::Duration::from_millis(50); std::thread::sleep(pause); + // Python3_fifo-specific things to workaround nonblocking plot issues + if start.elapsed().as_secs() > 5 { + let sync_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/sync_repl.sh"; + let res = Command::new(sync_repl_cmd).arg(self.cache_dir.clone()).output(); + info!( + "had to sync the repl because of timeout on awaiting result:\ + happens when a blocking command (plot, infinite loop) is run: {:?}", + res + ); + } + //check for stderr first if let Ok(mut file) = std::fs::File::open(&err_path) { info!("errfile exists"); From 47929026d3ea54a586ad851a951f78daae35cfb1 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 10:53:34 +0100 Subject: [PATCH 18/29] sync repl very often --- src/interpreters/Python3_fifo.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 6470469f..5e0a7f37 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -32,13 +32,12 @@ impl Python3_fifo { let mut out_contents = String::new(); let mut err_contents = String::new(); - let start = std::time::Instant::now(); loop { let pause = std::time::Duration::from_millis(50); std::thread::sleep(pause); // Python3_fifo-specific things to workaround nonblocking plot issues - if start.elapsed().as_secs() > 5 { + { let sync_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/sync_repl.sh"; let res = Command::new(sync_repl_cmd).arg(self.cache_dir.clone()).output(); info!( From 6a26920ab67e0309ec9fe551e07eda971ed75080 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:02:36 +0100 Subject: [PATCH 19/29] not spamming too much & quiet ion() --- src/interpreters/Python3_fifo.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 5e0a7f37..7224f9e4 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -32,12 +32,13 @@ impl Python3_fifo { let mut out_contents = String::new(); let mut err_contents = String::new(); + let start = std::time::Instant::now(); loop { let pause = std::time::Duration::from_millis(50); std::thread::sleep(pause); // Python3_fifo-specific things to workaround nonblocking plot issues - { + if start.elapsed().as_secs() > 2 { let sync_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/sync_repl.sh"; let res = Command::new(sync_repl_cmd).arg(self.cache_dir.clone()).output(); info!( @@ -455,9 +456,9 @@ impl ReplLikeInterpreter for Python3_fifo { let mut run_ioff = String::new(); if self.imports.contains("pyplot") { run_ion.push_str( - &"try:\n\timport matplotlib.pyplot ; matplotlib.pyplot.ion()\nexcept:\n\tpass\n\n", + &"try:\n\timport matplotlib.pyplot ;sniprun_ion_status_on = matplotlib.pyplot.ion()\nexcept:\n\tpass\n\n", ); - run_ioff.push_str(&"\nmatplotlib.pyplot.ioff()\n"); + run_ioff.push_str(&"\nsniprun_ion_status_off = matplotlib.pyplot.ioff()\n"); } let all_code = String::from("\n") + &self.code + "\n\n"; From 1e53150b69df392fe1b7318ebbdd5d9fd6b3c272 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:05:59 +0100 Subject: [PATCH 20/29] spam sync more often (200ms) --- src/interpreters/Python3_fifo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 7224f9e4..818d2e11 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -38,7 +38,7 @@ impl Python3_fifo { std::thread::sleep(pause); // Python3_fifo-specific things to workaround nonblocking plot issues - if start.elapsed().as_secs() > 2 { + if start.elapsed().as_millis() > 150 { let sync_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/sync_repl.sh"; let res = Command::new(sync_repl_cmd).arg(self.cache_dir.clone()).output(); info!( From c807363a81ad269c0c2d0683934ec51f67826f49 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:21:03 +0100 Subject: [PATCH 21/29] with build args --- src/interpreters/C_original.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 09a545db..d7fcf6ac 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -148,6 +148,29 @@ impl Interpreter for C_original { fn build(&mut self) -> Result<(), SniprunError> { info!("starting build"); //write code to file + + let mut build_args: Vec = vec![]; + if let Ok(cflags) = std::env::var("CFLAGS") { + build_args.push(String::from("-l")); + build_args.push(cflags); + } + + if let Ok(c_incl_path) = std::env::var("C_INCLUDE_PATH") { + build_args.push(String::from("-I")); + build_args.push(c_incl_path); + } + + if let Ok(cplus_incl_path) = std::env::var("CPLUS_INCLUDE_PATH") { + build_args.push(String::from("-I")); + build_args.push(cplus_incl_path); + } + + if let Ok(library_path) = std::env::var("LIBRARY_PATH") { + build_args.push(String::from("-L")); + build_args.push(library_path); + } + info!("build args are: {:?}", build_args); + let mut _file = File::create(&self.main_file_path).expect("Failed to create file for c-original"); write(&self.main_file_path, &self.code).expect("Unable to write to file for c-original"); @@ -155,6 +178,7 @@ impl Interpreter for C_original { .arg(&self.main_file_path) .arg("-o") .arg(&self.bin_path) + .args(&build_args) .output() .expect("Unable to start process"); From c9a15e954a818435c96c1de9c6ceacba612ee36c Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:26:11 +0100 Subject: [PATCH 22/29] fix cflags --- src/interpreters/C_original.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index d7fcf6ac..de1a3ecd 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -151,8 +151,7 @@ impl Interpreter for C_original { let mut build_args: Vec = vec![]; if let Ok(cflags) = std::env::var("CFLAGS") { - build_args.push(String::from("-l")); - build_args.push(cflags); + build_args.extend(cflags.split_whitespace().map(|s| s.to_owned())); } if let Ok(c_incl_path) = std::env::var("C_INCLUDE_PATH") { From 84f426ff34e1599b7a8c3732bb3a7496b8fa6a60 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:39:52 +0100 Subject: [PATCH 23/29] doc & all include if C_INCLUDE_PATH is set --- doc/C_original.md | 18 +++++++++++++++++- src/interpreters/C_original.rs | 29 ++++++++++++++++++----------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/doc/C_original.md b/doc/C_original.md index b79e9b97..bd9de7ee 100644 --- a/doc/C_original.md +++ b/doc/C_original.md @@ -12,4 +12,20 @@ require'sniprun'.setup({ }) ``` -This interpeter will also only import (all) #include \<...> but not any #include "..." +If you run with GCC, Sniprun will be able to run function + code in the same snippet, or functions + main() function regardlessly,but only the latter is supported by clang. + +This interpreter will also only import (all) #include \<...> but not any #include "..." (systems-wide include only, not the headers from your project, unless the environment variable `$C_INCLUDE_PATH` or `$CPLUS_INCLUDE_PATH` have been set) + + +the C\_original interpreter will also make use of the following environment variables: + +- `$C_INCLUDE_PATH` +- `$C_PLUS_INCLUDE_PATH` +- `$LIBRARY_PATH` +- `$CFLAGS` + + +and will add them to the build options it uses. Please specify _absolute path_, and not relative ones! + + +Using a tool such as [direnv](https://direnv.net/) may be really useful to set up those variables when you `cd` into your project' directory. diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index de1a3ecd..c48cbecd 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -12,7 +12,7 @@ pub struct C_original { } impl C_original { - fn fetch_imports(&mut self)-> Result<(), SniprunError> { + fn fetch_imports(&mut self) -> Result<(), SniprunError> { if self.support_level < SupportLevel::Import { return Ok(()); } @@ -40,6 +40,12 @@ impl C_original { if line.starts_with("#include <") { self.imports.push(line.to_string()); } + if line.starts_with("#include") + && (std::env::var("C_INCLUDE_PATH").is_ok() + || std::env::var("CPLUS_INCLUDE_PATH").is_ok()) + { + self.imports.push(line.to_string()); + } } info!("fecthed imports : {:?}", self.imports); Ok(()) @@ -48,7 +54,9 @@ impl C_original { fn fetch_config(&mut self) { let default_compiler = String::from("gcc"); self.compiler = default_compiler; - if let Some(used_compiler) = C_original::get_interpreter_option(&self.get_data(), "compiler") { + if let Some(used_compiler) = + C_original::get_interpreter_option(&self.get_data(), "compiler") + { if let Some(compiler_string) = used_compiler.as_str() { info!("Using custom compiler: {}", compiler_string); self.compiler = compiler_string.to_string(); @@ -133,7 +141,7 @@ impl Interpreter for C_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { self.fetch_imports()?; - + if !C_original::contains_main(&"int main (", &self.code, &"//") { self.code = String::from("int main() {\n") + &self.code + "\nreturn 0;}"; } @@ -196,11 +204,11 @@ impl Interpreter for C_original { if line.contains("error") { // info!("breaking at position {:?}", line.split_at(line.find("error").unwrap()).1); relevant_error += line - .split_at(line.find("error").unwrap()) - .1 - .trim_start_matches("error: ") - .trim_end_matches("error:") - .trim_start_matches("error"); + .split_at(line.find("error").unwrap()) + .1 + .trim_start_matches("error: ") + .trim_end_matches("error:") + .trim_start_matches("error"); break_loop = true; } } @@ -242,7 +250,7 @@ mod test_c_original { // should panic if not an Ok() let string_result = res.unwrap(); assert_eq!(string_result, "1=1\n"); - } + } #[test] #[serial(c_original)] @@ -254,8 +262,7 @@ mod test_c_original { match res { Err(SniprunError::CompilationError(_)) => (), - _ => panic!("Compilation should have failed") + _ => panic!("Compilation should have failed"), }; } - } From 61a31995bd72634b45112cd425c9fe865aa93c11 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 11:43:17 +0100 Subject: [PATCH 24/29] version bump + changelog --- CHANGELOG.md | 4 +++- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- doc/C_original.md | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f50c1bc..322ef28c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## v1.1.2 -- auto dectection of entry point for many languages +- auto detection of entry point for many languages +- CFLAGS and other variables +- Python3\_fifo plots work ## v1.1.1 - Fix terminal display issues diff --git a/Cargo.lock b/Cargo.lock index 4edf1147..d85ed343 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,18 +177,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.34" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -271,9 +271,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" [[package]] name = "serde_bytes" @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ "itoa", "ryu", @@ -336,7 +336,7 @@ checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "sniprun" -version = "1.1.1" +version = "1.1.2" dependencies = [ "dirs", "libc", @@ -362,9 +362,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.82" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 0e993378..9fc214ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.1.1" +version = "1.1.2" authors = ["michaelb "] edition = "2018" diff --git a/doc/C_original.md b/doc/C_original.md index bd9de7ee..864b0190 100644 --- a/doc/C_original.md +++ b/doc/C_original.md @@ -14,7 +14,7 @@ require'sniprun'.setup({ If you run with GCC, Sniprun will be able to run function + code in the same snippet, or functions + main() function regardlessly,but only the latter is supported by clang. -This interpreter will also only import (all) #include \<...> but not any #include "..." (systems-wide include only, not the headers from your project, unless the environment variable `$C_INCLUDE_PATH` or `$CPLUS_INCLUDE_PATH` have been set) +This interpreter will also only import (all) #include \<...> but not any #include "..." (systems-wide include only, not the headers from your project, unless the environment variable `$C_INCLUDE_PATH` or `$CPLUS_INCLUDE_PATH` have been set). In this case, please make sure those variable cover **ALL** the paths needed to fetch every header file `#include`'d the C\_original interpreter will also make use of the following environment variables: From f5ab93776b4d829bb4e146b8982cca9d0d370330 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 14:07:10 +0100 Subject: [PATCH 25/29] fix go_original --- src/interpreters/Go_original.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/Go_original.rs b/src/interpreters/Go_original.rs index d7444242..26d2bdc7 100644 --- a/src/interpreters/Go_original.rs +++ b/src/interpreters/Go_original.rs @@ -116,7 +116,7 @@ impl Interpreter for Go_original { } if !Go_original::contains_main(&"import \"fmt\"", &self.code, &"//") { - self.code = String::from("package \"fmt\"\n") + &self.code; + self.code = String::from("import \"fmt\"\n") + &self.code; } if !Go_original::contains_main(&"package main", &self.code, &"//") { From 8fc077c2dd709509d64b5744f0870dcc3adb5a0e Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 14:37:39 +0100 Subject: [PATCH 26/29] colon-separate flags & print full gcc command --- src/interpreters/C_original.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index c48cbecd..c5198d81 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -163,31 +163,30 @@ impl Interpreter for C_original { } if let Ok(c_incl_path) = std::env::var("C_INCLUDE_PATH") { - build_args.push(String::from("-I")); - build_args.push(c_incl_path); + build_args.extend(c_incl_path.split(':').map(|s| String::from("-I") + s)); } if let Ok(cplus_incl_path) = std::env::var("CPLUS_INCLUDE_PATH") { - build_args.push(String::from("-I")); - build_args.push(cplus_incl_path); + build_args.extend(cplus_incl_path.split(':').map(|s| String::from("-I") + s)); } if let Ok(library_path) = std::env::var("LIBRARY_PATH") { - build_args.push(String::from("-L")); - build_args.push(library_path); + build_args.extend(library_path.split(':').map(|s| String::from("-L") + s)); } - info!("build args are: {:?}", build_args); let mut _file = File::create(&self.main_file_path).expect("Failed to create file for c-original"); write(&self.main_file_path, &self.code).expect("Unable to write to file for c-original"); - let output = Command::new(&self.compiler) + let mut cmd = Command::new(&self.compiler); + let cmd = cmd .arg(&self.main_file_path) .arg("-o") .arg(&self.bin_path) - .args(&build_args) - .output() - .expect("Unable to start process"); + .args(&build_args); + + info!("full gcc command emitted:\n{}\n", format!("{:?}",cmd)); + + let output = cmd.output().expect("Unable to start process"); //TODO if relevant, return the error number (parse it from stderr) if !output.status.success() { From 6b6be7075068a350249b417995fbe32d70227947 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 5 Jan 2022 14:40:26 +0100 Subject: [PATCH 27/29] cleaner full build cmd --- src/interpreters/C_original.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index c5198d81..233382d6 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -184,7 +184,7 @@ impl Interpreter for C_original { .arg(&self.bin_path) .args(&build_args); - info!("full gcc command emitted:\n{}\n", format!("{:?}",cmd)); + info!("full gcc command emitted:\n{}\n", format!("{:?}",cmd).replace("\"", "")); let output = cmd.output().expect("Unable to start process"); From 1ba2180710f54b67bdba65cdd690a3c45c530484 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 6 Jan 2022 10:18:30 +0100 Subject: [PATCH 28/29] more logs --- src/interpreters/C_original.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 233382d6..2e2feb49 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -20,7 +20,7 @@ impl C_original { let mut v = vec![]; let mut errored = true; if let Some(real_nvim_instance) = self.data.nvim_instance.clone() { - info!("got real nvim isntance"); + info!("got real nvim instance"); let mut rvi = real_nvim_instance.lock().unwrap(); if let Ok(buffer) = rvi.get_current_buf() { info!("got buffer"); @@ -159,18 +159,22 @@ impl Interpreter for C_original { let mut build_args: Vec = vec![]; if let Ok(cflags) = std::env::var("CFLAGS") { + info!("CLFAGS env var found : {}", cflags); build_args.extend(cflags.split_whitespace().map(|s| s.to_owned())); } if let Ok(c_incl_path) = std::env::var("C_INCLUDE_PATH") { + info!("C_INCLUDE_PATH env var found : {}", c_incl_path); build_args.extend(c_incl_path.split(':').map(|s| String::from("-I") + s)); } if let Ok(cplus_incl_path) = std::env::var("CPLUS_INCLUDE_PATH") { + info!("CPLUS_INCLUDE_PATH env var found : {}", cplus_incl_path); build_args.extend(cplus_incl_path.split(':').map(|s| String::from("-I") + s)); } if let Ok(library_path) = std::env::var("LIBRARY_PATH") { + info!("LIBRARY_PATH env var found : {}", library_path); build_args.extend(library_path.split(':').map(|s| String::from("-L") + s)); } @@ -182,6 +186,7 @@ impl Interpreter for C_original { .arg(&self.main_file_path) .arg("-o") .arg(&self.bin_path) + .arg("-v") .args(&build_args); info!("full gcc command emitted:\n{}\n", format!("{:?}",cmd).replace("\"", "")); @@ -191,7 +196,7 @@ impl Interpreter for C_original { //TODO if relevant, return the error number (parse it from stderr) if !output.status.success() { let error_message = String::from_utf8(output.stderr).unwrap(); - info!("Returning nice C error message: {}", error_message); + info!("Full GCC error message: {}", error_message); let mut relevant_error = String::new(); let mut break_loop = false; @@ -214,6 +219,9 @@ impl Interpreter for C_original { Err(SniprunError::CompilationError(relevant_error)) } else { + + let compiler_output = String::from_utf8(output.stdout).unwrap(); + info!("compiler output:\n{}\n", compiler_output); Ok(()) } } From 302931d51ead0e8dcb2b1913737d0c734eeaa49c Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 6 Jan 2022 13:57:30 +0100 Subject: [PATCH 29/29] typo --- src/interpreters/C_original.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 2e2feb49..e80ff1ed 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -159,7 +159,7 @@ impl Interpreter for C_original { let mut build_args: Vec = vec![]; if let Ok(cflags) = std::env::var("CFLAGS") { - info!("CLFAGS env var found : {}", cflags); + info!("CFLAGS env var found : {}", cflags); build_args.extend(cflags.split_whitespace().map(|s| s.to_owned())); }