ctest_update: Support custom Git update command

Define CTest configuration variable CTEST_GIT_UPDATE_CUSTOM to set a
custom command line for updating Git-managed source trees.
This commit is contained in:
Brad King 2010-06-08 16:12:28 -04:00
parent 11bdc2b1a1
commit 2eae651acc
5 changed files with 95 additions and 16 deletions

View File

@ -49,6 +49,7 @@ SVNUpdateOptions: @SVN_UPDATE_OPTIONS@
# Git options
GITCommand: @GITCOMMAND@
GITUpdateOptions: @GIT_UPDATE_OPTIONS@
GITUpdateCustom: @CTEST_GIT_UPDATE_CUSTOM@
# Generic update command
UpdateCommand: @UPDATE_COMMAND@

View File

@ -85,7 +85,7 @@ void cmCTestGIT::NoteNewRevision()
}
//----------------------------------------------------------------------------
bool cmCTestGIT::UpdateImpl()
bool cmCTestGIT::UpdateByPull()
{
const char* git = this->CommandLineTool.c_str();
@ -114,14 +114,51 @@ bool cmCTestGIT::UpdateImpl()
OutputLogger out(this->Log, "pull-out> ");
OutputLogger err(this->Log, "pull-err> ");
if(this->RunUpdateCommand(&git_pull[0], &out, &err))
return this->RunUpdateCommand(&git_pull[0], &out, &err);
}
//----------------------------------------------------------------------------
bool cmCTestGIT::UpdateByCustom(std::string const& custom)
{
std::vector<std::string> git_custom_command;
cmSystemTools::ExpandListArgument(custom, git_custom_command, true);
std::vector<char const*> git_custom;
for(std::vector<std::string>::const_iterator
i = git_custom_command.begin(); i != git_custom_command.end(); ++i)
{
char const* git_submodule[] = {git, "submodule", "update", 0};
OutputLogger out2(this->Log, "submodule-out> ");
OutputLogger err2(this->Log, "submodule-err> ");
return this->RunChild(git_submodule, &out2, &err2);
git_custom.push_back(i->c_str());
}
return false;
git_custom.push_back(0);
OutputLogger custom_out(this->Log, "custom-out> ");
OutputLogger custom_err(this->Log, "custom-err> ");
return this->RunUpdateCommand(&git_custom[0], &custom_out, &custom_err);
}
//----------------------------------------------------------------------------
bool cmCTestGIT::UpdateInternal()
{
std::string custom = this->CTest->GetCTestConfiguration("GITUpdateCustom");
if(!custom.empty())
{
return this->UpdateByCustom(custom);
}
return this->UpdateByPull();
}
//----------------------------------------------------------------------------
bool cmCTestGIT::UpdateImpl()
{
if(!this->UpdateInternal())
{
return false;
}
const char* git = this->CommandLineTool.c_str();
char const* git_submodule[] = {git, "submodule", "update", 0};
OutputLogger submodule_out(this->Log, "submodule-out> ");
OutputLogger submodule_err(this->Log, "submodule-err> ");
return this->RunChild(git_submodule, &submodule_out, &submodule_err);
}
//----------------------------------------------------------------------------

View File

@ -32,6 +32,10 @@ private:
virtual void NoteNewRevision();
virtual bool UpdateImpl();
bool UpdateByPull();
bool UpdateByCustom(std::string const& custom);
bool UpdateInternal();
void LoadRevisions();
void LoadModifications();

View File

@ -51,6 +51,8 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
"GITCommand", "CTEST_GIT_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"GITUpdateOptions", "CTEST_GIT_UPDATE_OPTIONS");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"GITUpdateCustom", "CTEST_GIT_UPDATE_CUSTOM");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"HGCommand", "CTEST_HG_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,

View File

@ -192,15 +192,18 @@ run_child(
#-----------------------------------------------------------------------------
# Go back to before the changes so we can test updating.
message("Backing up to revision 1...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} reset --hard master~2
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} submodule update
)
macro(rewind_source src_dir)
message("Backing up to revision 1...")
run_child(
WORKING_DIRECTORY ${TOP}/${src_dir}
COMMAND ${GIT} reset --hard origin/master~2
)
run_child(
WORKING_DIRECTORY ${TOP}/${src_dir}
COMMAND ${GIT} submodule update
)
endmacro(rewind_source)
rewind_source(user-source)
# Make sure pull does not try to rebase (which does not work with
# modified files) even if ~/.gitconfig sets "branch.master.rebase".
@ -226,6 +229,22 @@ UpdateCommand: ${GIT}
# Run the dashboard command line interface.
run_dashboard_command_line(user-binary)
rewind_source(user-source)
modify_content(user-source)
message("Running CTest Dashboard Command Line (custom update)...")
# Create the user build tree.
create_build_tree(user-source user-binary-custom)
file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
"# GIT command configuration
UpdateCommand: ${GIT}
GITUpdateCustom: ${GIT};pull;origin;master
")
# Run the dashboard command line interface.
run_dashboard_command_line(user-binary-custom)
#-----------------------------------------------------------------------------
# Test initial checkout and update with a dashboard script.
message("Running CTest Dashboard Script...")
@ -254,3 +273,19 @@ execute_process(
# Run the dashboard script with CTest.
run_dashboard_script(dash-binary)
rewind_source(dash-source)
#-----------------------------------------------------------------------------
# Test custom update with a dashboard script.
message("Running CTest Dashboard Script (custom update)...")
create_dashboard_script(dash-binary-custom
"# git command configuration
set(CTEST_GIT_COMMAND \"${GIT}\")
set(CTEST_GIT_UPDATE_OPTIONS)
set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
")
# Run the dashboard script with CTest.
run_dashboard_script(dash-binary-custom)