1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestHandlerCommand.cxx,v $
6 Date: $Date: 2009-01-12 14:11:29 $
7 Version: $Revision: 1.15 $
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";
36 this->AppendXML
= false;
39 bool cmCTestHandlerCommand
40 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
42 // Allocate space for argument values.
44 this->Values
.resize(this->Last
, 0);
46 // Process input arguments.
47 this->ArgumentDoing
= ArgumentDoingNone
;
48 for(unsigned int i
=0; i
< args
.size(); ++i
)
50 // Check this argument.
51 if(!this->CheckArgumentKeyword(args
[i
]) &&
52 !this->CheckArgumentValue(args
[i
]))
55 e
<< "called with unknown argument \"" << args
[i
] << "\".";
56 this->SetError(e
.str().c_str());
60 // Quit if an argument is invalid.
61 if(this->ArgumentDoing
== ArgumentDoingError
)
67 cmCTestLog(this->CTest
, DEBUG
, "Initialize handler" << std::endl
;);
68 cmCTestGenericHandler
* handler
= this->InitializeHandler();
71 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
72 "Cannot instantiate test handler " << this->GetName()
77 handler
->SetAppendXML(this->AppendXML
);
79 handler
->PopulateCustomVectors(this->Makefile
);
80 if ( this->Values
[ct_BUILD
] )
82 this->CTest
->SetCTestConfiguration("BuildDirectory",
83 cmSystemTools::CollapseFullPath(
84 this->Values
[ct_BUILD
]).c_str());
89 this->Makefile
->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
93 CTest
->SetCTestConfiguration("BuildDirectory",
94 cmSystemTools::CollapseFullPath(bdir
).c_str());
98 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
99 "CTEST_BINARY_DIRECTORY not set" << std::endl
;);
102 if ( this->Values
[ct_SOURCE
] )
104 cmCTestLog(this->CTest
, DEBUG
,
105 "Set source directory to: " << this->Values
[ct_SOURCE
] << std::endl
);
106 this->CTest
->SetCTestConfiguration("SourceDirectory",
107 cmSystemTools::CollapseFullPath(
108 this->Values
[ct_SOURCE
]).c_str());
112 this->CTest
->SetCTestConfiguration("SourceDirectory",
113 cmSystemTools::CollapseFullPath(
114 this->Makefile
->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
116 if ( this->Values
[ct_SUBMIT_INDEX
] )
118 if ( this->CTest
->GetDartVersion() <= 1 )
120 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
121 "Dart before version 2.0 does not support collecting submissions."
123 << "Please upgrade the server to Dart 2 or higher, or do not use "
124 "SUBMIT_INDEX." << std::endl
);
128 handler
->SetSubmitIndex(atoi(this->Values
[ct_SUBMIT_INDEX
]));
131 std::string current_dir
= cmSystemTools::GetCurrentWorkingDirectory();
132 cmSystemTools::ChangeDirectory(
133 this->CTest
->GetCTestConfiguration("BuildDirectory").c_str());
134 int res
= handler
->ProcessHandler();
135 if ( this->Values
[ct_RETURN_VALUE
] && *this->Values
[ct_RETURN_VALUE
])
139 this->Makefile
->AddDefinition(
140 this->Values
[ct_RETURN_VALUE
], str
.str().c_str());
142 cmSystemTools::ChangeDirectory(current_dir
.c_str());
146 //----------------------------------------------------------------------------
147 bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string
const& arg
)
149 // Look for non-value arguments common to all commands.
152 this->ArgumentDoing
= ArgumentDoingNone
;
153 this->AppendXML
= true;
157 // Check for a keyword in our argument/value table.
158 for(unsigned int k
=0; k
< this->Arguments
.size(); ++k
)
160 if(this->Arguments
[k
] && arg
== this->Arguments
[k
])
162 this->ArgumentDoing
= ArgumentDoingKeyword
;
163 this->ArgumentIndex
= k
;
170 //----------------------------------------------------------------------------
171 bool cmCTestHandlerCommand::CheckArgumentValue(std::string
const& arg
)
173 if(this->ArgumentDoing
== ArgumentDoingKeyword
)
175 this->ArgumentDoing
= ArgumentDoingNone
;
176 unsigned int k
= this->ArgumentIndex
;
180 e
<< "Called with more than one value for " << this->Arguments
[k
];
181 this->Makefile
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
182 this->ArgumentDoing
= ArgumentDoingError
;
185 this->Values
[k
] = arg
.c_str();
186 cmCTestLog(this->CTest
, DEBUG
, "Set " << this->Arguments
[k
]
187 << " to " << arg
<< "\n");