diff options
-rw-r--r-- | Help/command/if.rst | 2 | ||||
-rw-r--r-- | Modules/FindMatlab.cmake | 4 | ||||
-rw-r--r-- | Modules/FindOctave.cmake | 14 | ||||
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 84 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunTest.h | 5 | ||||
-rw-r--r-- | Source/CursesDialog/cmCursesMainForm.cxx | 110 | ||||
-rw-r--r-- | Tests/FindOctave/Test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindOctave/Test/interp_main.cpp | 26 |
9 files changed, 106 insertions, 145 deletions
diff --git a/Help/command/if.rst b/Help/command/if.rst index a682c83..a48a0fa 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -23,7 +23,7 @@ Otherwise, optional ``elseif`` blocks are processed in the same way. Finally, if no ``condition`` is true, ``commands`` in the optional ``else`` block are executed. -Per legacy, the :command:`else` and :command:`elseif` commands admit +Per legacy, the :command:`else` and :command:`endif` commands admit an optional ``<condition>`` argument. If used, it must be a verbatim repeat of the argument of the opening diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 8544653..3547642 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -725,7 +725,7 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve file(REMOVE "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp") set(index -1) - string(FIND ${_matlab_version_from_cmd} "ans" index) + string(FIND "${_matlab_version_from_cmd}" "ans" index) if(index EQUAL -1) if(MATLAB_FIND_DEBUG) @@ -735,7 +735,7 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve else() set(matlab_list_of_all_versions_tmp) - string(SUBSTRING ${_matlab_version_from_cmd} ${index} -1 substring_ans) + string(SUBSTRING "${_matlab_version_from_cmd}" ${index} -1 substring_ans) string( REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*'?([0-9]+(\\.[0-9]+)?)" matlab_versions_regex diff --git a/Modules/FindOctave.cmake b/Modules/FindOctave.cmake index 8ae6a47..8110ff1 100644 --- a/Modules/FindOctave.cmake +++ b/Modules/FindOctave.cmake @@ -15,7 +15,10 @@ This module defines the following :prop_tgt:`IMPORTED` targets: ``Octave::Interpreter`` Octave interpreter (the main program) ``Octave::Octave`` - include directories and libraries + include directories and the octave library +``Octave::Octinterp`` + include directories and the octinterp library including the dependency on + Octave::Octave If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed. @@ -144,6 +147,15 @@ if(Octave_Development_FOUND) ) endif() + if(NOT TARGET Octave::Octinterp) + add_library(Octave::Octinterp UNKNOWN IMPORTED) + set_target_properties(Octave::Octinterp PROPERTIES + IMPORTED_LOCATION ${Octave_INTERP_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${Octave_INCLUDE_DIR}) + target_link_libraries(Octave::Octinterp INTERFACE + Octave::Octave) + endif() + endif() diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 6c6b3a0..a4eb53f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 14) -set(CMake_VERSION_PATCH 20190211) +set(CMake_VERSION_PATCH 20190212) #set(CMake_VERSION_RC 1) diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 5183c6f..41d02c5 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -9,8 +9,6 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include "cm_zlib.h" -#include "cmsys/Base64.h" #include "cmsys/RegularExpression.hxx" #include <chrono> #include <cmAlgorithms.h> @@ -32,9 +30,6 @@ cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler) this->TestResult.Status = cmCTestTestHandler::NOT_RUN; this->TestResult.TestCount = 0; this->TestResult.Properties = nullptr; - this->ProcessOutput.clear(); - this->CompressedOutput.clear(); - this->CompressionRatio = 2; this->NumberOfRunsLeft = 1; // default to 1 run of the test this->RunUntilFail = false; // default to run the test once this->RunAgain = false; // default to not having to run again @@ -69,73 +64,8 @@ void cmCTestRunTest::CheckOutput(std::string const& line) } } -// Streamed compression of test output. The compressed data -// is appended to this->CompressedOutput -void cmCTestRunTest::CompressOutput() -{ - int ret; - z_stream strm; - - unsigned char* in = reinterpret_cast<unsigned char*>( - const_cast<char*>(this->ProcessOutput.c_str())); - // zlib makes the guarantee that this is the maximum output size - int outSize = static_cast<int>( - static_cast<double>(this->ProcessOutput.size()) * 1.001 + 13.0); - unsigned char* out = new unsigned char[outSize]; - - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit(&strm, -1); // default compression level - if (ret != Z_OK) { - delete[] out; - return; - } - - strm.avail_in = static_cast<uInt>(this->ProcessOutput.size()); - strm.next_in = in; - strm.avail_out = outSize; - strm.next_out = out; - ret = deflate(&strm, Z_FINISH); - - if (ret != Z_STREAM_END) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error during output compression. Sending uncompressed output." - << std::endl); - delete[] out; - return; - } - - (void)deflateEnd(&strm); - - unsigned char* encoded_buffer = - new unsigned char[static_cast<int>(outSize * 1.5)]; - - size_t rlen = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1); - - this->CompressedOutput.clear(); - for (size_t i = 0; i < rlen; i++) { - this->CompressedOutput += encoded_buffer[i]; - } - - if (strm.total_in) { - this->CompressionRatio = - static_cast<double>(strm.total_out) / static_cast<double>(strm.total_in); - } - - delete[] encoded_buffer; - delete[] out; -} - bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) { - if ((!this->TestHandler->MemCheck && - this->CTest->ShouldCompressTestOutput()) || - (this->TestHandler->MemCheck && - this->CTest->ShouldCompressTestOutput())) { - this->CompressOutput(); - } - this->WriteLogOutputTop(completed, total); std::string reason; bool passed = true; @@ -336,10 +266,18 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) // if the test actually started and ran // record the results in TestResult if (started) { - bool compress = !this->TestHandler->MemCheck && - this->CompressionRatio < 1 && this->CTest->ShouldCompressTestOutput(); + std::string compressedOutput; + if (!this->TestHandler->MemCheck && + this->CTest->ShouldCompressTestOutput()) { + std::string str = this->ProcessOutput; + if (this->CTest->CompressString(str)) { + compressedOutput = std::move(str); + } + } + bool compress = !compressedOutput.empty() && + compressedOutput.length() < this->ProcessOutput.length(); this->TestResult.Output = - compress ? this->CompressedOutput : this->ProcessOutput; + compress ? compressedOutput : this->ProcessOutput; this->TestResult.CompressOutput = compress; this->TestResult.ReturnValue = this->TestProcess->GetExitValue(); if (!skipped) { diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 918d5fa..38cc417 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -58,9 +58,6 @@ public: // Read and store output. Returns true if it must be called again. void CheckOutput(std::string const& line); - // Compresses the output, writing to CompressedOutput - void CompressOutput(); - // launch the test process, return whether it started correctly bool StartTest(size_t completed, size_t total); // capture and report the test results @@ -105,8 +102,6 @@ private: cmCTest* CTest; std::unique_ptr<cmProcess> TestProcess; std::string ProcessOutput; - std::string CompressedOutput; - double CompressionRatio; // The test results cmCTestTestHandler::cmCTestTestResult TestResult; cmCTestMultiProcessHandler& MultiTestHandler; diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index ec18ece..3fe1834 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -79,18 +79,11 @@ cmCursesMainForm::~cmCursesMainForm() // See if a cache entry is in the list of entries in the ui. bool cmCursesMainForm::LookForCacheEntry(const std::string& key) { - if (!this->Entries) { - return false; - } - - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - if (key == (*it)->Key) { - return true; - } - } - - return false; + return this->Entries && + std::any_of(this->Entries->begin(), this->Entries->end(), + [&key](cmCursesCacheEntryComposite* entry) { + return key == entry->Key; + }); } // Create new cmCursesCacheEntryComposite entries from the cache @@ -185,13 +178,12 @@ void cmCursesMainForm::RePost() } else { // If normal mode, count only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -212,27 +204,26 @@ void cmCursesMainForm::RePost() // Assign fields int j = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } - this->Fields[3 * j] = (*it)->Label->Field; - this->Fields[3 * j + 1] = (*it)->IsNewLabel->Field; - this->Fields[3 * j + 2] = (*it)->Entry->Field; + this->Fields[3 * j] = entry->Label->Field; + this->Fields[3 * j + 1] = entry->IsNewLabel->Field; + this->Fields[3 * j + 2] = entry->Entry->Field; j++; } // if no cache entries there should still be one dummy field if (j == 0) { - it = this->Entries->begin(); - this->Fields[0] = (*it)->Label->Field; - this->Fields[1] = (*it)->IsNewLabel->Field; - this->Fields[2] = (*it)->Entry->Field; + const auto& front = *this->Entries->front(); + this->Fields[0] = front.Label->Field; + this->Fields[1] = front.IsNewLabel->Field; + this->Fields[2] = front.Entry->Field; this->NumberOfVisibleEntries = 1; } // Has to be null terminated. @@ -273,13 +264,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) } else { // If normal, display only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -292,13 +282,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (height > 0) { bool isNewPage; int i = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -309,10 +298,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (isNewPage) { this->NumberOfPages++; } - (*it)->Label->Move(left, top + row - 1, isNewPage); - (*it)->IsNewLabel->Move(left + 32, top + row - 1, false); - (*it)->Entry->Move(left + 33, top + row - 1, false); - (*it)->Entry->SetPage(this->NumberOfPages); + entry->Label->Move(left, top + row - 1, isNewPage); + entry->IsNewLabel->Move(left + 32, top + row - 1, false); + entry->Entry->Move(left + 33, top + row - 1, false); + entry->Entry->SetPage(this->NumberOfPages); i++; } } @@ -658,28 +647,28 @@ void cmCursesMainForm::RemoveEntry(const char* value) return; } - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* val = (*it)->GetValue(); - if (val && !strcmp(value, val)) { - this->CMakeInstance->UnwatchUnusedCli(value); - this->Entries->erase(it); - break; - } + auto removeIt = std::find_if(this->Entries->begin(), this->Entries->end(), + [value](cmCursesCacheEntryComposite* entry) { + const char* val = entry->GetValue(); + return val && !strcmp(value, val); + }); + + if (removeIt != this->Entries->end()) { + this->CMakeInstance->UnwatchUnusedCli(value); + this->Entries->erase(removeIt); } } // copy from the list box to the cache manager void cmCursesMainForm::FillCacheManagerFromUI() { - size_t size = this->Entries->size(); - for (size_t i = 0; i < size; i++) { - std::string cacheKey = (*this->Entries)[i]->Key; + for (cmCursesCacheEntryComposite* entry : *this->Entries) { + const std::string& cacheKey = entry->Key; const char* existingValue = this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey); if (existingValue) { std::string oldValue = existingValue; - std::string newValue = (*this->Entries)[i]->Entry->GetValue(); + std::string newValue = entry->GetValue(); std::string fixedOldValue; std::string fixedNewValue; cmStateEnums::CacheEntryType t = @@ -975,17 +964,14 @@ void cmCursesMainForm::HandleInput() if (nextCur) { // make the next or prev. current field after deletion - nextCur = nullptr; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); - ++it) { - if (nextVal == (*it)->Key) { - nextCur = (*it)->Entry->Field; - } - } - - if (nextCur) { - set_current_field(this->Form, nextCur); + auto nextEntryIt = + std::find_if(this->Entries->begin(), this->Entries->end(), + [&nextVal](cmCursesCacheEntryComposite* entry) { + return nextVal == entry->Key; + }); + + if (nextEntryIt != this->Entries->end()) { + set_current_field(this->Form, (*nextEntryIt)->Entry->Field); } } } diff --git a/Tests/FindOctave/Test/CMakeLists.txt b/Tests/FindOctave/Test/CMakeLists.txt index ce33fcd..73aa831 100644 --- a/Tests/FindOctave/Test/CMakeLists.txt +++ b/Tests/FindOctave/Test/CMakeLists.txt @@ -10,6 +10,10 @@ add_executable(test_tgt main.cpp) target_link_libraries(test_tgt Octave::Octave) add_test(NAME test_tgt COMMAND test_tgt) +add_executable(test_octinterp_tgt interp_main.cpp) +target_link_libraries(test_octinterp_tgt Octave::Octinterp) +add_test(NAME test_octinterp_tgt COMMAND test_octinterp_tgt) + add_test(NAME test_tgt_exe COMMAND Octave::Interpreter -q --eval "runtests('.')" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/Tests/FindOctave/Test/interp_main.cpp b/Tests/FindOctave/Test/interp_main.cpp new file mode 100644 index 0000000..1efa187 --- /dev/null +++ b/Tests/FindOctave/Test/interp_main.cpp @@ -0,0 +1,26 @@ +#include <iostream> +#include <oct.h> +#include <octave.h> +#include <parse.h> +#include <toplev.h> + +int main(void) +{ + string_vector argv(2); + argv(0) = "embedded"; + argv(1) = "-q"; + + try { + octave_main(2, argv.c_str_vec(), 1); + octave_value_list in; + in(0) = 72.0; + const octave_value_list result = feval("sqrt", in); + std::cout << "result is " << result(0).scalar_value() << std::endl; + clean_up_and_exit(0); + } catch (const octave::exit_exception& ex) { + std::cerr << "Octave interpreter exited with status = " << ex.exit_status() + << std::endl; + } catch (const octave::execution_exception&) { + std::cerr << "error encountered in Octave evaluator!" << std::endl; + } +} |