Commit 970c8234 authored by Pedro Navarro's avatar Pedro Navarro Committed by Brad King

ctest_update: Add support for Perforce p4 client

Teach the ctest_update implementation to use the p4 command-line
client to perform updates and extract the list of changes.

Add a CTest.UpdateP4 test like those that exist already for the other
version control tools.  Make the test available when p4 and the p4d
server are found.  During the test launch p4d in the background to
serve a repository from the test directory.  Then direct the client
toward this server for the duration of the test.
parent ddef8a7c
......@@ -149,6 +149,7 @@ if(BUILD_TESTING)
find_program(BZRCOMMAND bzr)
find_program(HGCOMMAND hg)
find_program(GITCOMMAND git)
find_program(P4COMMAND p4)
if(NOT UPDATE_TYPE)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
......@@ -180,6 +181,9 @@ if(BUILD_TESTING)
elseif("${_update_type}" STREQUAL "git")
set(UPDATE_COMMAND "${GITCOMMAND}")
set(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
elseif("${_update_type}" STREQUAL "p4")
set(UPDATE_COMMAND "${P4COMMAND}")
set(UPDATE_OPTIONS "${P4_UPDATE_OPTIONS}")
endif()
set(DART_TESTING_TIMEOUT 1500 CACHE STRING
......@@ -275,6 +279,7 @@ if(BUILD_TESTING)
CVS_UPDATE_OPTIONS
DART_TESTING_TIMEOUT
GITCOMMAND
P4COMMAND
HGCOMMAND
MAKECOMMAND
MEMORYCHECK_COMMAND
......
......@@ -52,6 +52,13 @@ GITCommand: @GITCOMMAND@
GITUpdateOptions: @GIT_UPDATE_OPTIONS@
GITUpdateCustom: @CTEST_GIT_UPDATE_CUSTOM@
# Perforce options
P4Command: @P4COMMAND@
P4Client: @CTEST_P4_CLIENT@
P4Options: @CTEST_P4_OPTIONS@
P4UpdateOptions: @CTEST_P4_UPDATE_OPTIONS@
P4UpdateCustom: @CTEST_P4_UPDATE_CUSTOM@
# Generic update command
UpdateCommand: @UPDATE_COMMAND@
UpdateOptions: @UPDATE_OPTIONS@
......
......@@ -465,6 +465,8 @@ set(CTEST_SRCS cmCTest.cxx
CTest/cmCTestGIT.h
CTest/cmCTestHG.cxx
CTest/cmCTestHG.h
CTest/cmCTestP4.cxx
CTest/cmCTestP4.h
)
# Build CTestLib
......
This diff is collapsed.
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2013 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.
============================================================================*/
#ifndef cmCTestP4_h
#define cmCTestP4_h
#include "cmCTestGlobalVC.h"
#include <vector>
#include <map>
/** \class cmCTestP4
* \brief Interaction with the Perforce command-line tool
*
*/
class cmCTestP4: public cmCTestGlobalVC
{
public:
/** Construct with a CTest instance and update log stream. */
cmCTestP4(cmCTest* ctest, std::ostream& log);
virtual ~cmCTestP4();
private:
std::vector<std::string> ChangeLists;
struct User
{
std::string UserName;
std::string Name;
std::string EMail;
std::string AccessTime;
User(): UserName(), Name(), EMail(), AccessTime() {}
};
std::map<std::string, User> Users;
std::vector<std::string> P4Options;
User GetUserData(const std::string& username);
void SetP4Options(std::vector<char const*> &options);
std::string GetWorkingRevision();
virtual void NoteOldRevision();
virtual void NoteNewRevision();
virtual bool UpdateImpl();
bool UpdateCustom(const std::string& custom);
void LoadRevisions();
void LoadModifications();
// Parsing helper classes.
class IdentifyParser;
class ChangesParser;
class UserParser;
class DescribeParser;
class DiffParser;
friend class IdentifyParser;
friend class ChangesParser;
friend class UserParser;
friend class DescribeParser;
friend class DiffParser;
};
#endif
......@@ -59,6 +59,14 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
"HGCommand", "CTEST_HG_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"P4Command", "CTEST_P4_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"P4UpdateOptions", "CTEST_P4_UPDATE_OPTIONS");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"P4Client", "CTEST_P4_CLIENT");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"P4Options", "CTEST_P4_OPTIONS");
cmCTestGenericHandler* handler
= this->CTest->GetInitializedHandler("update");
......
......@@ -28,6 +28,7 @@
#include "cmCTestBZR.h"
#include "cmCTestGIT.h"
#include "cmCTestHG.h"
#include "cmCTestP4.h"
#include <cmsys/auto_ptr.hxx>
......@@ -51,7 +52,8 @@ static const char* cmCTestUpdateHandlerUpdateStrings[] =
"SVN",
"BZR",
"GIT",
"HG"
"HG",
"P4"
};
static const char* cmCTestUpdateHandlerUpdateToString(int type)
......@@ -146,6 +148,10 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{
return cmCTestUpdateHandler::e_HG;
}
if ( stype.find("p4") != std::string::npos )
{
return cmCTestUpdateHandler::e_P4;
}
}
else
{
......@@ -172,6 +178,10 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{
return cmCTestUpdateHandler::e_HG;
}
if ( stype.find("p4") != std::string::npos )
{
return cmCTestUpdateHandler::e_P4;
}
}
return cmCTestUpdateHandler::e_UNKNOWN;
}
......@@ -223,6 +233,7 @@ int cmCTestUpdateHandler::ProcessHandler()
case e_BZR: vc.reset(new cmCTestBZR(this->CTest, ofs)); break;
case e_GIT: vc.reset(new cmCTestGIT(this->CTest, ofs)); break;
case e_HG: vc.reset(new cmCTestHG(this->CTest, ofs)); break;
case e_P4: vc.reset(new cmCTestP4(this->CTest, ofs)); break;
default: vc.reset(new cmCTestVC(this->CTest, ofs)); break;
}
vc->SetCommandLineTool(this->UpdateCommand);
......@@ -350,6 +361,18 @@ int cmCTestUpdateHandler::DetectVCS(const char* dir)
{
return cmCTestUpdateHandler::e_HG;
}
sourceDirectory = dir;
sourceDirectory += "/.p4";
if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
{
return cmCTestUpdateHandler::e_P4;
}
sourceDirectory = dir;
sourceDirectory += "/.p4config";
if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
{
return cmCTestUpdateHandler::e_P4;
}
return cmCTestUpdateHandler::e_UNKNOWN;
}
......@@ -380,6 +403,7 @@ bool cmCTestUpdateHandler::SelectVCS()
case e_BZR: key = "BZRCommand"; break;
case e_GIT: key = "GITCommand"; break;
case e_HG: key = "HGCommand"; break;
case e_P4: key = "P4Command"; break;
default: break;
}
if (key)
......
......@@ -44,6 +44,7 @@ public:
e_BZR,
e_GIT,
e_HG,
e_P4,
e_LAST
};
......
......@@ -1877,6 +1877,26 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateHG_DIR}")
endif()
# Test CTest Update with P4
find_program(P4_EXECUTABLE NAMES p4)
find_program(P4D_EXECUTABLE NAMES p4d)
mark_as_advanced(P4_EXECUTABLE P4D_EXECUTABLE)
set(CTEST_TEST_UPDATE_P4 0)
if(P4_EXECUTABLE AND P4D_EXECUTABLE)
if(NOT "${P4_EXECUTABLE};${P4D_EXECUTABLE}" MATCHES "cygwin" OR UNIX)
set(CTEST_TEST_UPDATE_P4 1)
endif()
endif()
if(CTEST_TEST_UPDATE_P4)
set(CTestUpdateP4_DIR "CTest UpdateP4")
configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateP4.cmake.in"
"${CMake_BINARY_DIR}/Tests/CTestUpdateP4.cmake" @ONLY)
add_test(CTest.UpdateP4 ${CMAKE_CMAKE_COMMAND}
-P "${CMake_BINARY_DIR}/Tests/CTestUpdateP4.cmake"
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateP4_DIR}")
endif()
endif()
configure_file(
......
......@@ -216,7 +216,7 @@ function(run_dashboard_script bin_dir)
)
# Verify the updates reported by CTest.
list(APPEND UPDATE_MAYBE Updated{subdir})
list(APPEND UPDATE_MAYBE Updated{subdir} Updated{CTestConfig.cmake})
check_updates(${bin_dir}
Updated{foo.txt}
Updated{bar.txt}
......
# This script drives creation of a perforce repository and checks
# that CTest can update from it.
#-----------------------------------------------------------------------------
# Test in a directory next to this script.
get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(P4_TOP "${TOP}")
set(TOP "${TOP}/@CTestUpdateP4_DIR@")
# Include code common to all update tests.
include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
#-----------------------------------------------------------------------------
# Perforce server options
set(P4_HOST localhost)
set(P4_PORT 1888)
#-----------------------------------------------------------------------------
# Report p4 tools in use and set its defaults
message("Using P4 tools:")
set(P4 "@P4_EXECUTABLE@")
set(P4D "@P4D_EXECUTABLE@")
message(" p4 = ${P4}")
message(" p4d = ${P4D}")
set(P4_CLIENT -c ctest_p4)
set(P4_OPTIONS -H ${P4_HOST} -p ${P4_PORT})
set(P4CMD ${P4} ${P4_OPTIONS})
#-----------------------------------------------------------------------------
# Start the Perforce server
if(UNIX)
set(P4_ROOT ${P4_TOP}/perforce)
message("Starting p4d on '${P4_ROOT}' listening on port ${P4_PORT}...")
# Stop a previous instance of Perforce running
execute_process(
WORKING_DIRECTORY ${TOP}
COMMAND ${P4CMD} admin stop
OUTPUT_QUIET
ERROR_QUIET
)
# Make sure we don't have a perforce directory from a previous run
file(REMOVE_RECURSE ${P4_ROOT})
file(MAKE_DIRECTORY ${P4_ROOT})
set(P4_SERVER "nohup '${P4D}' -d -r '${P4_ROOT}'")
set(P4_SERVER "${P4_SERVER} -L '${P4_ROOT}/p4.log'")
set(P4_SERVER "${P4_SERVER} -J '${P4_ROOT}/journal'")
set(P4_SERVER "${P4_SERVER} -p ${P4_PORT} >/dev/null 2>&1 &")
message("Server command line: ${P4_SERVER}")
execute_process(
COMMAND sh -c "
${P4_SERVER}
for i in 1 2 3 4 5 6 7 8 9 10; do
echo 'Waiting for server to start...'
sleep 1
if '${P4}' -H ${P4_HOST} -p ${P4_PORT} help >/dev/null 2>&1; then
echo 'Server started.'
exit
fi
done
echo 'Gave up waiting for server to start.'
"
)
endif()
#-----------------------------------------------------------------------------
# Initialize the testing directory.
message("Creating test directory...")
init_testing()
#-----------------------------------------------------------------------------
# Create the repository.
message("Creating depot...")
file(WRITE ${TOP}/depot.spec "Depot: ctest\n")
file(APPEND ${TOP}/depot.spec "Type: local\n")
file(APPEND ${TOP}/depot.spec "Map: ctest/...\n")
run_child(
WORKING_DIRECTORY ${TOP}
COMMAND ${P4CMD} depot -i
INPUT_FILE ${TOP}/depot.spec
)
#-----------------------------------------------------------------------------
# Import initial content into the repository.
message("Importing content...")
create_content(user-source)
message("Creating client spec...")
file(WRITE ${TOP}/client.spec "Client: ctest_p4\n")
file(APPEND ${TOP}/client.spec "Root: ${TOP}/user-source\n")
file(APPEND ${TOP}/client.spec "View: //ctest/... //ctest_p4/...\n")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} client -i
INPUT_FILE ${TOP}/client.spec
)
# After creating the depot and the client view, all P4 commands need to
# have the client spec passed to them
list(APPEND P4CMD ${P4_CLIENT})
message("Adding files to repository")
file(GLOB_RECURSE files ${TOP}/user-source/*)
foreach(filename ${files})
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} add ${filename}
)
endforeach()
message("Submitting changes to repository")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} submit -d "CTEST: Initial content"
)
message("Tagging the repository")
file(WRITE ${TOP}/label.spec "Label: r1\n")
file(APPEND ${TOP}/label.spec "View: //ctest/...\n")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} label -i
INPUT_FILE ${TOP}/label.spec
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} labelsync -l r1
)
#-----------------------------------------------------------------------------
# Make changes in the working tree.
message("Changing content...")
update_content(user-source files_added files_removed dirs_added)
foreach(filename ${files_added})
message("add: ${filename}")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} add ${TOP}/user-source/${filename}
)
endforeach()
foreach(filename ${files_removed})
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} delete ${TOP}/user-source/${filename}
)
endforeach()
#-----------------------------------------------------------------------------
# Commit the changes to the repository.
message("Committing revision 2...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} submit -d "CTEST: Changed content"
)
#-----------------------------------------------------------------------------
# Make changes in the working tree.
message("Changing content again...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} edit //ctest/...
)
change_content(user-source)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} revert -a //ctest/...
)
#-----------------------------------------------------------------------------
# Commit the changes to the repository.
message("Committing revision 3...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} submit -d "CTEST: Changed content again"
)
#-----------------------------------------------------------------------------
# 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 ${P4CMD} sync @r1
)
# Create a modified file.
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} sync @r1
)
# We should p4 open any files that modify_content creates
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} open ${TOP}/user-source/CTestConfig.cmake
)
modify_content(user-source)
#-----------------------------------------------------------------------------
# Test updating the user work directory with the command-line interface.
message("Running CTest Dashboard Command Line...")
# Create the user build tree.
create_build_tree(user-source user-binary)
file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
"# P4 command configuration
UpdateCommand: ${P4}
P4Client: ctest_p4
P4Options: -H ${P4_HOST} -p ${P4_PORT}
")
# Run the dashboard command line interface.
run_dashboard_command_line(user-binary)
# Revert the modified files
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} revert ${TOP}/user-source/CTestConfig.cmake
)
#-----------------------------------------------------------------------------
# Test initial checkout and update with a dashboard script.
# Create a new client so we can check out files on a different directory
message("Running CTest Dashboard Script...")
message("Creating client spec...")
file(WRITE ${TOP}/client2.spec "Client: ctest2_p4\n")
file(APPEND ${TOP}/client2.spec "Root: ${TOP}/dash-source\n")
file(APPEND ${TOP}/client2.spec "View: //ctest/... //ctest2_p4/...\n")
run_child(
COMMAND ${P4CMD} client -i
INPUT_FILE ${TOP}/client2.spec
)
file(MAKE_DIRECTORY ${TOP}/dash-source)
create_dashboard_script(dash-binary
"# P4 command configuration
set(CTEST_P4_CLIENT \"ctest2_p4\")
set(CTEST_P4_OPTIONS \"-H ${P4_HOST} -p ${P4_PORT}\")
set(CTEST_UPDATE_COMMAND \"${P4}\")
")
# Run the dashboard script with CTest.
run_dashboard_script(dash-binary)
#-----------------------------------------------------------------------------
# Clean up
message("Shutting down p4d")
run_child(
WORKING_DIRECTORY ${TOP}
COMMAND ${P4CMD} admin stop
)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment