Browse Source

Use BufferSearch from c++utilities

lmdb
Martchus 2 months ago
parent
commit
e5f4057c61
  1. 2
      librepomgr/CMakeLists.txt
  2. 37
      librepomgr/buildactions/buildactionlivestreaming.cpp
  3. 36
      librepomgr/buildactions/buildactionprivate.h
  4. 9
      librepomgr/buildactions/conductbuild.cpp
  5. 34
      librepomgr/tests/buildactions.cpp

2
librepomgr/CMakeLists.txt

@ -80,7 +80,7 @@ set(LINK_TESTS_AGAINST_APP_TARGET ON)
set(CONFIGURATION_PACKAGE_SUFFIX
""
CACHE STRING "sets the suffix for find_package() calls to packages configured via c++utilities")
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.10.3 REQUIRED)
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.11.0 REQUIRED)
use_cpp_utilities(VISIBILITY PUBLIC)
# find boost libraries

37
librepomgr/buildactions/buildactionlivestreaming.cpp

@ -293,43 +293,6 @@ void BuildProcessSession::conclude()
buildAction->m_ongoingProcesses.erase(m_logFilePath);
}
void BufferSearch::operator()(const BuildProcessSession::BufferType &buffer, std::size_t bufferSize)
{
if (m_hasResult || (!m_giveUpTerm.empty() && m_giveUpTermIterator == m_giveUpTerm.end())) {
return;
}
for (auto i = buffer->data(), end = buffer->data() + bufferSize; i != end; ++i) {
const auto currentChar = *i;
if (m_searchTermIterator == m_searchTerm.end()) {
for (const auto &terminationChar : m_terminationChars) {
if (currentChar == terminationChar) {
m_hasResult = true;
break;
}
}
if (m_hasResult) {
m_callback(std::move(m_result));
return;
}
m_result += currentChar;
continue;
}
if (currentChar == *m_searchTermIterator) {
++m_searchTermIterator;
} else {
m_searchTermIterator = m_searchTerm.begin();
}
if (m_giveUpTerm.empty()) {
continue;
}
if (currentChar == *m_giveUpTermIterator) {
++m_giveUpTermIterator;
} else {
m_giveUpTermIterator = m_giveUpTerm.begin();
}
}
}
std::shared_ptr<BuildProcessSession> BuildAction::makeBuildProcess(
std::string &&displayName, std::string &&logFilePath, ProcessHandler &&handler, AssociatedLocks &&locks)
{

36
librepomgr/buildactions/buildactionprivate.h

@ -32,6 +32,10 @@ namespace boost::process {
class child;
}
namespace CppUtilities {
class BufferSearch;
}
namespace LibRepoMgr {
enum class BuildActionAccess {
@ -269,35 +273,6 @@ template <typename... ChildArgs> void BuildProcessSession::launch(ChildArgs &&..
readMoreFromPipe();
}
/// \brief The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively specified buffers.
struct LIBREPOMGR_EXPORT BufferSearch {
BufferSearch(
std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm, std::function<void(std::string &&)> &&callback);
void operator()(const BuildProcessSession::BufferType &buffer, std::size_t bufferSize);
private:
const std::string_view m_searchTerm;
const std::string_view m_terminationChars;
const std::string_view m_giveUpTerm;
const std::function<void(std::string &&)> m_callback;
std::string_view::const_iterator m_searchTermIterator;
std::string_view::const_iterator m_giveUpTermIterator;
std::string m_result;
bool m_hasResult;
};
inline BufferSearch::BufferSearch(
std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm, std::function<void(std::string &&)> &&callback)
: m_searchTerm(searchTerm)
, m_terminationChars(terminationChars)
, m_giveUpTerm(giveUpTerm)
, m_callback(std::move(callback))
, m_searchTermIterator(m_searchTerm.begin())
, m_giveUpTermIterator(m_giveUpTerm.begin())
, m_hasResult(false)
{
}
struct ProcessResult;
/// \brief The InternalBuildAction struct contains internal details (which are not serialized / accessible via the web API) and helpers.
@ -620,7 +595,8 @@ private:
void checkBuildErrors(BatchProcessingSession::ContainerType &&failedPackages);
void dumpBuildProgress();
void addLogFile(std::string &&logFilePath);
void assignNewVersion(const std::string &packageName, PackageBuildProgress &packageProgress, std::string &&updatedVersionInfo);
void assignNewVersion(
const std::string &packageName, PackageBuildProgress &packageProgress, CppUtilities::BufferSearch &, std::string &&updatedVersionInfo);
void copyPkgbuildToOriginalSourceDirectory(
const std::string &packageName, PackageBuildProgress &packageProgress, const std::string &buildDirectory);
PackageStagingNeeded checkWhetherStagingIsNeededAndPopulateRebuildList(

9
librepomgr/buildactions/conductbuild.cpp

@ -9,6 +9,7 @@
#include <c++utilities/conversion/stringbuilder.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <c++utilities/io/buffersearch.h>
#include <c++utilities/io/inifile.h>
#include <c++utilities/io/misc.h>
#include <c++utilities/io/path.h>
@ -929,9 +930,10 @@ InvocationResult ConductBuild::invokeMakechrootpkg(
std::bind(&ConductBuild::handleMakechrootpkgErrorsAndAddPackageToRepo, this, makepkgchrootSession, std::ref(packageName),
std::ref(packageProgress), std::placeholders::_1, std::placeholders::_2));
processSession->registerNewDataHandler(BufferSearch("Updated version: ", "\e\n", "Starting build",
std::bind(&ConductBuild::assignNewVersion, this, std::ref(packageName), std::ref(packageProgress), std::placeholders::_1)));
std::bind(
&ConductBuild::assignNewVersion, this, std::ref(packageName), std::ref(packageProgress), std::placeholders::_1, std::placeholders::_2)));
processSession->registerNewDataHandler(BufferSearch("Synchronizing chroot copy", "\n", std::string_view(),
[processSession = processSession.get()](std::string &&) { processSession->locks().pop_back(); }));
[processSession = processSession.get()](BufferSearch &, std::string &&) { processSession->locks().pop_back(); }));
// lock the chroot directory to prevent other build tasks from using it
m_buildAction->log()(Phrases::InfoMessage, "Building ", packageName, '\n');
@ -1406,7 +1408,8 @@ void ConductBuild::addLogFile(std::string &&logFilePath)
m_buildAction->logfiles.emplace_back(std::move(logFilePath));
}
void ConductBuild::assignNewVersion(const std::string &packageName, PackageBuildProgress &packageProgress, string &&updatedVersionInfo)
void ConductBuild::assignNewVersion(
const std::string &packageName, PackageBuildProgress &packageProgress, BufferSearch &, std::string &&updatedVersionInfo)
{
auto updatedVersionInfoParts = splitString(updatedVersionInfo, " ", EmptyPartsTreat::Omit);
if (updatedVersionInfoParts.empty()) {

34
librepomgr/tests/buildactions.cpp

@ -39,7 +39,6 @@ class BuildActionsTests : public TestFixture {
CPPUNIT_TEST(testLogging);
CPPUNIT_TEST(testProcessSession);
CPPUNIT_TEST(testBuildActionProcess);
CPPUNIT_TEST(testBufferSearch);
CPPUNIT_TEST(testParsingInfoFromPkgFiles);
CPPUNIT_TEST(testPreparingBuild);
CPPUNIT_TEST(testConductingBuild);
@ -53,7 +52,6 @@ public:
void testLogging();
void testProcessSession();
void testBuildActionProcess();
void testBufferSearch();
void testParsingInfoFromPkgFiles();
void testPreparingBuild();
void testConductingBuild();
@ -270,38 +268,6 @@ void BuildActionsTests::testBuildActionProcess()
TESTUTILS_ASSERT_LIKE_FLAGS("PID logged", ".*Launched \"test\", PID\\: [0-9]+.*\n.*"s, std::regex::extended, m_buildAction->output);
}
/*!
* \brief Tests the BufferSearch class.
*/
void BuildActionsTests::testBufferSearch()
{
// make a buffer
BuildProcessSession::BufferPoolType bufferPool(30);
auto buffer = bufferPool.newBuffer();
// setup testing the search
std::string expectedResult;
bool hasResult = false;
BufferSearch bs("Updated version: ", "\e\n", "Starting build", [&expectedResult, &hasResult](std::string &&result) {
CPPUNIT_ASSERT_EQUAL(expectedResult, result);
CPPUNIT_ASSERT_MESSAGE("callback only invoked once", !hasResult);
hasResult = true;
});
// feed data into the search
bs(buffer, 0);
std::strcpy(buffer->data(), "Starting Updated");
bs(buffer, 16);
std::strcpy(buffer->data(), " version: some ");
bs(buffer, 15);
expectedResult = "some version number";
std::strcpy(buffer->data(), "version number\emore chars");
bs(buffer, 25);
CPPUNIT_ASSERT(hasResult);
std::strcpy(buffer->data(), "... Starting build ...");
bs(buffer, 22);
}
/*!
* \brief Tests the ReloadLibraryDependencies build action.
*/

Loading…
Cancel
Save