1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestHandlerCommand.cxx,v $
6 Date: $Date: 2008/01/23 15:28:01 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCTestHandlerCommand.h"
20 #include "cmCTestGenericHandler.h"
22 cmCTestHandlerCommand::cmCTestHandlerCommand()
24 const size_t INIT_SIZE
= 100;
26 this->Arguments
.reserve(INIT_SIZE
);
27 for ( cc
= 0; cc
< INIT_SIZE
; ++ cc
)
29 this->Arguments
.push_back(0);
31 this->Arguments
[ct_RETURN_VALUE
] = "RETURN_VALUE";
32 this->Arguments
[ct_SOURCE
] = "SOURCE";
33 this->Arguments
[ct_BUILD
] = "BUILD";
34 this->Arguments
[ct_SUBMIT_INDEX
] = "SUBMIT_INDEX";
38 bool cmCTestHandlerCommand
39 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
41 if ( !this->ProcessArguments(args
, (unsigned int)this->Last
,
42 &*this->Arguments
.begin(),this->Values
) )
47 cmCTestLog(this->CTest
, DEBUG
, "Initialize handler" << std::endl
;);
48 cmCTestGenericHandler
* handler
= this->InitializeHandler();
51 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
52 "Cannot instantiate test handler " << this->GetName()
57 cmCTestLog(this->CTest
, DEBUG
, "Populate Custom Vectors" << std::endl
;);
58 handler
->PopulateCustomVectors(this->Makefile
);
60 if ( this->Values
[ct_BUILD
] )
62 this->CTest
->SetCTestConfiguration("BuildDirectory",
63 cmSystemTools::CollapseFullPath(
64 this->Values
[ct_BUILD
]).c_str());
68 this->CTest
->SetCTestConfiguration("BuildDirectory",
69 cmSystemTools::CollapseFullPath(
70 this->Makefile
->GetDefinition("CTEST_BINARY_DIRECTORY")).c_str());
72 if ( this->Values
[ct_SOURCE
] )
74 cmCTestLog(this->CTest
, DEBUG
,
75 "Set source directory to: " << this->Values
[ct_SOURCE
] << std::endl
);
76 this->CTest
->SetCTestConfiguration("SourceDirectory",
77 cmSystemTools::CollapseFullPath(
78 this->Values
[ct_SOURCE
]).c_str());
82 this->CTest
->SetCTestConfiguration("SourceDirectory",
83 cmSystemTools::CollapseFullPath(
84 this->Makefile
->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
86 if ( this->Values
[ct_SUBMIT_INDEX
] )
88 if ( this->CTest
->GetDartVersion() <= 1 )
90 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
91 "Dart before version 2.0 does not support collecting submissions."
93 << "Please upgrade the server to Dart 2 or higher, or do not use "
94 "SUBMIT_INDEX." << std::endl
);
98 handler
->SetSubmitIndex(atoi(this->Values
[ct_SUBMIT_INDEX
]));
102 std::string current_dir
= cmSystemTools::GetCurrentWorkingDirectory();
103 cmSystemTools::ChangeDirectory(
104 this->CTest
->GetCTestConfiguration("BuildDirectory").c_str());
105 int res
= handler
->ProcessHandler();
106 if ( this->Values
[ct_RETURN_VALUE
] && *this->Values
[ct_RETURN_VALUE
])
110 this->Makefile
->AddDefinition(
111 this->Values
[ct_RETURN_VALUE
], str
.str().c_str());
113 cmSystemTools::ChangeDirectory(current_dir
.c_str());
117 bool cmCTestHandlerCommand::ProcessArguments(
118 std::vector
<std::string
> const& args
, int last
, const char** strings
,
119 std::vector
<const char*>& values
)
124 for ( cc
= 0; cc
< last
; ++ cc
)
129 for(size_t i
=0; i
< args
.size(); ++i
)
131 if ( state
> 0 && state
< last
)
133 values
[state
] = args
[i
].c_str();
134 cmCTestLog(this->CTest
, DEBUG
, "Set " << strings
[state
] << " to "
135 << args
[i
].c_str() << std::endl
);
141 for ( cc
= 0; cc
< last
; ++ cc
)
143 if ( strings
[cc
] && args
[i
] == strings
[cc
] )
148 cmOStringStream ostr
;
149 ostr
<< "called with incorrect number of arguments. "
150 << strings
[state
] << " specified twice.";
151 this->SetError(ostr
.str().c_str());
162 << "called with incorrect number of arguments. Extra argument is: "
163 << args
[i
].c_str() << ".";
164 this->SetError(str
.str().c_str());