From 39e9c1bff0e9a0b76c24a108f01db132505a5851 Mon Sep 17 00:00:00 2001 From: Venelin Date: Sat, 24 Aug 2024 13:06:34 +0300 Subject: [PATCH] fix debug not recompiling --- run_tests.sh | 7 ++++++- src/cppipe.cpp | 24 ++++++++---------------- test/functions_test.cppipe | 4 ++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 9981b9b..563c417 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,7 +2,12 @@ set -e # Test cppipe functions -cppipe test/test.cpp +OKs=$(cppipe test/functions_test.cppipe | grep OK | wc -l) +if ! [ $OKs = 12 ] +then + echo "EXPECTED 1 OKs, got $OKs" + exit 1 +fi # Test on a C file echo OK | cppipe test/c_file.c diff --git a/src/cppipe.cpp b/src/cppipe.cpp index 62b6b8b..45977f1 100644 --- a/src/cppipe.cpp +++ b/src/cppipe.cpp @@ -281,35 +281,27 @@ void compile_src_file() // Only compile if the source is newer then the bin if(preprocess_and_compare() || !fs::exists(bin)) { - string preprocessed_file = cache_dir / src_file.stem() += - (src_type == SrcType::C ? ".i" : ".ii"); // todo: duplicates with old_pp_path + string preprocessed_file = cache_dir / (debug ? DEBUG_PREFIX : "") += src_file.stem() + += (src_type == SrcType::C ? ".i" : ".ii"); // todo: duplicates with old_pp_path (std::optional?) + Cmd compile( src_type == SrcType::C ? CC : CXX, preprocessed_file.c_str(), "-o", bin.c_str() ); - if(src_type == SrcType::C) - { - for(const char* flag: { CFLAGS }) - compile += flag; - } - else - { - for(const char* flag: { CXXFLAGS }) - compile += flag; - } + if(src_type == SrcType::C) + compile.append_args({ CFLAGS }); + else + compile.append_args({ CXXFLAGS }); if(debug) - { compile.append_args({ DEBUG_FLAGS }); - } else - { compile.append_args({ RELEASE_FLAGS }); - } + if( !compile() ) // if failed to compile exit(1); diff --git a/test/functions_test.cppipe b/test/functions_test.cppipe index e00ff2b..956eb95 100644 --- a/test/functions_test.cppipe +++ b/test/functions_test.cppipe @@ -22,8 +22,8 @@ int main(int argc, char* argv[]) Cmd echo("echo"); Cmd rm("rm"); - string out1 = $(ll | grep + "cpp" | grep + "child"); - if(out1.find("childProcess.cpp") != string::npos) + string out1 = $(ll + "src" | grep + "inl" | grep + "child"); + if(out1.find("childProcess.inl") != string::npos) cout << "OK 0/11" << endl; string out2 = $(echo + "abc" + "def");