diff options
author | Zach Mullen <zach.mullen@kitware.com> | 2011-02-18 17:11:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-03-15 19:07:37 (GMT) |
commit | 350546db3aa956e34487bd38dd048fe9a0689e4a (patch) | |
tree | 3f0bda38ef56ddba39d93cb172e5cec8e6fb3fe7 /Source/CTest | |
parent | 0554e5e50f6eb3117b4e207f4b01876dbe5a75a4 (diff) | |
download | CMake-350546db3aa956e34487bd38dd048fe9a0689e4a.zip CMake-350546db3aa956e34487bd38dd048fe9a0689e4a.tar.gz CMake-350546db3aa956e34487bd38dd048fe9a0689e4a.tar.bz2 |
Implement ctest_upload command
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestSubmitHandler.cxx | 1 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 44 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestUploadCommand.cxx | 57 | ||||
-rw-r--r-- | Source/CTest/cmCTestUploadCommand.h | 79 | ||||
-rw-r--r-- | Source/CTest/cmCTestUploadHandler.cxx | 77 | ||||
-rw-r--r-- | Source/CTest/cmCTestUploadHandler.h | 45 |
8 files changed, 262 insertions, 45 deletions
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 12d5fd1..5841b8d 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -50,6 +50,7 @@ #include "cmCTestSubmitCommand.h" #include "cmCTestTestCommand.h" #include "cmCTestUpdateCommand.h" +#include "cmCTestUploadCommand.h" #define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log" @@ -357,6 +358,7 @@ void cmCTestScriptHandler::CreateCMake() this->AddCTestCommand(new cmCTestSubmitCommand); this->AddCTestCommand(new cmCTestTestCommand); this->AddCTestCommand(new cmCTestUpdateCommand); + this->AddCTestCommand(new cmCTestUploadCommand); } void cmCTestScriptHandler::GetCommandDocumentation( diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 43441c0..142bb46 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -1204,6 +1204,7 @@ int cmCTestSubmitHandler::ProcessHandler() this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml"); this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml"); this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml"); + this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml"); // Query parts for files to submit. for(cmCTest::Part p = cmCTest::PartStart; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f87c929..bad26c5 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1282,7 +1282,7 @@ void cmCTestTestHandler::AttachFiles(std::ostream& os, result->Properties->AttachedFiles.begin(); file != result->Properties->AttachedFiles.end(); ++file) { - std::string base64 = this->EncodeFile(*file); + std::string base64 = this->CTest->Base64GzipEncodeFile(*file); std::string fname = cmSystemTools::GetFilenameName(*file); os << "\t\t<NamedMeasurement name=\"Attached File\" encoding=\"base64\" " "compression=\"tar/gzip\" filename=\"" << fname << "\" type=\"file\">" @@ -1293,48 +1293,6 @@ void cmCTestTestHandler::AttachFiles(std::ostream& os, } //---------------------------------------------------------------------- -std::string cmCTestTestHandler::EncodeFile(std::string file) -{ - std::string tarFile = file + "_temp.tar.gz"; - std::vector<cmStdString> files; - files.push_back(file); - - if(!cmSystemTools::CreateTar(tarFile.c_str(), files, true, false, false)) - { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Error creating tar while " - "attaching file: " << file << std::endl); - return ""; - } - long len = cmSystemTools::FileLength(tarFile.c_str()); - std::ifstream ifs(tarFile.c_str(), std::ios::in -#ifdef _WIN32 - | std::ios::binary -#endif - ); - unsigned char *file_buffer = new unsigned char [ len + 1 ]; - ifs.read(reinterpret_cast<char*>(file_buffer), len); - ifs.close(); - cmSystemTools::RemoveFile(tarFile.c_str()); - - unsigned char *encoded_buffer - = new unsigned char [ static_cast<int>( - static_cast<double>(len) * 1.5 + 5.0) ]; - - unsigned long rlen - = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1); - - std::string base64 = ""; - for(unsigned long i = 0; i < rlen; i++) - { - base64 += encoded_buffer[i]; - } - delete [] file_buffer; - delete [] encoded_buffer; - - return base64; -} - -//---------------------------------------------------------------------- int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec) { std::vector<cmStdString>::iterator it; diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 2c4b230..3089d35 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -151,8 +151,6 @@ protected: void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result); // Write attached test files into the xml void AttachFiles(std::ostream& os, cmCTestTestResult* result); - // Helper function to encode attached test files - std::string EncodeFile(std::string file); //! Clean test output to specified length bool CleanTestOutput(std::string& output, size_t length); diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx new file mode 100644 index 0000000..9f0954b --- /dev/null +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -0,0 +1,57 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmCTestUploadCommand.h" + +#include "cmCTest.h" +#include "cmCTestGenericHandler.h" +#include "cmCTestUploadHandler.h" + +cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler() +{ + cmCTestGenericHandler* handler + = this->CTest->GetInitializedHandler("upload"); + if ( !handler ) + { + this->SetError("internal CTest error. Cannot instantiate upload handler"); + return 0; + } + static_cast<cmCTestUploadHandler*>(handler)->SetFiles(this->Files); + + return handler; +} + + +//---------------------------------------------------------------------------- +bool cmCTestUploadCommand::CheckArgumentKeyword(std::string const& arg) +{ + return this->CheckArgumentValue(arg); +} + + +//---------------------------------------------------------------------------- +bool cmCTestUploadCommand::CheckArgumentValue(std::string const& arg) +{ + cmStdString filename(arg); + if(cmSystemTools::FileExists(filename.c_str())) + { + this->Files.insert(filename); + return true; + } + else + { + cmOStringStream e; + e << "File \"" << filename << "\" does not exist. Cannot submit " + << "a non-existent file."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } +} diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h new file mode 100644 index 0000000..b8c9d9f --- /dev/null +++ b/Source/CTest/cmCTestUploadCommand.h @@ -0,0 +1,79 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmCTestUploadCommand_h +#define cmCTestUploadCommand_h + +#include "cmCTestHandlerCommand.h" +#include "cmCTest.h" + +/** \class cmCTestUpload + * \brief Run a ctest script + * + * cmCTestUploadCommand defines the command to upload result files for + * the project. + */ +class cmCTestUploadCommand : public cmCTestHandlerCommand +{ +public: + + cmCTestUploadCommand() + { + } + + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + cmCTestUploadCommand* ni = new cmCTestUploadCommand; + ni->CTest = this->CTest; + ni->CTestScriptHandler = this->CTestScriptHandler; + return ni; + } + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() { return "ctest_upload";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Upload files to a dashboard server."; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + " ctest_upload(...)\n" + "Pass a list of files to be sent along with the build results to " + "the dashboard server.\n"; + } + + cmTypeMacro(cmCTestUploadCommand, cmCTestHandlerCommand); + +protected: + cmCTestGenericHandler* InitializeHandler(); + + virtual bool CheckArgumentKeyword(std::string const& arg); + virtual bool CheckArgumentValue(std::string const& arg); + + cmCTest::SetOfStrings Files; +}; + + +#endif diff --git a/Source/CTest/cmCTestUploadHandler.cxx b/Source/CTest/cmCTestUploadHandler.cxx new file mode 100644 index 0000000..d5f6ab6 --- /dev/null +++ b/Source/CTest/cmCTestUploadHandler.cxx @@ -0,0 +1,77 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc. + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmCTestUploadHandler.h" + +#include "cmGeneratedFileStream.h" +#include "cmVersion.h" +#include "cmXMLSafe.h" + +//---------------------------------------------------------------------------- +cmCTestUploadHandler::cmCTestUploadHandler() +{ + this->Initialize(); +} + +//---------------------------------------------------------------------------- +void cmCTestUploadHandler::Initialize() +{ + this->Superclass::Initialize(); + this->Files.clear(); +} + +void cmCTestUploadHandler::SetFiles(const cmCTest::SetOfStrings& files) +{ + this->Files = files; +} + +//---------------------------------------------------------------------------- +int cmCTestUploadHandler::ProcessHandler() +{ + cmGeneratedFileStream ofs; + if ( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), + "Upload.xml", ofs)) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Cannot open Upload.xml file" << std::endl); + return -1; + } + + cmCTest::SetOfStrings::const_iterator it; + ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + << "<?xml-stylesheet type=\"text/xsl\" " + "href=\"Dart/Source/Server/XSL/Build.xsl " + "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n" + << "<Site BuildName=\"" + << this->CTest->GetCTestConfiguration("BuildName") + << "\" BuildStamp=\"" + << this->CTest->GetCurrentTag() << "-" + << this->CTest->GetTestModelString() << "\" Name=\"" + << this->CTest->GetCTestConfiguration("Site") << "\" Generator=\"ctest" + << cmVersion::GetCMakeVersion() + << "\">\n"; + this->CTest->AddSiteProperties(ofs); + ofs << "<Files>\n"; + + for ( it = this->Files.begin(); it != this->Files.end(); it ++ ) + { + cmCTestLog(this->CTest, OUTPUT, + "\tUpload file: " << it->c_str() << std::endl); + ofs << "<File filename=\"" << cmXMLSafe(*it) << "\">\n" + << "<Content compression=\"tar/gzip\" encoding=\"base64\">\n"; + ofs << this->CTest->Base64GzipEncodeFile(*it); + ofs << "\n</Content>\n" + << "</File>\n"; + } + ofs << "</Files>\n" + << "</Site>\n"; + return 0; +} diff --git a/Source/CTest/cmCTestUploadHandler.h b/Source/CTest/cmCTestUploadHandler.h new file mode 100644 index 0000000..23ed35a --- /dev/null +++ b/Source/CTest/cmCTestUploadHandler.h @@ -0,0 +1,45 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmCTestUploadHandler_h +#define cmCTestUploadHandler_h + +#include "cmCTestGenericHandler.h" + +/** \class cmCTestUploadHandler + * \brief Helper class for CTest + * + * Submit arbitrary files + * + */ +class cmCTestUploadHandler : public cmCTestGenericHandler +{ +public: + cmTypeMacro(cmCTestUploadHandler, cmCTestGenericHandler); + + cmCTestUploadHandler(); + ~cmCTestUploadHandler() {} + + /* + * The main entry point for this class + */ + int ProcessHandler(); + + void Initialize(); + + /** Specify a set of files to submit. */ + void SetFiles(cmCTest::SetOfStrings const& files); + +private: + cmCTest::SetOfStrings Files; +}; + +#endif |